f



Can the value of NAME_MAX be changed?

Can the value of NAME_MAX be changed?
Changing its value does not seem to make any difference.

____________________________________
#include <stdlib.h>                    
#include <stdio.h>
#include <limits.h>

#define _POSIX_SOURCE

#ifndef NAME_MAX
#error NAME_MAX not defined
#endif

#undef NAME_MAX

#define NAME_MAX 100000


#ifndef _POSIX_NAME_MAX
#error _POSIX_NAME_MAX not defined
#endif

#undef _POSIX_NAME_MAX
#define _POSIX_NAME_MAX 100000


int main(void)
{
	char c;
	FILE *s,*d;
	printf("%d\n",NAME_MAX);
	printf("%d\n",_POSIX_NAME_MAX);
	getchar();
	s=fopen("temp.c","r"); 
	if (s==NULL)
	{
		perror("Cannot open");
		getchar();
		return -1;
	}

d=fopen("ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd
ddddddddddddddddddddddddddddddddddddddtemp2.c","w");
	if (d==NULL)
	{
		perror("Cannot open");
		getchar();
		return -1;
	}
	while((c=fgetc(s))!=EOF) putc(c,d);
	
       getchar();	   
       return 0;
}


-- 
somebudy@despammed.com
You need not make any modifications, the mail id is valid
0
Me
6/25/2003 7:59:34 PM
comp.unix.programmer 10848 articles. 0 followers. kokososo56 (350) is leader. Post Follow

4 Replies
1363 Views

Similar Articles

[PageSpeed] 41

Me <somebudy@despammed.com> writes:

> Can the value of NAME_MAX be changed?
> Changing its value does not seem to make any difference.

NAME_MAX is referenced in the source code of the fopen() function,
which you did not recompile.

If you are willing to recompile the entire standard library, then
yes, you can probably set it to whatever you want.

---
John Gordon            "Your hat makes baby Brell cry."
gordon@jtan.com         -- James Grahame in alt.games.everquest
0
John
6/25/2003 9:41:26 PM
Me wrote:

> Can the value of NAME_MAX be changed?
> Changing its value does not seem to make any difference.
> 
> ____________________________________
> #include <stdlib.h>
> #include <stdio.h>
> #include <limits.h>
> 
> #define _POSIX_SOURCE
> 
> #ifndef NAME_MAX
> #error NAME_MAX not defined
> #endif
> 
> #undef NAME_MAX
> 
> #define NAME_MAX 100000
> 
> 
> #ifndef _POSIX_NAME_MAX
> #error _POSIX_NAME_MAX not defined
> #endif
> 
> #undef _POSIX_NAME_MAX
> #define _POSIX_NAME_MAX 100000
> 
> 
> int main(void)
> {
> char c;
> FILE *s,*d;
> printf("%d\n",NAME_MAX);
> printf("%d\n",_POSIX_NAME_MAX);
> getchar();
> s=fopen("temp.c","r");
> if (s==NULL)
> {
> perror("Cannot open");
> getchar();
> return -1;
> }
> 
>
d=fopen("ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd
> ddddddddddddddddddddddddddddddddddddddtemp2.c","w");
> if (d==NULL)
> {
> perror("Cannot open");
> getchar();
> return -1;
> }
> while((c=fgetc(s))!=EOF) putc(c,d);
> 
>        getchar();
>        return 0;
> }
> 
> 

Why do you want to change it?  It exists as a pre-defined value for a good
reason.
0
Sean
6/26/2003 9:55:40 AM
On Wed, 25 Jun 2003 21:41:26 GMT,  John Gordon wrote:

>Me <somebudy@despammed.com> writes:
>
>> Can the value of NAME_MAX be changed?
>> Changing its value does not seem to make any difference.
>
>NAME_MAX is referenced in the source code of the fopen() function,
>which you did not recompile.
>
>If you are willing to recompile the entire standard library, then
>yes, you can probably set it to whatever you want.

Any way, lets say I change it somehow to a lower value; how will the operating
system treat files with longer names? What if I set it to 0? Will it ever boot
again?

On my system in KDE when I try to rename a file I have the following problem.
In the text box if the number of characters exceed a certain value (NAME_MAX?) I
am automatically logged off.
Do you face such a problem?

Try and put 2 dashes followed by one space as a sig separator, like this "-- "
(without quotes) 8-)

Thanks a lot.


-- 
somebudy@despammed.com
You need not make any modifications, the mail id is valid
0
Me
6/26/2003 12:59:30 PM
On Thu, 26 Jun 2003 18:29:30 +0530, Me <somebudy@despammed.com> wrote:


[snip]

>
> On my system in KDE when I try to rename a file I have the following 
> problem.
> In the text box if the number of characters exceed a certain value 
> (NAME_MAX?) I
> am automatically logged off.
> Do you face such a problem?
>
> Try and put 2 dashes followed by one space as a sig separator, like this 
> "-- "
> (without quotes) 8-)
>
> Thanks a lot.
>
>

This is a bug in KDE or whatever, having nothing to do with NAME_MAX or any 
other part of the UNIX kernel.

And, should you get that far, NAME_MAX is only the length of a component of 
the path. It's not a limit on the whole path, which is what users are 
normally concerned with. That's a different constant (if the system even 
has a limit), and it's similarly read-only: PATH_MAX. It may not be 
defined, as having a limit isn't a requirement.

Generally, software has to be designed to:

1. Handle all paths, no matter the length, up to a reasonable number (e.g., 
4K). But 4K paths occur only when the program is generating the path. Users 
never type or paste paths that long, although in theory they could.

2. Give an error message or whatever if the path is too long. Aborting 
(which is what's hapenning here, from your description) is never 
acceptable.

--Marc
0
Marc
6/26/2003 2:23:52 PM
Reply: