Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > NAME_MAX

Reply
Thread Tools

NAME_MAX

 
 
occhiverdi
Guest
Posts: n/a
 
      07-09-2004
Hi,

I would like to know which file do I need to include to get NAME_MAX? I'm
trying to read filenames of a directory but it gave me error saying that
the NAME_MAX is undefined. I've looked into the /usr/include directory and
I see that it's not defined anywhere.

#include <dirent.h>
....
struct dirent * file;
char filename[NAME_MAX + 1];
....
while ((file = readdir(queue_dir)) != NULL) {
filename = file -> d_name;
....

Thanks for help.

occhiverdi
 
Reply With Quote
 
 
 
 
Ben Pfaff
Guest
Posts: n/a
 
      07-09-2004
occhiverdi <(E-Mail Removed)> writes:

> I would like to know which file do I need to include to get NAME_MAX?


Standard C doesn't have a NAME_MAX. There is a FILENAME_MAX in
<stdio.h>.
--
"When I have to rely on inadequacy, I prefer it to be my own."
--Richard Heathfield
 
Reply With Quote
 
 
 
 
Quentarez
Guest
Posts: n/a
 
      07-09-2004
I believe you must #include <limits.h>.


"occhiverdi" <(E-Mail Removed)> wrote in message
news:IwzHc.12860$(E-Mail Removed)...
> Hi,
>
> I would like to know which file do I need to include to get NAME_MAX? I'm
> trying to read filenames of a directory but it gave me error saying that
> the NAME_MAX is undefined. I've looked into the /usr/include directory and
> I see that it's not defined anywhere.
>
> #include <dirent.h>
> ...
> struct dirent * file;
> char filename[NAME_MAX + 1];
> ...
> while ((file = readdir(queue_dir)) != NULL) {
> filename = file -> d_name;
> ...
>
> Thanks for help.
>
> occhiverdi



 
Reply With Quote
 
osmium
Guest
Posts: n/a
 
      07-09-2004
occhiverdi writes:

> I would like to know which file do I need to include to get NAME_MAX? I'm
> trying to read filenames of a directory but it gave me error saying that
> the NAME_MAX is undefined. I've looked into the /usr/include directory and
> I see that it's not defined anywhere.
>
> #include <dirent.h>
> ...
> struct dirent * file;
> char filename[NAME_MAX + 1];
> ...
> while ((file = readdir(queue_dir)) != NULL) {
> filename = file -> d_name;
> ...


Perhaps you want FILENAME_MAX? I would expect it to be in <stdio.h>.


 
Reply With Quote
 
Ben Pfaff
Guest
Posts: n/a
 
      07-09-2004
"Quentarez" <(E-Mail Removed)> writes:

> I believe you must #include <limits.h>.


<limits.h> does not contain NAME_MAX.
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
 
Reply With Quote
 
occhiverdi
Guest
Posts: n/a
 
      07-09-2004
occhiverdi wrote:

> #include <dirent.h>
> ...
> struct dirent * file;
> char filename[NAME_MAX + 1];
> ...
> while ((file = readdir(queue_dir)) != NULL) {
> filename = file -> d_name;
> ...



Thanks for the replies.

I see that I only have to declare filename as
char * filename;
It works.

occhiverdi

 
Reply With Quote
 
Martin Ambuhl
Guest
Posts: n/a
 
      07-09-2004
occhiverdi wrote:

> Hi,
>
> I would like to know which file do I need to include to get NAME_MAX?


Include <stdio.h> to get FILENAME_MAX. There is no standard C macro
named 'NAME_MAX'.
 
Reply With Quote
 
Emmanuel Delahaye
Guest
Posts: n/a
 
      07-09-2004
In 'comp.lang.c', occhiverdi <(E-Mail Removed)> wrote:

> I see that I only have to declare filename as
> char * filename;
> It works.


What works? I'm scared...

--
-ed- get my email here: http://marreduspam.com/ad672570
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
 
Reply With Quote
 
Jens.Toerring@physik.fu-berlin.de
Guest
Posts: n/a
 
      07-09-2004
Emmanuel Delahaye <(E-Mail Removed)> wrote:
> In 'comp.lang.c', occhiverdi <(E-Mail Removed)> wrote:


>> I see that I only have to declare filename as
>> char * filename;
>> It works.


> What works? I'm scared...


In that case it might even work, because he's just copying the
pointer to some member of a structure the function returns,
he's not calling e.g. strcpy() with that pointer.
<OT>
Of course, that only works as expected if the OP doesn't want to
keep what the pointer is pointing to after the next invocation of
the readdir() function, i.e. when he uses 'filename' only as an
abbreviation for 'file->d_name'.
</OT>
Regards, Jens
--
\ Jens Thoms Toerring ___ http://www.velocityreviews.com/forums/(E-Mail Removed)-berlin.de
\__________________________ http://www.toerring.de
 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      07-09-2004
Emmanuel Delahaye <(E-Mail Removed)> writes:
> In 'comp.lang.c', occhiverdi <(E-Mail Removed)> wrote:
> > I see that I only have to declare filename as
> > char * filename;
> > It works.

>
> What works? I'm scared...


When I first read occhiverdi's response, I was also concerned that he
was incorrectly using an uninitialized char*. But if you'll read
the full article (including the part that you snipped), you'll see
that he wrote:

> filename = file -> d_name;


which is perfectly legitimate assuming that file->d_name is valid.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments