From 54a9c0fc607f9345505ef45a87247045efbd7488 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Hentschel?= Date: Sat, 2 Jun 2012 19:05:30 +0200 Subject: [PATCH] ntdll: Add a helper function that returns the record length of a dirent struct. --- configure | 14 ++++++++++++++ configure.ac | 6 ++++++ dlls/ntdll/directory.c | 19 ++++++++++++++----- include/config.h.in | 3 +++ 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/configure b/configure index e8201d31799..a55c6a6a7a4 100755 --- a/configure +++ b/configure @@ -13794,6 +13794,20 @@ _ACEOF fi +ac_fn_c_check_member "$LINENO" "struct dirent" "d_reclen" "ac_cv_member_struct_dirent_d_reclen" "#ifdef HAVE_DIRENT_H +#include +#endif +" +if test "x$ac_cv_member_struct_dirent_d_reclen" = xyes; then : + +cat >>confdefs.h <<_ACEOF +#define HAVE_STRUCT_DIRENT_D_RECLEN 1 +_ACEOF + + +fi + + ac_fn_c_check_member "$LINENO" "struct msghdr" "msg_accrights" "ac_cv_member_struct_msghdr_msg_accrights" "#include #ifdef HAVE_SYS_SOCKET_H # include diff --git a/configure.ac b/configure.ac index d1acb72a58f..5cd12a597a0 100644 --- a/configure.ac +++ b/configure.ac @@ -2219,6 +2219,12 @@ AC_CHECK_MEMBERS([struct statvfs.f_blocks],,, #include #endif]) +dnl Check for dirent.d_reclen +AC_CHECK_MEMBERS([struct dirent.d_reclen],,, +[#ifdef HAVE_DIRENT_H +#include +#endif]) + dnl Check for socket structure members AC_CHECK_MEMBERS([struct msghdr.msg_accrights, struct sockaddr.sa_len, struct sockaddr_un.sun_len],,, [#include diff --git a/dlls/ntdll/directory.c b/dlls/ntdll/directory.c index 329e0639714..c8fff6b3b6c 100644 --- a/dlls/ntdll/directory.c +++ b/dlls/ntdll/directory.c @@ -1709,6 +1709,15 @@ static inline int wine_getdirentries(int fd, char *buf, int nbytes, long *basep) return res; } +static inline int dir_reclen(struct dirent *de) +{ +#ifdef HAVE_STRUCT_DIRENT_D_RECLEN + return de->d_reclen; +#else + return _DIRENT_RECLEN(de->d_namlen); +#endif +} + /*********************************************************************** * read_directory_getdirentries * @@ -1754,9 +1763,9 @@ static int read_directory_getdirentries( int fd, IO_STATUS_BLOCK *io, void *buff /* check if we got . and .. from getdirentries */ if (res > 0) { - if (!strcmp( de->d_name, "." ) && res > de->d_reclen) + if (!strcmp( de->d_name, "." ) && res > dir_reclen(de)) { - struct dirent *next_de = (struct dirent *)(data + de->d_reclen); + struct dirent *next_de = (struct dirent *)(data + dir_reclen(de)); if (!strcmp( next_de->d_name, ".." )) fake_dot_dot = 0; } } @@ -1792,7 +1801,7 @@ static int read_directory_getdirentries( int fd, IO_STATUS_BLOCK *io, void *buff while (res > 0) { - res -= de->d_reclen; + res -= dir_reclen(de); if (de->d_fileno && !(fake_dot_dot && (!strcmp( de->d_name, "." ) || !strcmp( de->d_name, ".." ))) && ((info = append_entry( buffer, io, length, de->d_name, NULL, mask, class )))) @@ -1819,7 +1828,7 @@ static int read_directory_getdirentries( int fd, IO_STATUS_BLOCK *io, void *buff if (res > 0 && (single_entry || io->Information + max_dir_info_size(class) > length)) { lseek( fd, (unsigned long)restart_pos, SEEK_SET ); - size = (char *)de + de->d_reclen - data; + size = (char *)de + dir_reclen(de) - data; io->Information = restart_info_pos; last_info = restart_last_info; goto restart; @@ -1828,7 +1837,7 @@ static int read_directory_getdirentries( int fd, IO_STATUS_BLOCK *io, void *buff /* move on to the next entry */ if (res > 0) { - de = (struct dirent *)((char *)de + de->d_reclen); + de = (struct dirent *)((char *)de + dir_reclen(de)); continue; } if (size < initial_size) break; /* already restarted once, give up now */ diff --git a/include/config.h.in b/include/config.h.in index c4b67a0e61d..7d6e2612e48 100644 --- a/include/config.h.in +++ b/include/config.h.in @@ -785,6 +785,9 @@ /* Define to 1 if you have the `strtoull' function. */ #undef HAVE_STRTOULL +/* Define to 1 if `d_reclen' is a member of `struct dirent'. */ +#undef HAVE_STRUCT_DIRENT_D_RECLEN + /* Define to 1 if `direction' is a member of `struct ff_effect'. */ #undef HAVE_STRUCT_FF_EFFECT_DIRECTION