* sysdeps/unix/dirstream.h: Rewritten.
* sysdeps/unix/readdir.c: Rewritten.
* sysdeps/unix/telldir.c: Rewritten.
* sysdeps/unix/closedir.c: Use <...> instead of "..." for dirstream.h.
Remove __ from DIR struct member names.
* sysdeps/unix/dirfd.c: Likewise.
* sysdeps/unix/seekdir.c: Likewise.
* sysdeps/unix/rewinddir.c: Likewise.
* sysdeps/unix/opendir.c: Likewise. Don't allocate extra space after
DIR structure.
* sysdeps/stub/direct.h: File removed.
* sysdeps/unix/bsd/bsd4.4/direct.h: File removed.
* sysdeps/unix/bsd/direct.h: File removed.
* sysdeps/unix/common/direct.h: File removed.
* sysdeps/unix/sysv/irix4/direct.h: File removed.
* sysdeps/unix/sysv/isc3/direct.h: File removed.
* sysdeps/unix/sysv/sco3.2.4/direct.h: File removed.
* sysdeps/unix/sysv/sysv4/solaris2/direct.h: File removed.
* sysdeps/unix/common/direntry.h: New file.
* sysdeps/unix/bsd/direntry.h: New file.
* sysdeps/unix/bsd/bsd4.4/direntry.h: New file.
* sysdeps/unix/sysv/direntry.h: New file.
* sysdeps/stub/direntry.h: New file.
* dirent/dirent.h (struct dirent): Type removed. Include <direntry.h>
to define it.
(_D_EXACT_NAMLEN, _D_ALLOC_NAMLEN): New macros.
* dirent/Makefile (headers): Add direntry.h.
(distribute): Remove direct.h.
* sysdeps/posix/getcwd.c: Use new macros instead of d_namlen.
* dirent/scandir.c: Likewise.
* io/fts.c (fts_build): Likewise.
* io/ftw.c (ftw_dir): Likewise.
* sysdeps/posix/ttyname.c: Likewise.
/* Read the directory, attaching each entry to the `link' pointer. */
adjaddr = NULL;
for (head = tail = NULL, nitems = 0; dp = readdir(dirp);) {
+ int namlen;
+
if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name))
continue;
- if ((p = fts_alloc(sp, dp->d_name, (int)dp->d_namlen)) == NULL)
+ namlen = _D_EXACT_NAMLEN (dp);
+ if ((p = fts_alloc(sp, dp->d_name, namlen)) == NULL)
goto mem1;
- if (dp->d_namlen > maxlen) {
- if (fts_palloc(sp, (size_t)dp->d_namlen)) {
+ if (namlen > maxlen) {
+ if (fts_palloc(sp, (size_t)namlen)) {
/*
* No more memory for path or structures. Save
* errno, free up the current structure and the
maxlen = sp->fts_pathlen - sp->fts_cur->fts_pathlen - 1;
}
- p->fts_pathlen = len + dp->d_namlen + 1;
+ p->fts_pathlen = len + namlen + 1;
p->fts_parent = sp->fts_cur;
p->fts_level = level;
-/* Copyright (C) 1992, 1995 Free Software Foundation, Inc.
+/* Copyright (C) 1992, 1995, 1996 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ian Lance Taylor (ian@airs.com).
{
struct stat s;
int flag, retval, newlev;
+ size_t namlen;
++got;
if (entry->d_name[0] == '.'
- && (entry->d_namlen == 1 ||
- (entry->d_namlen == 2 && entry->d_name[1] == '.')))
+ && (entry->d_name[1] == '\0' ||
+ (entry->d_name[1] == '.' && entry->d_name[2] == '\0')))
{
errno = 0;
continue;
}
- if (entry->d_namlen + len + 1 > PATH_MAX)
+ namlen = _D_EXACT_NAMLEN (entry);
+
+ if (namlen + len + 1 > PATH_MAX)
{
#ifdef ENAMETOOLONG
errno = ENAMETOOLONG;
dir[len] = '/';
memcpy ((PTR) (dir + len + 1), (PTR) entry->d_name,
- entry->d_namlen + 1);
+ namlen + 1);
if (stat (dir, &s) < 0)
{
{
if (retval == 0)
retval = ftw_dir (dirs, newlev, descriptors, dir,
- entry->d_namlen + len + 1, func);
+ namlen + len + 1, func);
if (dirs[newlev] != NULL)
{
int save;
while ((d = readdir (dirstream)) != NULL)
{
if (d->d_name[0] == '.' &&
- (d->d_namlen == 1 || (d->d_namlen == 2 && d->d_name[1] == '.')))
+ (d->d_name[1] == '\0' ||
+ (d->d_name[1] == '.' && d->d_name[2] == '\0')))
continue;
if (mount_point || d->d_ino == thisino)
{
- char *name = __alloca (dotlist + dotsize - dotp +
- 1 + d->d_namlen + 1);
+ char name[dotlist + dotsize - dotp + 1 + _D_ALLOC_NAMLEN (d)];
memcpy (name, dotp, dotlist + dotsize - dotp);
name[dotlist + dotsize - dotp] = '/';
- memcpy (&name[dotlist + dotsize - dotp + 1],
- d->d_name, d->d_namlen + 1);
+ strcpy (&name[dotlist + dotsize - dotp + 1], d->d_name);
if (__lstat (name, &st) < 0)
{
int save = errno;
}
else
{
- if (pathp - path < d->d_namlen + 1)
+ size_t namlen = _D_EXACT_NAMLEN (d);
+
+ if (pathp - path < namlen)
{
if (buf != NULL)
{
path = buf;
}
}
- pathp -= d->d_namlen;
- (void) memcpy (pathp, d->d_name, d->d_namlen);
+ pathp -= namlen;
+ (void) memcpy (pathp, d->d_name, namlen);
*--pathp = '/';
(void) closedir (dirstream);
}
-/* Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1992, 1993, 1996 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
while ((d = readdir (dirstream)) != NULL)
if (d->d_fileno == myino)
{
- if (sizeof (dev) + d->d_namlen + 1 > namelen)
+ size_t dlen = _D_ALLOC_NAMLEN (d);
+ if (sizeof (dev) + dlen > namelen)
{
free (name);
- namelen = 2 * (sizeof (dev) + d->d_namlen + 1); /* Big enough. */
+ namelen = 2 * (sizeof (dev) + dlen); /* Big enough. */
name = malloc (namelen);
if (! name)
return NULL;
(void) memcpy (name, dev, sizeof (dev) - 1);
name[sizeof (dev) - 1] = '/';
}
- (void) memcpy (&name[sizeof (dev)], d->d_name, d->d_namlen + 1);
+ (void) memcpy (&name[sizeof (dev)], d->d_name, dlen);
if (stat (name, &st) == 0 && st.st_dev == mydev)
{
(void) closedir (dirstream);
--- /dev/null
+/* Directory entry structure `struct dirent'. 4.4BSD version.
+Copyright (C) 1996 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+struct dirent
+ {
+ __ino_t d_fileno; /* File serial number. */
+ unsigned short int d_reclen; /* Length of the whole `struct dirent'. */
+ unsigned char d_type; /* File type, possibly unknown. */
+ unsigned char d_namlen; /* Length of the file name. */
+
+ /* Only this member is in the POSIX standard. */
+ char d_name[1]; /* File name (actually longer). */
+ };
+
+#define _DIRENT_HAVE_D_RECLEN 1
+#define _DIRENT_HAVE_D_NAMLEN 1
+#define _DIRENT_HAVE_D_TYPE 1