NAME_MAX

O

occhiverdi

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
 
B

Ben Pfaff

occhiverdi said:
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>.
 
O

osmium

occhiverdi said:
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>.
 
O

occhiverdi

occhiverdi said:
#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
 
M

Martin Ambuhl

occhiverdi said:
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'.
 
J

Jens.Toerring

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
 
K

Keith Thompson

Emmanuel Delahaye said:
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 said:
filename = file -> d_name;

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

Emmanuel Delahaye

In 'comp.lang.c' said:
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


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

Agreed. I have read too fast. My bad.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top