2008-07-09 15:16:00 +04:00
|
|
|
/*
|
2012-07-19 22:11:40 +04:00
|
|
|
* Copyright 2002-2012 Haiku, Inc. All Rights Reserved.
|
2008-07-09 15:16:00 +04:00
|
|
|
* Distributed under the terms of the MIT License.
|
|
|
|
*/
|
2004-09-15 03:08:21 +04:00
|
|
|
#ifndef _DIRENT_H
|
|
|
|
#define _DIRENT_H
|
|
|
|
|
2002-07-11 18:59:59 +04:00
|
|
|
|
2002-08-20 15:10:51 +04:00
|
|
|
#include <sys/types.h>
|
2002-08-03 06:03:27 +04:00
|
|
|
|
2002-07-11 18:59:59 +04:00
|
|
|
|
|
|
|
typedef struct dirent {
|
2002-11-29 05:49:58 +03:00
|
|
|
dev_t d_dev; /* device */
|
|
|
|
dev_t d_pdev; /* parent device (only for queries) */
|
|
|
|
ino_t d_ino; /* inode number */
|
|
|
|
ino_t d_pino; /* parent inode (only for queries) */
|
|
|
|
unsigned short d_reclen; /* length of this record, not the name */
|
dirent: Use an actual flexible-length array for d_name.
GCC 11 treats [1] as a fixed-length array and not a flexible-length
array, and so some things that used direct strcmp("..", ent->d_name),
for instance, would be optimized out as being always unequal,
which was the cause of #17389. Using a real FLA informs GCC that
there is going to be more than one byte of data, and thus this
fixes that bug.
BeOS used [1] and not [0], possibly because it had to deal with
compilers (MetroWerks? Early GCC2?) that did not support FLAs.
GCC 2.95 does, using [0], and GCC 4 does, using [], so we can go
with that here.
(I did try using [0] for both, which seems to be OK with GCC 11,
but GCC 8 throws errors when d_name is dereferenced directly
as being-out-of-bounds. So, we have to use the #if here and give
newer GCC the [] syntax and not [0] to avoid that problem.)
The real question probably is whether or not we should backport
some variant of these changes to R1/beta3, as software at HaikuPorts
very well may run in to the same issue. (The alternative workaround
is to compile with -O1 and not -O2 for any affected software.) But
maybe this is an argument for keeping with the beta4 schedule of
this coming January...
2021-11-19 00:34:03 +03:00
|
|
|
#if __GNUC__ == 2
|
|
|
|
char d_name[0]; /* name of the entry (null byte terminated) */
|
|
|
|
#else
|
|
|
|
char d_name[]; /* name of the entry (null byte terminated) */
|
|
|
|
#endif
|
2002-07-11 18:59:59 +04:00
|
|
|
} dirent_t;
|
|
|
|
|
2008-07-09 15:16:00 +04:00
|
|
|
typedef struct __DIR DIR;
|
2002-07-11 18:59:59 +04:00
|
|
|
|
|
|
|
#ifndef MAXNAMLEN
|
|
|
|
# ifdef NAME_MAX
|
|
|
|
# define MAXNAMLEN NAME_MAX
|
|
|
|
# else
|
|
|
|
# define MAXNAMLEN 256
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2002-10-26 17:07:30 +04:00
|
|
|
#ifdef __cplusplus
|
2002-07-11 18:59:59 +04:00
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2010-01-01 21:52:09 +03:00
|
|
|
DIR* fdopendir(int fd);
|
2009-08-30 00:25:24 +04:00
|
|
|
DIR* opendir(const char* dirName);
|
|
|
|
struct dirent* readdir(DIR* dir);
|
|
|
|
int readdir_r(DIR* dir, struct dirent* entry,
|
|
|
|
struct dirent** _result);
|
|
|
|
int closedir(DIR* dir);
|
|
|
|
void rewinddir(DIR* dir);
|
|
|
|
void seekdir(DIR* dir, long int position);
|
|
|
|
long int telldir(DIR* dir);
|
2011-01-07 00:34:06 +03:00
|
|
|
int dirfd(DIR* dir);
|
2010-01-01 21:49:55 +03:00
|
|
|
|
|
|
|
int alphasort(const struct dirent** entry1,
|
|
|
|
const struct dirent** entry2);
|
|
|
|
int scandir(const char* dir, struct dirent*** _entryArray,
|
|
|
|
int (*selectFunc)(const struct dirent*),
|
|
|
|
int (*compareFunc)(const struct dirent** entry1,
|
|
|
|
const struct dirent** entry2));
|
2008-07-17 05:01:52 +04:00
|
|
|
|
2002-10-26 17:07:30 +04:00
|
|
|
#ifdef __cplusplus
|
2002-07-11 18:59:59 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-09-15 03:08:21 +04:00
|
|
|
#endif /* _DIRENT_H */
|