Operating System - Linux
1752790 Members
6189 Online
108789 Solutions
New Discussion юеВ

fopen fails for path name of more than 255 characters

 
Satya_6
Frequent Advisor

fopen fails for path name of more than 255 characters

Hi,

How can I open a file with path name more than 255 characters using fopen?

TIA
Satya
7 REPLIES 7
Muthukumar_5
Honored Contributor

Re: fopen fails for path name of more than 255 characters

You can use upto 1023 character in a pathname including last null character.

Information are available as,

-- man fopen --

[ENAMETOOLONG] The length of the pathname string exceeds PATH_MAX or a
pathname component is longer than NAME_MAX while
POSIX_NO_TRUNC is in effect.

-- /usr/include/limits.h --

# define PATH_MAX 1023 /* max number of characters in a pathname (not
including terminating null) */

hth.
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: fopen fails for path name of more than 255 characters

I hope you are using hfs file system rgt? It is only supportable upto 255 characters.

ref: man errno

[ENAMETOOLONG] File name too long. A path specified exceeds the
maximum path length for the system. The maximum path
length is specified by PATH_MAX and is defined in
. PATH_MAX is guaranteed to be at least 1023
bytes. This error is also generated if the length of a
path name component exceeds NAME_MAX and the
_POSIX_NO_TRUNC option is in effect for the specified
path. Currently, _POSIX_NO_TRUNC is in effect only for
HFS file systems configured to allow path name
components up to 255 bytes long (see convertfs(1M)) and
therefore only path names referring to such file
systems can generate the error for this case. The
values of NAME_MAX, PATH_MAX, and _POSIX_NO_TRUNC for a
particular path name can be queried by using the
pathconf() system call (see pathconf(2)).

hth.
Easy to suggest when don't know about the problem!
Satya_6
Frequent Advisor

Re: fopen fails for path name of more than 255 characters

Thanks for the quick response, but I should say it is not of much help as I had done man fopen errno and checked the values using the pathconf before posting it to this forum.

Is there no way, I can have a pathname more than 255 on HFS filesytem and successfully open using fopen?

TIA
Satya
Muthukumar_5
Honored Contributor

Re: fopen fails for path name of more than 255 characters

You can able to have 255 characters for file name length with HFS fs. If you want to have more then use VxFS fs.

More Reference:

http://www.faqs.org/faqs/hp/hpux-faq/
Subject: 5.3.1 How can I enable long file names?

hth.
Easy to suggest when don't know about the problem!
Satya_6
Frequent Advisor

Re: fopen fails for path name of more than 255 characters

Thanks again, in fact I have the vxfs file system only and I can have a file with a maximum length of 255 characters and if it exceeds 255 chars, the fopen is failing. So Is there any way by which I can handle files with name more than 255 characters on vxfs file system?


TIA
Satya
Stephen Keane
Honored Contributor

Re: fopen fails for path name of more than 255 characters

Suggest you run pathconf() against each directory (dir_name) in the path leading up to the file you wish to fopen(), with arguments

long rc;
rc = pathconf(dir_name, _PC_NO_TRUNC);

Will return -1 on error and set errno, else will return 0 or 1. If it returns 1, then that directory cannot contain a filename of > 255 characters length.

Muthukumar_5
Honored Contributor

Re: fopen fails for path name of more than 255 characters

getconf PATH_MAX

what you are getting. what is your uname -a o/p?

hth.
Easy to suggest when don't know about the problem!