If the dimensions of the array can only be a constant value, what is the value of char d_name [...]?

If the dimensions of the array can only be a constant value than

char d_name[...] 

mean?

Actually, a dire dirent is declared in the dirent.h file. his declaration corresponds to:

 struct dirent{ .... ino_t d_ino; char d_name[...]; ... }; 

It is used to read the contents of a directory one at a time, i.e. inode numbers and file names, etc.

I mean, what is the maximum size of such an array and how much space is statically allocated in memory after defining such an array? Is such a definition portable?

+4
source share
1 answer

Assuming this is from struct linux_dirent , this is actually char d_name[] :

 struct linux_dirent { unsigned long d_ino; /* Inode number */ unsigned long d_off; /* Offset to next linux_dirent */ unsigned short d_reclen; /* Length of this linux_dirent */ char d_name[]; /* Filename (null-terminated) */ } 

It is called a flexible member of the array, using malloc , you can allocate more memory for the structure giving d_name size of the variable.

EDIT

Text indicating OP:

Directory entries represented by structural dirent

 struct dirent { ... ino_t d_ino; /* XSI extension --- see text */ char d_name[...]; /* See text on the size of this array */ ... }; 

When ... authors signal that the size is not fixed for the standard . Each implementation must choose a fixed size, for example, Linux chooses 256. But this is not valid code.

+9
source

Source: https://habr.com/ru/post/1400714/


All Articles