diff options
author | Theodore Ts'o <tytso@mit.edu> | 1997-04-26 13:58:21 +0000 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 1997-04-26 13:58:21 +0000 |
commit | 50e1e10fa0ac12a3e2a9d20a75ee9041873cda96 (patch) | |
tree | 7ef931607cf258793edffa5deb1ddb1f46469d04 /lib/e2p/iod.c | |
parent | f3db3566b5e1342e49dffc5ec3f418a838584194 (diff) | |
download | e2fsprogs-50e1e10fa0ac12a3e2a9d20a75ee9041873cda96.tar.gz |
Many files:
Checked in e2fsprogs 0.5c
Diffstat (limited to 'lib/e2p/iod.c')
-rw-r--r-- | lib/e2p/iod.c | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/lib/e2p/iod.c b/lib/e2p/iod.c index 52c16a13..7b02a7f3 100644 --- a/lib/e2p/iod.c +++ b/lib/e2p/iod.c @@ -14,8 +14,6 @@ * 93/10/30 - Creation */ -#include <dirent.h> - #include "e2p.h" int iterate_on_dir (const char * dir_name, @@ -23,7 +21,13 @@ int iterate_on_dir (const char * dir_name, void * private) { DIR * dir; - struct dirent de; +#if HAVE_DIRENT_NAMELEN + /* Declare DE_BUF with some extra room for the name. */ + char de_buf[sizeof (struct dirent) + 32]; + struct dirent *de = (struct dirent *)&de_buf; +#else + struct dirent de_buf, *de = &de_buf; +#endif struct dirent *dep; dir = opendir (dir_name); @@ -31,12 +35,32 @@ int iterate_on_dir (const char * dir_name, return -1; while ((dep = readdir (dir))) { - de.d_ino = dep->d_ino; - de.d_off = dep->d_off; - de.d_reclen = dep->d_reclen; - strcpy (de.d_name, dep->d_name); - (*func) (dir_name, &de, private); +#if HAVE_DIRENT_NAMELEN + /* See if there's enough room for this entry in DE, and grow if + not. */ + if (de_len < dep->d_reclen) + { + de_len = dep->d_reclen + 32; + de = + (de == (struct dirent *)&de_buf + ? malloc (de_len) + : realloc (de, de_len)); + if (de == NULL) + { + errno = ENOMEM; + return -1; + } + } + memcpy (de, dep, dep->d_reclen); +#else + *de = *dep; +#endif + (*func) (dir_name, de, private); } +#if HAVE_DIRENT_NAMELEN + if (de != (struct dirent *)&de_buf) + free (de); +#endif closedir (dir); return 0; } |