diff options
author | gcc <gcc@7b3dc134-2b1b-0410-93df-9e9f96275f8d> | 2006-08-17 01:18:26 +0000 |
---|---|---|
committer | gcc <gcc@7b3dc134-2b1b-0410-93df-9e9f96275f8d> | 2006-08-17 01:18:26 +0000 |
commit | 15f34685e7a9b5caf761af2ebf6afa20438d440b (patch) | |
tree | dc04ce3cdf040f198743c15b64557824de174680 /libc/dirent | |
parent | 1e848e0e775a36f6359161f5deb890942ef42ff3 (diff) |
Import glibc-mainline for 2006-08-16
git-svn-id: svn://svn.eglibc.org/fsf/trunk@4 7b3dc134-2b1b-0410-93df-9e9f96275f8d
Diffstat (limited to 'libc/dirent')
29 files changed, 1643 insertions, 0 deletions
diff --git a/libc/dirent/.cvsignore b/libc/dirent/.cvsignore new file mode 100644 index 000000000..3fc9f4cdf --- /dev/null +++ b/libc/dirent/.cvsignore @@ -0,0 +1,6 @@ +*.d *.o *.so *.po *.go stamp.* *.stamp *.ustamp *.udeps +*.gz *.Z *.tar *.tgz +=* +TODO COPYING* AUTHORS copyr-* copying.* +glibc-* +distinfo diff --git a/libc/dirent/Makefile b/libc/dirent/Makefile new file mode 100644 index 000000000..ef639f209 --- /dev/null +++ b/libc/dirent/Makefile @@ -0,0 +1,39 @@ +# Copyright (C) 1991-2000,2002,2003,2005,2006 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 Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 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 +# Lesser General Public License for more details. + +# You should have received a copy of the GNU Lesser General Public +# License along with the GNU C Library; if not, write to the Free +# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA +# 02111-1307 USA. + +# +# Sub-makefile for dirent portion of the library. +# +subdir := dirent + +headers := dirent.h bits/dirent.h +routines := opendir closedir readdir readdir_r rewinddir \ + seekdir telldir scandir alphasort versionsort \ + getdents getdents64 dirfd readdir64 readdir64_r scandir64 \ + alphasort64 versionsort64 fdopendir +distribute := dirstream.h + +tests := list tst-seekdir opendir-tst1 bug-readdir1 tst-fdopendir \ + tst-fdopendir2 + +CFLAGS-scandir.c = $(uses-callbacks) +CFLAGS-scandir64.c = $(uses-callbacks) + +include ../Rules + +opendir-tst1-ARGS = --test-dir=${common-objpfx}dirent diff --git a/libc/dirent/Versions b/libc/dirent/Versions new file mode 100644 index 000000000..41c158442 --- /dev/null +++ b/libc/dirent/Versions @@ -0,0 +1,47 @@ +libc { + GLIBC_2.0 { + # a* + alphasort; + + # c* + closedir; + + # d* + dirfd; + + # g* + getdirentries; + + # o* + opendir; + + # r* + readdir; readdir_r; rewinddir; + + # s* + scandir; seekdir; + + # t* + telldir; + } + GLIBC_2.1 { + # a* + alphasort64; + + # r* + readdir64; readdir64_r; + + # s* + scandir64; + + # v* + versionsort; versionsort64; + } + GLIBC_2.2 { + # g* + getdirentries64; + } + GLIBC_2.4 { + fdopendir; + } +} diff --git a/libc/dirent/alphasort.c b/libc/dirent/alphasort.c new file mode 100644 index 000000000..b378626f6 --- /dev/null +++ b/libc/dirent/alphasort.c @@ -0,0 +1,27 @@ +/* Copyright (C) 1992, 1997, 1998 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 Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <dirent.h> +#include <string.h> + +int +alphasort (const void *a, const void *b) +{ + return strcoll ((*(const struct dirent **) a)->d_name, + (*(const struct dirent **) b)->d_name); +} diff --git a/libc/dirent/alphasort64.c b/libc/dirent/alphasort64.c new file mode 100644 index 000000000..fe84aec2f --- /dev/null +++ b/libc/dirent/alphasort64.c @@ -0,0 +1,27 @@ +/* Copyright (C) 1992, 1997, 1998, 2000 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 Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <dirent.h> +#include <string.h> + +int +alphasort64 (const void *a, const void *b) +{ + return strcoll ((*(const struct dirent64 **) a)->d_name, + (*(const struct dirent64 **) b)->d_name); +} diff --git a/libc/dirent/bug-readdir1.c b/libc/dirent/bug-readdir1.c new file mode 100644 index 000000000..4c3521dbb --- /dev/null +++ b/libc/dirent/bug-readdir1.c @@ -0,0 +1,38 @@ +#include <dirent.h> +#include <errno.h> +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <sys/types.h> + + +int +main (void) +{ + DIR *dirp; + struct dirent* ent; + + /* open a dir stream */ + dirp = opendir ("/tmp"); + if (dirp == NULL) + { + if (errno == ENOENT) + exit (0); + + perror ("opendir"); + exit (1); + } + + /* close the directory file descriptor, making it invalid */ + if (close (dirfd (dirp)) != 0) + { + puts ("could not close directory file descriptor"); + /* This is not an error. It is not guaranteed this is possible. */ + return 0; + } + + ent = readdir (dirp); + + return ent != NULL || errno != EBADF; +} diff --git a/libc/dirent/closedir.c b/libc/dirent/closedir.c new file mode 100644 index 000000000..4410f02fb --- /dev/null +++ b/libc/dirent/closedir.c @@ -0,0 +1,35 @@ +/* Copyright (C) 1991, 1995, 1996, 1997 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 Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <stddef.h> +#include <dirent.h> + + +/* Close the directory stream DIRP. + Return 0 if successful, -1 if not. */ +int +__closedir (DIR *dirp) +{ + __set_errno (ENOSYS); + return -1; +} +weak_alias (__closedir, closedir) + +stub_warning (closedir) +#include <stub-tag.h> diff --git a/libc/dirent/dirent.h b/libc/dirent/dirent.h new file mode 100644 index 000000000..ed4147dbc --- /dev/null +++ b/libc/dirent/dirent.h @@ -0,0 +1,351 @@ +/* Copyright (C) 1991-2000, 2003, 2004, 2005 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 Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +/* + * POSIX Standard: 5.1.2 Directory Operations <dirent.h> + */ + +#ifndef _DIRENT_H +#define _DIRENT_H 1 + +#include <features.h> + +__BEGIN_DECLS + +#include <bits/types.h> + +#ifdef __USE_XOPEN +# ifndef __ino_t_defined +# ifndef __USE_FILE_OFFSET64 +typedef __ino_t ino_t; +# else +typedef __ino64_t ino_t; +# endif +# define __ino_t_defined +# endif +# if defined __USE_LARGEFILE64 && !defined __ino64_t_defined +typedef __ino64_t ino64_t; +# define __ino64_t_defined +# endif +#endif + +/* This file defines `struct dirent'. + + It defines the macro `_DIRENT_HAVE_D_NAMLEN' iff there is a `d_namlen' + member that gives the length of `d_name'. + + It defines the macro `_DIRENT_HAVE_D_RECLEN' iff there is a `d_reclen' + member that gives the size of the entire directory entry. + + It defines the macro `_DIRENT_HAVE_D_OFF' iff there is a `d_off' + member that gives the file offset of the next directory entry. + + It defines the macro `_DIRENT_HAVE_D_TYPE' iff there is a `d_type' + member that gives the type of the file. + */ + +#include <bits/dirent.h> + +#if (defined __USE_BSD || defined __USE_MISC) && !defined d_fileno +# define d_ino d_fileno /* Backward compatibility. */ +#endif + +/* These macros extract size information from a `struct dirent *'. + They may evaluate their argument multiple times, so it must not + have side effects. Each of these may involve a relatively costly + call to `strlen' on some systems, so these values should be cached. + + _D_EXACT_NAMLEN (DP) returns the length of DP->d_name, not including + its terminating null character. + + _D_ALLOC_NAMLEN (DP) returns a size at least (_D_EXACT_NAMLEN (DP) + 1); + that is, the allocation size needed to hold the DP->d_name string. + Use this macro when you don't need the exact length, just an upper bound. + This macro is less likely to require calling `strlen' than _D_EXACT_NAMLEN. + */ + +#ifdef _DIRENT_HAVE_D_NAMLEN +# define _D_EXACT_NAMLEN(d) ((d)->d_namlen) +# define _D_ALLOC_NAMLEN(d) (_D_EXACT_NAMLEN (d) + 1) +#else +# define _D_EXACT_NAMLEN(d) (strlen ((d)->d_name)) +# ifdef _DIRENT_HAVE_D_RECLEN +# define _D_ALLOC_NAMLEN(d) (((char *) (d) + (d)->d_reclen) - &(d)->d_name[0]) +# else +# define _D_ALLOC_NAMLEN(d) (sizeof (d)->d_name > 1 ? sizeof (d)->d_name : \ + _D_EXACT_NAMLEN (d) + 1) +# endif +#endif + + +#ifdef __USE_BSD +/* File types for `d_type'. */ +enum + { + DT_UNKNOWN = 0, +# define DT_UNKNOWN DT_UNKNOWN + DT_FIFO = 1, +# define DT_FIFO DT_FIFO + DT_CHR = 2, +# define DT_CHR DT_CHR + DT_DIR = 4, +# define DT_DIR DT_DIR + DT_BLK = 6, +# define DT_BLK DT_BLK + DT_REG = 8, +# define DT_REG DT_REG + DT_LNK = 10, +# define DT_LNK DT_LNK + DT_SOCK = 12, +# define DT_SOCK DT_SOCK + DT_WHT = 14 +# define DT_WHT DT_WHT + }; + +/* Convert between stat structure types and directory types. */ +# define IFTODT(mode) (((mode) & 0170000) >> 12) +# define DTTOIF(dirtype) ((dirtype) << 12) +#endif + + +/* This is the data type of directory stream objects. + The actual structure is opaque to users. */ +typedef struct __dirstream DIR; + +/* Open a directory stream on NAME. + Return a DIR stream on the directory, or NULL if it could not be opened. + + This function is a possible cancellation point and therefore not + marked with __THROW. */ +extern DIR *opendir (__const char *__name) __nonnull ((1)); + +#ifdef __USE_GNU +/* Same as opendir, but open the stream on the file descriptor FD. + + This function is a possible cancellation point and therefore not + marked with __THROW. */ +extern DIR *fdopendir (int __fd); +#endif + +/* Close the directory stream DIRP. + Return 0 if successful, -1 if not. + + This function is a possible cancellation point and therefore not + marked with __THROW. */ +extern int closedir (DIR *__dirp) __nonnull ((1)); + +/* Read a directory entry from DIRP. Return a pointer to a `struct + dirent' describing the entry, or NULL for EOF or error. The + storage returned may be overwritten by a later readdir call on the + same DIR stream. + + If the Large File Support API is selected we have to use the + appropriate interface. + + This function is a possible cancellation point and therefore not + marked with __THROW. */ +#ifndef __USE_FILE_OFFSET64 +extern struct dirent *readdir (DIR *__dirp) __nonnull ((1)); +#else +# ifdef __REDIRECT +extern struct dirent *__REDIRECT (readdir, (DIR *__dirp), readdir64) + __nonnull ((1)); +# else +# define readdir readdir64 +# endif +#endif + +#ifdef __USE_LARGEFILE64 +extern struct dirent64 *readdir64 (DIR *__dirp) __nonnull ((1)); +#endif + +#if defined __USE_POSIX || defined __USE_MISC +/* Reentrant version of `readdir'. Return in RESULT a pointer to the + next entry. + + This function is a possible cancellation point and therefore not + marked with __THROW. */ +# ifndef __USE_FILE_OFFSET64 +extern int readdir_r (DIR *__restrict __dirp, + struct dirent *__restrict __entry, + struct dirent **__restrict __result) + __nonnull ((1, 2, 3)); +# else +# ifdef __REDIRECT +extern int __REDIRECT (readdir_r, + (DIR *__restrict __dirp, + struct dirent *__restrict __entry, + struct dirent **__restrict __result), + readdir64_r) __nonnull ((1, 2, 3)); +# else +# define readdir_r readdir64_r +# endif +# endif + +# ifdef __USE_LARGEFILE64 +extern int readdir64_r (DIR *__restrict __dirp, + struct dirent64 *__restrict __entry, + struct dirent64 **__restrict __result) + __nonnull ((1, 2, 3)); +# endif +#endif /* POSIX or misc */ + +/* Rewind DIRP to the beginning of the directory. */ +extern void rewinddir (DIR *__dirp) __THROW __nonnull ((1)); + +#if defined __USE_BSD || defined __USE_MISC || defined __USE_XOPEN +# include <bits/types.h> + +/* Seek to position POS on DIRP. */ +extern void seekdir (DIR *__dirp, long int __pos) __THROW __nonnull ((1)); + +/* Return the current position of DIRP. */ +extern long int telldir (DIR *__dirp) __THROW __nonnull ((1)); +#endif + +#if defined __USE_BSD || defined __USE_MISC + +/* Return the file descriptor used by DIRP. */ +extern int dirfd (DIR *__dirp) __THROW __nonnull ((1)); + +# if defined __OPTIMIZE__ && defined _DIR_dirfd +# define dirfd(dirp) _DIR_dirfd (dirp) +# endif + +# ifndef MAXNAMLEN +/* Get the definitions of the POSIX.1 limits. */ +# include <bits/posix1_lim.h> + +/* `MAXNAMLEN' is the BSD name for what POSIX calls `NAME_MAX'. */ +# ifdef NAME_MAX +# define MAXNAMLEN NAME_MAX +# else +# define MAXNAMLEN 255 +# endif +# endif + +# define __need_size_t +# include <stddef.h> + +/* Scan the directory DIR, calling SELECTOR on each directory entry. + Entries for which SELECT returns nonzero are individually malloc'd, + sorted using qsort with CMP, and collected in a malloc'd array in + *NAMELIST. Returns the number of entries selected, or -1 on error. */ +# ifndef __USE_FILE_OFFSET64 +extern int scandir (__const char *__restrict __dir, + struct dirent ***__restrict __namelist, + int (*__selector) (__const struct dirent *), + int (*__cmp) (__const void *, __const void *)) + __nonnull ((1, 2)); +# else +# ifdef __REDIRECT +extern int __REDIRECT (scandir, + (__const char *__restrict __dir, + struct dirent ***__restrict __namelist, + int (*__selector) (__const struct dirent *), + int (*__cmp) (__const void *, __const void *)), + scandir64) __nonnull ((1, 2)); +# else +# define scandir scandir64 +# endif +# endif + +# if defined __USE_GNU && defined __USE_LARGEFILE64 +/* This function is like `scandir' but it uses the 64bit dirent structure. + Please note that the CMP function must now work with struct dirent64 **. */ +extern int scandir64 (__const char *__restrict __dir, + struct dirent64 ***__restrict __namelist, + int (*__selector) (__const struct dirent64 *), + int (*__cmp) (__const void *, __const void *)) + __nonnull ((1, 2)); +# endif + +/* Function to compare two `struct dirent's alphabetically. */ +# ifndef __USE_FILE_OFFSET64 +extern int alphasort (__const void *__e1, __const void *__e2) + __THROW __attribute_pure__ __nonnull ((1, 2)); +# else +# ifdef __REDIRECT +extern int __REDIRECT_NTH (alphasort, + (__const void *__e1, __const void *__e2), + alphasort64) __attribute_pure__ __nonnull ((1, 2)); +# else +# define alphasort alphasort64 +# endif +# endif + +# if defined __USE_GNU && defined __USE_LARGEFILE64 +extern int alphasort64 (__const void *__e1, __const void *__e2) + __THROW __attribute_pure__ __nonnull ((1, 2)); +# endif + +# ifdef __USE_GNU +/* Function to compare two `struct dirent's by name & version. */ +# ifndef __USE_FILE_OFFSET64 +extern int versionsort (__const void *__e1, __const void *__e2) + __THROW __attribute_pure__ __nonnull ((1, 2)); +# else +# ifdef __REDIRECT +extern int __REDIRECT_NTH (versionsort, + (__const void *__e1, __const void *__e2), + versionsort64) + __attribute_pure__ __nonnull ((1, 2)); +# else +# define versionsort versionsort64 +# endif +# endif + +# ifdef __USE_LARGEFILE64 +extern int versionsort64 (__const void *__e1, __const void *__e2) + __THROW __attribute_pure__ __nonnull ((1, 2)); +# endif +# endif + +/* Read directory entries from FD into BUF, reading at most NBYTES. + Reading starts at offset *BASEP, and *BASEP is updated with the new + position after reading. Returns the number of bytes read; zero when at + end of directory; or -1 for errors. */ +# ifndef __USE_FILE_OFFSET64 +extern __ssize_t getdirentries (int __fd, char *__restrict __buf, + size_t __nbytes, + __off_t *__restrict __basep) + __THROW __nonnull ((2, 4)); +# else +# ifdef __REDIRECT +extern __ssize_t __REDIRECT_NTH (getdirentries, + (int __fd, char *__restrict __buf, + size_t __nbytes, + __off64_t *__restrict __basep), + getdirentries64) __nonnull ((2, 4)); +# else +# define getdirentries getdirentries64 +# endif +# endif + +# ifdef __USE_LARGEFILE64 +extern __ssize_t getdirentries64 (int __fd, char *__restrict __buf, + size_t __nbytes, + __off64_t *__restrict __basep) + __THROW __nonnull ((2, 4)); +# endif + +#endif /* Use BSD or misc. */ + +__END_DECLS + +#endif /* dirent.h */ diff --git a/libc/dirent/dirfd.c b/libc/dirent/dirfd.c new file mode 100644 index 000000000..06c0cde43 --- /dev/null +++ b/libc/dirent/dirfd.c @@ -0,0 +1,33 @@ +/* Return the file descriptor used by a DIR stream. Stub version. + Copyright (C) 1995, 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 Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <dirent.h> +#include <dirstream.h> +#include <errno.h> + +int +dirfd (dirp) + DIR *dirp; +{ + __set_errno (ENOSYS); + return -1; +} + +stub_warning (dirfd) +#include <stub-tag.h> diff --git a/libc/dirent/fdopendir.c b/libc/dirent/fdopendir.c new file mode 100644 index 000000000..275cfd58f --- /dev/null +++ b/libc/dirent/fdopendir.c @@ -0,0 +1,35 @@ +/* Open a directory stream from a file descriptor. Stub version. + Copyright (C) 2005, 2006 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 Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <stddef.h> +#include <dirent.h> + + +/* Open a directory stream on FD. */ +DIR * +__fdopendir (int fd) +{ + __set_errno (ENOSYS); + return NULL; +} +weak_alias (__fdopendir, fdopendir) + +stub_warning (fdopendir) +#include <stub-tag.h> diff --git a/libc/dirent/getdents.c b/libc/dirent/getdents.c new file mode 100644 index 000000000..1b1b7c7e8 --- /dev/null +++ b/libc/dirent/getdents.c @@ -0,0 +1,37 @@ +/* Copyright (C) 1991, 1995, 1996, 1997 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 Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <stddef.h> +#include <errno.h> +#include <sys/types.h> +#include <dirent.h> + +ssize_t +__getdirentries (fd, buf, nbytes, basep) + int fd; + char *buf; + size_t nbytes; + off_t *basep; +{ + __set_errno (ENOSYS); + return -1; +} +weak_alias (__getdirentries, getdirentries) + +stub_warning (getdirentries) +#include <stub-tag.h> diff --git a/libc/dirent/getdents64.c b/libc/dirent/getdents64.c new file mode 100644 index 000000000..cb30e7654 --- /dev/null +++ b/libc/dirent/getdents64.c @@ -0,0 +1,36 @@ +/* Copyright (C) 1991,95,96,97,99,2000 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 Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <stddef.h> +#include <errno.h> +#include <sys/types.h> +#include <dirent.h> + +ssize_t +getdirentries64 (fd, buf, nbytes, basep) + int fd; + char *buf; + size_t nbytes; + off64_t *basep; +{ + __set_errno (ENOSYS); + return -1; +} + +stub_warning (getdirentries64) +#include <stub-tag.h> diff --git a/libc/dirent/list.c b/libc/dirent/list.c new file mode 100644 index 000000000..bd34d87cb --- /dev/null +++ b/libc/dirent/list.c @@ -0,0 +1,76 @@ +/* Copyright (C) 1991, 1993, 1997, 1998, 2000 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 Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <stddef.h> +#include <stdio.h> +#include <stdlib.h> +#include <dirent.h> + + +static int +test (const char *name) +{ + DIR *dirp; + struct dirent *entp; + int retval = 0; + + puts (name); + + dirp = opendir (name); + if (dirp == NULL) + { + perror ("opendir"); + return 1; + } + + errno = 0; + while ((entp = readdir (dirp)) != NULL) + printf ("%s\tfile number %lu\n", + entp->d_name, (unsigned long int) entp->d_fileno); + + if (errno) + { + perror ("readdir"); + retval = 1; + } + + if (closedir (dirp) < 0) + { + perror ("closedir"); + retval = 1; + } + + return retval; +} + +int +main (int argc, char **argv) +{ + int retval = 0; + --argc; + ++argv; + + if (argc == 0) + retval = test ("."); + else + while (argc-- > 0) + retval |= test (*argv++); + + return retval; +} diff --git a/libc/dirent/opendir-tst1.c b/libc/dirent/opendir-tst1.c new file mode 100644 index 000000000..ad1c06125 --- /dev/null +++ b/libc/dirent/opendir-tst1.c @@ -0,0 +1,97 @@ +/* Copyright (C) 1998, 2000 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <dirent.h> +#include <errno.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +/* Name of the FIFO. */ +char tmpname[] = "fifoXXXXXX"; + + +/* Do the real work. */ +static int +real_test (void) +{ + DIR *dirp; + + /* This should not block for an FIFO. */ + dirp = opendir (tmpname); + + /* Successful. */ + if (dirp != NULL) + { + /* Oh, oh, how can this work? */ + fputs ("`opendir' succeeded on a FIFO???\n", stdout); + closedir (dirp); + return 1; + } + + if (errno != ENOTDIR) + { + fprintf (stdout, "`opendir' return error `%s' instead of `%s'\n", + strerror (errno), strerror (ENOTDIR)); + return 1; + } + + return 0; +} + + +static int +do_test (int argc, char *argv[]) +{ + int retval; + + if (mktemp (tmpname) == NULL) + { + perror ("mktemp"); + return 1; + } + + /* Try to generate a FIFO. */ + if (mknod (tmpname, 0600 | S_IFIFO, 0) < 0) + { + perror ("mknod"); + /* We cannot make this an error. */ + return 0; + } + + retval = real_test (); + + remove (tmpname); + + return retval; +} + + +static void +do_cleanup (void) +{ + remove (tmpname); +} +#define CLEANUP_HANDLER do_cleanup () + + +/* Include the test skeleton. */ +#include <test-skeleton.c> diff --git a/libc/dirent/opendir.c b/libc/dirent/opendir.c new file mode 100644 index 000000000..771013f6e --- /dev/null +++ b/libc/dirent/opendir.c @@ -0,0 +1,34 @@ +/* Copyright (C) 1991, 1995, 1996, 1997 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 Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <stddef.h> +#include <dirent.h> + + +/* Open a directory stream on NAME. */ +DIR * +__opendir (const char *name) +{ + __set_errno (ENOSYS); + return NULL; +} +weak_alias (__opendir, opendir) + +stub_warning (opendir) +#include <stub-tag.h> diff --git a/libc/dirent/readdir.c b/libc/dirent/readdir.c new file mode 100644 index 000000000..893b246d4 --- /dev/null +++ b/libc/dirent/readdir.c @@ -0,0 +1,33 @@ +/* Copyright (C) 1991, 1995, 1996, 1997 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 Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <stddef.h> +#include <dirent.h> + +/* Read a directory entry from DIRP. */ +struct dirent * +__readdir (DIR *dirp) +{ + __set_errno (ENOSYS); + return NULL; +} +weak_alias (__readdir, readdir) + +stub_warning (readdir) +#include <stub-tag.h> diff --git a/libc/dirent/readdir64.c b/libc/dirent/readdir64.c new file mode 100644 index 000000000..0c18bd944 --- /dev/null +++ b/libc/dirent/readdir64.c @@ -0,0 +1,32 @@ +/* Copyright (C) 1991, 1995, 1996, 1997, 1998 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 Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <stddef.h> +#include <dirent.h> + +/* Read a directory entry from DIRP. */ +struct dirent64 * +__readdir64 (DIR *dirp) +{ + __set_errno (ENOSYS); + return NULL; +} +weak_alias (__readdir64, readdir64) +stub_warning (readdir64) +#include <stub-tag.h> diff --git a/libc/dirent/readdir64_r.c b/libc/dirent/readdir64_r.c new file mode 100644 index 000000000..cf9e952e1 --- /dev/null +++ b/libc/dirent/readdir64_r.c @@ -0,0 +1,33 @@ +/* Copyright (C) 1991, 1995, 1996, 1997 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 Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <stddef.h> +#include <dirent.h> + +/* Read a directory entry from DIRP, store result in ENTRY and return + pointer to result in *RESULT. */ +int +readdir64_r (DIR *dirp, struct dirent64 *entry, struct dirent64 **result) +{ + __set_errno (ENOSYS); + *result = NULL; + return -1; +} +stub_warning (readdir64_r) +#include <stub-tag.h> diff --git a/libc/dirent/readdir_r.c b/libc/dirent/readdir_r.c new file mode 100644 index 000000000..ad45dfa50 --- /dev/null +++ b/libc/dirent/readdir_r.c @@ -0,0 +1,35 @@ +/* Copyright (C) 1991, 1995, 1996, 1997 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 Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <stddef.h> +#include <dirent.h> + +/* Read a directory entry from DIRP, store result in ENTRY and return + pointer to result in *RESULT. */ +int +__readdir_r (DIR *dirp, struct dirent *entry, struct dirent **result) +{ + __set_errno (ENOSYS); + *result = NULL; + return ENOSYS; +} +weak_alias (__readdir_r, readdir_r) + +stub_warning (readdir_r) +#include <stub-tag.h> diff --git a/libc/dirent/rewinddir.c b/libc/dirent/rewinddir.c new file mode 100644 index 000000000..e78d31688 --- /dev/null +++ b/libc/dirent/rewinddir.c @@ -0,0 +1,35 @@ +/* Copyright (C) 1991, 1995, 1996, 1997 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 Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <stddef.h> +#include <dirent.h> + + +/* Rewind DIRP to the beginning of the directory. */ +void +rewinddir (dirp) + DIR *dirp; +{ + __set_errno (ENOSYS); + /* No way to indicate failure. */ +} + + +stub_warning (rewinddir) +#include <stub-tag.h> diff --git a/libc/dirent/scandir.c b/libc/dirent/scandir.c new file mode 100644 index 000000000..89bd9e94f --- /dev/null +++ b/libc/dirent/scandir.c @@ -0,0 +1,148 @@ +/* Copyright (C) 1992-1998, 2000, 2002, 2003 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 Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <dirent.h> +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <bits/libc-lock.h> + +#ifndef SCANDIR +#define SCANDIR scandir +#define READDIR __readdir +#define DIRENT_TYPE struct dirent +#endif + +#ifndef SCANDIR_CANCEL +#define SCANDIR_CANCEL +struct scandir_cancel_struct +{ + DIR *dp; + void *v; + size_t cnt; +}; + +static void +cancel_handler (void *arg) +{ + struct scandir_cancel_struct *cp = arg; + size_t i; + void **v = cp->v; + + for (i = 0; i < cp->cnt; ++i) + free (v[i]); + free (v); + (void) __closedir (cp->dp); +} +#endif + + +int +SCANDIR (dir, namelist, select, cmp) + const char *dir; + DIRENT_TYPE ***namelist; + int (*select) (const DIRENT_TYPE *); + int (*cmp) (const void *, const void *); +{ + DIR *dp = __opendir (dir); + DIRENT_TYPE **v = NULL; + size_t vsize = 0; + struct scandir_cancel_struct c; + DIRENT_TYPE *d; + int save; + + if (dp == NULL) + return -1; + + save = errno; + __set_errno (0); + + c.dp = dp; + c.v = NULL; + c.cnt = 0; + __libc_cleanup_push (cancel_handler, &c); + + while ((d = READDIR (dp)) != NULL) + { + int use_it = select == NULL; + + if (! use_it) + { + use_it = select (d); + /* The select function might have changed errno. It was + zero before and it need to be again to make the latter + tests work. */ + __set_errno (0); + } + + if (use_it) + { + DIRENT_TYPE *vnew; + size_t dsize; + + /* Ignore errors from select or readdir */ + __set_errno (0); + + if (__builtin_expect (c.cnt == vsize, 0)) + { + DIRENT_TYPE **new; + if (vsize == 0) + vsize = 10; + else + vsize *= 2; + new = (DIRENT_TYPE **) realloc (v, vsize * sizeof (*v)); + if (new == NULL) + break; + v = new; + c.v = (void *) v; + } + + dsize = &d->d_name[_D_ALLOC_NAMLEN (d)] - (char *) d; + vnew = (DIRENT_TYPE *) malloc (dsize); + if (vnew == NULL) + break; + + v[c.cnt++] = (DIRENT_TYPE *) memcpy (vnew, d, dsize); + } + } + + if (__builtin_expect (errno, 0) != 0) + { + save = errno; + + while (c.cnt > 0) + free (v[--c.cnt]); + free (v); + c.cnt = -1; + } + else + { + /* Sort the list if we have a comparison function to sort with. */ + if (cmp != NULL) + qsort (v, c.cnt, sizeof (*v), cmp); + + *namelist = v; + } + + __libc_cleanup_pop (0); + + (void) __closedir (dp); + __set_errno (save); + + return c.cnt; +} diff --git a/libc/dirent/scandir64.c b/libc/dirent/scandir64.c new file mode 100644 index 000000000..68608de9a --- /dev/null +++ b/libc/dirent/scandir64.c @@ -0,0 +1,30 @@ +/* Copyright (C) 2000 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 Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <dirent.h> + +#define SCANDIR scandir64 +#define READDIR __readdir64 +#define DIRENT_TYPE struct dirent64 + +int scandir64 (__const char *__restrict __dir, + struct dirent64 ***__restrict __namelist, + int (*__selector) (__const struct dirent64 *), + int (*__cmp) (__const void *, __const void *)); + +#include <dirent/scandir.c> diff --git a/libc/dirent/seekdir.c b/libc/dirent/seekdir.c new file mode 100644 index 000000000..c3828cde0 --- /dev/null +++ b/libc/dirent/seekdir.c @@ -0,0 +1,41 @@ +/* Copyright (C) 1991, 1995, 1996, 1997, 1999 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 Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <sys/types.h> +#include <errno.h> +#include <stddef.h> +#include <dirent.h> + +/* Seek to position POS in DIRP. */ +void +seekdir (dirp, pos) + DIR *dirp; + long int pos; +{ + if (dirp == NULL) + { + __set_errno (EINVAL); + return; + } + + __set_errno (ENOSYS); +} + + +stub_warning (seekdir) +#include <stub-tag.h> diff --git a/libc/dirent/telldir.c b/libc/dirent/telldir.c new file mode 100644 index 000000000..7b1445232 --- /dev/null +++ b/libc/dirent/telldir.c @@ -0,0 +1,41 @@ +/* Copyright (C) 1991, 1995, 1996, 1997, 1999 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 Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <errno.h> +#include <sys/types.h> +#include <stddef.h> +#include <dirent.h> + +/* Return the current position of DIRP. */ +long int +telldir (dirp) + DIR *dirp; +{ + if (dirp == NULL) + { + __set_errno (EINVAL); + return -1l; + } + + __set_errno (ENOSYS); + return -1l; +} + + +stub_warning (telldir) +#include <stub-tag.h> diff --git a/libc/dirent/tst-fdopendir.c b/libc/dirent/tst-fdopendir.c new file mode 100644 index 000000000..3cf315d85 --- /dev/null +++ b/libc/dirent/tst-fdopendir.c @@ -0,0 +1,124 @@ +#include <stdio.h> +#include <fcntl.h> +#include <stdlib.h> +#include <unistd.h> +#include <dirent.h> +#include <stdbool.h> +#include <string.h> + + +static int +do_test (void) +{ + char fname[] = "/tmp/jXXXXXX"; + int fd = mkstemp (fname); + if (fd == -1) + { + puts ("mkstemp failed"); + return 1; + } + + write (fd, "hello", 5); + close (fd); + + struct stat64 st; + if (stat64 (fname, &st) == -1) + { + puts ("first stat failed"); + return 0; + } + + /* Make sure there is enough time between the creation and the access. */ + sleep (2); + + fd = open (fname, O_RDONLY | O_NOATIME); + if (fd == -1) + { + puts ("first open failed"); + return 1; + } + + char buf[5]; + read(fd, buf, sizeof (buf)); + close(fd); + + struct stat64 st2; + if (stat64 (fname, &st2) == -1) + { + puts ("second stat failed"); + return 0; + } + + bool no_noatime = false; +#ifdef _STATBUF_ST_NSEC + if (st.st_atim.tv_sec != st2.st_atim.tv_sec + || st.st_atim.tv_nsec != st2.st_atim.tv_nsec) +#else + if (st.st_atime != st2.st_atime) +#endif + { + puts ("file atime changed"); + no_noatime = true; + } + + unlink(fname); + + strcpy(fname, "/tmp/dXXXXXX"); + char *d = mkdtemp (fname); + if (d == NULL) + { + puts ("mkdtemp failed"); + return 1; + } + + if (stat64 (d, &st) == -1) + { + puts ("third stat failed"); + return 0; + } + sleep (2); + + fd = open64 (d, O_RDONLY|O_NDELAY|O_DIRECTORY|O_NOATIME); + if (fd == -1) + { + puts ("second open failed"); + return 1; + } + DIR *dir = fdopendir (fd); + if (dir == NULL) + { + puts ("fdopendir failed"); + return 1; + } + + struct dirent *de; + while ((de = readdir (dir)) != NULL) + ; + + closedir (dir); + + if (stat64 (d, &st2) == -1) + { + puts ("fourth stat failed"); + return 0; + } +#ifdef _STATBUF_ST_NSEC + if (!no_noatime + && (st.st_atim.tv_sec != st2.st_atim.tv_sec + || st.st_atim.tv_nsec != st2.st_atim.tv_nsec)) +#else + if (!no_noatime && st.st_atime != st2.st_atime) +#endif + { + puts ("directory atime changed"); + return 1; + } + + rmdir(fname); + + return 0; +} + +#define TIMEOUT 6 +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/libc/dirent/tst-fdopendir2.c b/libc/dirent/tst-fdopendir2.c new file mode 100644 index 000000000..3720809dc --- /dev/null +++ b/libc/dirent/tst-fdopendir2.c @@ -0,0 +1,41 @@ +#include <errno.h> +#include <dirent.h> +#include <stdio.h> +#include <unistd.h> + + +static int +do_test (void) +{ + char tmpl[] = "/tmp/tst-fdopendir2-XXXXXX"; + int fd = mkstemp (tmpl); + if (fd == -1) + { + puts ("cannot open temp file"); + return 1; + } + + errno = 0; + DIR *d = fdopendir (fd); + + int e = errno; + + close (fd); + unlink (tmpl); + + if (d != NULL) + { + puts ("fdopendir with normal file descriptor did not fail"); + return 1; + } + if (e != ENOTDIR) + { + printf ("fdopendir set errno to %d, not %d as expected\n", e, ENOTDIR); + return 1; + } + + return 0; +} + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" diff --git a/libc/dirent/tst-seekdir.c b/libc/dirent/tst-seekdir.c new file mode 100644 index 000000000..43808fecb --- /dev/null +++ b/libc/dirent/tst-seekdir.c @@ -0,0 +1,78 @@ +#include <stdio.h> +#include <dirent.h> +#include <stdlib.h> + +int +main (int argc, char *argv[]) +{ + DIR * dirp; + long int save3 = 0; + long int cur; + int i = 0; + int result = 0; + struct dirent *dp; + long int save0; + long int rewind; + + dirp = opendir ("."); + if (dirp == NULL) + { + printf ("opendir failed: %m\n"); + return 1; + } + + save0 = telldir (dirp); + if (save0 == -1) + { + printf ("telldir failed: %m\n"); + result = 1; + } + + for (dp = readdir (dirp); dp != NULL; dp = readdir (dirp)) + { + /* save position 3 (after fourth entry) */ + if (i++ == 3) + save3 = telldir (dirp); + + printf ("%s\n", dp->d_name); + + /* stop at 400 (just to make sure dirp->__offset and dirp->__size are + scrambled */ + if (i == 400) + break; + } + + printf ("going back past 4-th entry...\n"); + + /* go back to saved entry */ + seekdir (dirp, save3); + + /* Check whether telldir equals to save3 now. */ + cur = telldir (dirp); + if (cur != save3) + { + printf ("seekdir (d, %ld); telldir (d) == %ld\n", save3, cur); + result = 1; + } + + /* print remaining files (3-last) */ + for (dp = readdir (dirp); dp != NULL; dp = readdir (dirp)) + printf ("%s\n", dp->d_name); + + /* Check rewinddir */ + rewinddir (dirp); + rewind = telldir (dirp); + if (rewind == -1) + { + printf ("telldir failed: %m\n"); + result = 1; + } + else if (save0 != rewind) + { + printf ("rewinddir didn't reset directory stream\n"); + result = 1; + } + + closedir (dirp); + return result; +} diff --git a/libc/dirent/versionsort.c b/libc/dirent/versionsort.c new file mode 100644 index 000000000..d986981bc --- /dev/null +++ b/libc/dirent/versionsort.c @@ -0,0 +1,27 @@ +/* Copyright (C) 1992, 1997, 1998 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 Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <dirent.h> +#include <string.h> + +int +versionsort (const void *a, const void *b) +{ + return __strverscmp ((*(const struct dirent **) a)->d_name, + (*(const struct dirent **) b)->d_name); +} diff --git a/libc/dirent/versionsort64.c b/libc/dirent/versionsort64.c new file mode 100644 index 000000000..e47182702 --- /dev/null +++ b/libc/dirent/versionsort64.c @@ -0,0 +1,27 @@ +/* Copyright (C) 1992, 1997, 1998, 2000 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 Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <dirent.h> +#include <string.h> + +int +versionsort64 (const void *a, const void *b) +{ + return __strverscmp ((*(const struct dirent64 **) a)->d_name, + (*(const struct dirent64 **) b)->d_name); +} |