473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

NAME_MAX

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
Nov 14 '05 #1
10 10842
I believe you must #include <limits.h>.
"occhiverdi" <oc********@nospam.mailcity.com> wrote in message
news:Iw********************@news3.tin.it...
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

Nov 14 '05 #2
occhiverdi <oc********@nospam.mailcity.com> 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
Nov 14 '05 #3
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>.
Nov 14 '05 #4
"Quentarez" <qu*******@hotmail.com> 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;}
Nov 14 '05 #5
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

Nov 14 '05 #6
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'.
Nov 14 '05 #7
In 'comp.lang.c', occhiverdi <oc********@nospam.mailcity.com> 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/
Nov 14 '05 #8
Emmanuel Delahaye <em**********@noos.fr> wrote:
In 'comp.lang.c', occhiverdi <oc********@nospam.mailcity.com> 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 ___ Je***********@physik.fu-berlin.de
\__________________________ http://www.toerring.de
Nov 14 '05 #9
Emmanuel Delahaye <em**********@noos.fr> writes:
In 'comp.lang.c', occhiverdi <oc********@nospam.mailcity.com> 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) ks***@mib.org <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.
Nov 14 '05 #10
In 'comp.lang.c', Keith Thompson <ks***@mib.org> wrote:
Emmanuel Delahaye <em**********@noos.fr> writes:
In 'comp.lang.c', occhiverdi <oc********@nospam.mailcity.com> 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.


Agreed. I have read too fast. My bad.

--
-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/
Nov 14 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Martin Pohlack | last post by:
Hi, I have a funtion which shall compute the amount for a later malloc. In this function I need the sizes of some struct members without having an instance or pointer of the struct. As...
13
by: Ioannis Vranos | last post by:
Hi all, Is long long supposed to be supported in all C99 implementations?If yes is it supposed to be 64 bit at least? GCC says that it supports long long, but i got this: #include <stdio.h>...
9
by: fybar | last post by:
Hi, I am in the progress of writing a program that will read in the contents of a directory and then do some stuff to some of the files. So far I am getting the contents of the directory but I get...
9
by: Michael B Allen | last post by:
Is there a macro for determining the address of the end of an object? For example, if f is a pointer to an instance of the below struct, endof(f->a) would be equal to the address of member b. ...
12
by: Chad | last post by:
On page 180 from the 2nd edition of "The C Programming Language" by Kernighan and Richtie, they use the following: #define NAME_MAX 14 typedef struct { long ino; char name; } Dirent;
1
by: mariodr | last post by:
Hi! This is my first post on the web ever! To make it short, I made a routine to change certain bytes in a file in binary mode. It all worked perfectly, until I decided to use a long name...
28
by: Bill | last post by:
Hello All, I am trying to pass a struct to a function. How would that best be accomplished? Thanks, Bill
270
by: jacob navia | last post by:
In my "Happy Christmas" message, I proposed a function to read a file into a RAM buffer and return that buffer or NULL if the file doesn't exist or some other error is found. It is interesting...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.