haiku/headers/private/fs_shell/fssh_dirent.h
Augustin Cavalier 7db2616c44 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 . 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-18 16:34:03 -05:00

47 lines
1.1 KiB
C

/*
** Distributed under the terms of the MIT License.
*/
#ifndef _FSSH_DIRENT_H
#define _FSSH_DIRENT_H
#include "fssh_defs.h"
typedef struct fssh_dirent {
fssh_dev_t d_dev; /* device */
fssh_dev_t d_pdev; /* parent device (only for queries) */
fssh_ino_t d_ino; /* inode number */
fssh_ino_t d_pino; /* parent inode (only for queries) */
unsigned short d_reclen; /* length of this record, not the name */
#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
} fssh_dirent_t;
typedef struct {
int fd;
struct fssh_dirent ent;
} fssh_DIR;
#ifdef __cplusplus
extern "C" {
#endif
fssh_DIR *fssh_opendir(const char *dirname);
struct fssh_dirent *fssh_readdir(fssh_DIR *dir);
int fssh_readdir_r(fssh_DIR *dir, struct fssh_dirent *entry,
struct fssh_dirent **_result);
int fssh_closedir(fssh_DIR *dir);
void fssh_rewinddir(fssh_DIR *dir);
void fssh_seekdir(fssh_DIR *dir, long int loc);
long int fssh_telldir(fssh_DIR *);
#ifdef __cplusplus
}
#endif
#endif /* _FSSH_DIRENT_H */