Sponsored Content
Full Discussion: struct dirent variances
Top Forums Programming struct dirent variances Post 302176181 by odys on Monday 17th of March 2008 04:48:55 PM
Old 03-17-2008
struct dirent variances

Hello,

Recently I need to create a filesystem related code.
I noticed lot of inconsistent documentation regarding
struct dirent:

1. 'd_namlen' field
info libc in chapter ''File System Interface"
specifies 'd_namlen' field as length of 'd_name' string.
When compiling under Linux (and GNU libc obviously)
'd_namlen' is missing.

2. 'd_reclen'
this field is documented as "length of d_name" in readdir(2) whereas in '/usr/include/dirent.h' it is described as 'size of entire directory entry'. In 'info libc' 'd_reclen' is mentioned but not really described at all.

3. 'd_off' field
in readdir(2) this is offset to current dirent [from start of the directory], but again in '/usr/include/dirent.h' this is "offset of next directory entry".

I understand that only 'd_name' is really portable and it is enough for my purposes.
But could anybody explain above? In my opinion some of inconsistencies from 2. and 3. are due to readir(2)
possibly deals with kernel 'struct dirent' which can be independent of libc one.

Regards,
Miroslaw

Regards.
 

10 More Discussions You Might Find Interesting

1. Programming

save a struct

hi all , can i save a structure in c in a file? how ? help me , thx. :) (2 Replies)
Discussion started by: kall_ANSI
2 Replies

2. Programming

dirent.h problem ..

hi...do opendir/readdir/closedir work also in windows platform? I tried to access directory name (d_name) but it didn't work out (or perhaps I made a mistake). Could someone share ideas about this? Thank's in advance. (3 Replies)
Discussion started by: qqq
3 Replies

3. Programming

struct tm problem

I receive an integer as argument for a function. within function definition i want it to be of type struct tm. eg.. main() { int a; ...... } function(...,..,a,..) int a; { struct tm tm; if(!a) ^ time(&a); ^ ... (4 Replies)
Discussion started by: bankpro
4 Replies

4. Programming

Struct Array

in my .c file i have a struct atop of the program defined as follows: #define MAX 10 int curtab; static struct tab { int count; int use; } tab; with the initial function following it like so: int tab_create(int init_count) { int i; for(i=0; i < MAX; i++) {... (1 Reply)
Discussion started by: micmac700
1 Replies

5. Linux

GCOV : struct bb

Hi, I am working on gcov.Meaning, analysing the functionality of gcov. There is one structure called "struct bb". I am not sure, how struct bb members are getting assigned values. If anyone knows how it is happening pls let me know. Thanks in advance. --Vichu (0 Replies)
Discussion started by: Vichu
0 Replies

6. Programming

dirent.h distinguishes files from directories ?

In C, I want to list all files recursively in a folder. But to do that, how can I distinguish files from directories ? (I realise I could use find in a shell script or use system("ls -R > file") but I want to use only C.) DIR *ptr; struct dirent *files; ptr =... (2 Replies)
Discussion started by: cyler
2 Replies

7. UNIX for Dummies Questions & Answers

How to access a struct within a struct?

Can someone tell me how to do this? Just a thought that entered my mind when learning about structs. First thought was: struct one { struct two; } struct two { three; } one->two->three would this be how you would access "three"? (1 Reply)
Discussion started by: unbelievable21
1 Replies

8. Programming

help with struct command in C

in C i am using this code to get the c time or a time or m time struct dirent *dir; struct stat my; stat(what, &my); thetime = my.st_ctime; How can i check if i have permission to check the c time of the file? (1 Reply)
Discussion started by: omega666
1 Replies

9. UNIX for Dummies Questions & Answers

struct winsize

what is struct winsize used for? i tried looking it up, but no luck. (0 Replies)
Discussion started by: l flipboi l
0 Replies

10. Programming

Storing C++-struct in file - problem when adding new item in struct

Hi, I have received an application that stores some properties in a file. The existing struct looks like this: struct TData { UINT uSizeIncludingStrings; // copy of Telnet data struct UINT uSize; // basic properties: TCHAR szHost; //defined in Sshconfig UINT iPortNr; TCHAR... (2 Replies)
Discussion started by: Powerponken
2 Replies
SCANDIR(3)						   BSD Library Functions Manual 						SCANDIR(3)

NAME
scandir, scandir_b, alphasort -- scan a directory SYNOPSIS
#include <sys/types.h> #include <dirent.h> int scandir(const char *dirname, struct dirent ***namelist, int (*select)(const struct dirent *), int (*compar)(const struct dirent **, const struct dirent **)); int alphasort(const struct dirent **d1, const struct dirent **d2); int scandir_b(const char *dirname, struct dirent ***namelist, int (^select)(const struct dirent *), int (^compar)(const struct dirent **, const struct dirent **)); DESCRIPTION
The scandir() function reads the directory dirname and builds an array of pointers to directory entries using malloc(3). It returns the num- ber of entries in the array. A pointer to the array of directory entries is stored in the location referenced by namelist (even if the num- ber of entries is 0). The select argument is a pointer to a user supplied subroutine which is called by scandir() to select which entries are to be included in the array. The select routine is passed a pointer to a directory entry and should return a non-zero value if the directory entry is to be included in the array. If select is null, then all the directory entries will be included. The compar argument is a pointer to a user supplied subroutine which is passed to qsort(3) to sort the completed array. If this pointer is null, the array is not sorted. The alphasort() function is a routine which can be used for the compar argument to sort the array alphabetically. The memory allocated for the array can be deallocated with free(3), by freeing each pointer in the array and then the array itself. The scandir_b() function works the same way as the scandir() function, except that select and compar are blocks instead of subroutines. DIAGNOSTICS
Returns -1 if the directory cannot be opened for reading or if malloc(3) cannot allocate enough memory to hold all the data structures. SEE ALSO
directory(3), malloc(3), qsort(3), dir(5) HISTORY
The scandir() and alphasort() functions appeared in 4.2BSD. The scandir_b() function appeared in Mac OS X 10.6. BSD
May 20, 2008 BSD
All times are GMT -4. The time now is 11:05 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy