2011-02-25 Ralf Corsépius <ralf.corsepius@rtems.org>

* libcsupport/src/opendir.c, libcsupport/src/closedir.c,
	libcsupport/src/readdir.c, libcsupport/src/rewinddir.c,
	libcsupport/src/scandir.c, libcsupport/src/seekdir.c,
	libcsupport/src/telldir.c: Remove.
	* libcsuppport/Makefile.am: Reflect changes above.
	* configure.ac: Error out if libc doesn't provide
	opendir, closedir, readdir, rewinddir, scandir, seekdir,
	telldir.
This commit is contained in:
Ralf Corsepius
2011-02-25 02:13:21 +00:00
parent e530f72f73
commit bbc1a10935
10 changed files with 17 additions and 577 deletions
+11
View File
@@ -1,3 +1,14 @@
2011-02-25 Ralf Corsépius <ralf.corsepius@rtems.org>
* libcsupport/src/opendir.c, libcsupport/src/closedir.c,
libcsupport/src/readdir.c, libcsupport/src/rewinddir.c,
libcsupport/src/scandir.c, libcsupport/src/seekdir.c,
libcsupport/src/telldir.c: Remove.
* libcsuppport/Makefile.am: Reflect changes above.
* configure.ac: Error out if libc doesn't provide
opendir, closedir, readdir, rewinddir, scandir, seekdir,
telldir.
2011-02-24 Ralf Corsépius <ralf.corsepius@rtems.org>
* libcsupport/include/sys/statvfs.h: Remove include <sys/cdefs.h>
+6 -2
View File
@@ -49,8 +49,12 @@ AC_CHECK_FUNCS([isascii fileno])
# Check for functions supplied by newlib >= 1.17.0
# Newlib's posix/ directory
AC_CHECK_FUNCS([sleep usleep \
opendir closedir readdir readdir_r \
rewinddir scandir seekdir telldir isatty])
readdir_r \
isatty])
AC_CHECK_FUNCS([opendir closedir readdir rewinddir scandir seekdir telldir],,
[rtems_missing_func="$ac_func";break])
AS_IF([test -n "$rtems_missing_func"],
AC_MSG_ERROR([Missing function $rtems_missing_func in libc])])
AC_CHECK_FUNCS([creat])
AC_CHECK_FUNCS([__assert])
AC_CHECK_FUNCS([execl execlp execle execv execvp execve])
-3
View File
@@ -76,9 +76,6 @@ SYSTEM_CALL_C_FILES += src/readv.c src/writev.c
endif
DIRECTORY_SCAN_C_FILES =
## 20 Nov 2008: Now using these from newlib's posix directory
DIRECTORY_SCAN_C_FILES += src/opendir.c src/closedir.c src/readdir.c \
src/rewinddir.c src/scandir.c src/seekdir.c src/telldir.c
## Newlib SHOULD have provided this one
DIRECTORY_SCAN_C_FILES += src/readdir_r.c
## Comment out when using these from newlib's unix directory
-78
View File
@@ -1,78 +0,0 @@
/*
* closedir() - POSIX 1003.1b - XXX
*
* This was copied from Newlib 1.8.0.
*
*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)closedir.c 5.9 (Berkeley) 2/23/91";
#endif /* LIBC_SCCS and not lint */
#if HAVE_CONFIG_H
#include "config.h"
#endif
#ifndef HAVE_CLOSEDIR
#include <sys/types.h>
#include <dirent.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <rtems/libio_.h>
#include <rtems/seterr.h>
/*
* close a directory.
*/
int
closedir(
DIR *dirp )
{
int fd;
if ( !dirp )
rtems_set_errno_and_return_minus_one( EBADF );
fd = dirp->dd_fd;
dirp->dd_fd = -1;
dirp->dd_loc = 0;
(void)free((void *)dirp->dd_buf);
(void)free((void *)dirp);
return(close(fd));
}
#endif
-93
View File
@@ -1,93 +0,0 @@
/*
* opendir() - POSIX 1003.1b - XXX
*
* This was copied from Newlib 1.8.0.
*
*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)opendir.c 5.11 (Berkeley) 2/23/91";
#endif /* LIBC_SCCS and not lint */
#if HAVE_CONFIG_H
#include "config.h"
#endif
#ifndef HAVE_OPENDIR
#include <dirent.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
/*
* open a directory.
*/
DIR *
opendir(
const char *name )
{
register DIR *dirp;
register int fd;
if ((fd = open(name, 0)) == -1)
return NULL;
if (fcntl(fd, F_SETFD, 1) == -1 ||
(dirp = (DIR *)malloc(sizeof(DIR))) == NULL) {
close (fd);
return NULL;
}
/*
* If CLSIZE is an exact multiple of DIRBLKSIZ, use a CLSIZE
* buffer that it cluster boundary aligned.
* Hopefully this can be a big win someday by allowing page trades
* to user space to be done by getdirentries()
*/
dirp->dd_buf = malloc (512);
dirp->dd_len = 512;
if (dirp->dd_buf == NULL) {
close (fd);
return NULL;
}
dirp->dd_fd = fd;
dirp->dd_loc = 0;
dirp->dd_seek = 0;
/*
* Set up seek point for rewinddir.
*/
return dirp;
}
#endif
-95
View File
@@ -1,95 +0,0 @@
/*
* readdir() - POSIX 1003.1b - XXX
*
* This was copied from Newlib 1.8.0.
*
*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)readdir.c 5.7 (Berkeley) 6/1/90";
#endif /* LIBC_SCCS and not lint */
#if HAVE_CONFIG_H
#include "config.h"
#endif
#ifndef HAVE_READDIR
#include <dirent.h>
#include <stdint.h>
extern int getdents(
int dd_fd,
char *dd_buf,
int dd_len
);
/*
* get next entry in a directory.
*/
struct dirent *
readdir( DIR *dirp )
{
register struct dirent *dp;
if ( !dirp )
return NULL;
for (;;) {
if (dirp->dd_loc == 0) {
dirp->dd_size = getdents (dirp->dd_fd,
dirp->dd_buf,
dirp->dd_len);
if (dirp->dd_size <= 0)
return NULL;
}
if (dirp->dd_loc >= dirp->dd_size) {
dirp->dd_loc = 0;
continue;
}
dp = (struct dirent *)(dirp->dd_buf + dirp->dd_loc);
if ((intptr_t)dp & 03) /* bogus pointer check */
return NULL;
if (dp->d_reclen <= 0 ||
dp->d_reclen > dirp->dd_len + 1 - dirp->dd_loc)
return NULL;
dirp->dd_loc += dp->d_reclen;
if (dp->d_ino == 0)
continue;
return (dp);
}
}
#endif
-42
View File
@@ -1,42 +0,0 @@
/*
* rewinddir() - POSIX 1003.1b - XXX
*
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#ifndef HAVE_REWINDDIR
#include <sys/types.h>
#include <dirent.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
void rewinddir(
DIR *dirp
)
{
off_t status;
if ( !dirp )
return;
status = lseek( dirp->dd_fd, 0, SEEK_SET );
if( status == -1 )
return;
dirp->dd_loc = 0;
}
#endif
-168
View File
@@ -1,168 +0,0 @@
/*
* scandir() - POSIX 1003.1b - XXX
*
* This was copied from Newlib 1.8.0.
*
*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)scandir.c 5.10 (Berkeley) 2/23/91";
#endif /* LIBC_SCCS and not lint */
#if HAVE_CONFIG_H
#include "config.h"
#endif
/*
* Scan the directory dirname calling select to make a list of selected
* directory entries then sort using qsort and compare routine dcomp.
* Returns the number of entries and a pointer to a list of pointers to
* struct dirent (through namelist). Returns -1 if there were any errors.
*/
#ifndef HAVE_SCANDIR
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <stdlib.h>
#include <string.h>
/*
* The DIRSIZ macro gives the minimum record length which will hold
* the directory entry. This requires the amount of space in struct dirent
* without the d_name field, plus enough space for the name with a terminating
* null byte (dp->d_namlen+1), rounded up to a 4 byte boundary.
*/
#undef DIRSIZ
/*
#define DIRSIZ(dp) \
((sizeof (struct dirent) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
*/
#define DIRSIZ(dp) \
((sizeof (struct dirent) - (NAME_MAX+1)) + (((dp)->d_namlen+1 + 3) &~ 3))
int
scandir(
const char *dirname,
struct dirent ***namelist,
int (*select)(struct dirent *),
int (*dcomp)(const struct dirent **, const struct dirent **))
{
register struct dirent *d = NULL;
register struct dirent *p = NULL;
register struct dirent **names = NULL;
register size_t nitems = 0;
struct stat stb;
size_t arraysz;
DIR *dirp = NULL;
int i;
if ((dirp = opendir(dirname)) == NULL)
return(-1);
if (fstat(dirp->dd_fd, &stb) < 0)
goto cleanup_and_bail;
/*
* estimate the array size by taking the size of the directory file
* and dividing it by a multiple of the minimum size entry.
*/
arraysz = (stb.st_size / 24);
names = (struct dirent **)malloc(arraysz * sizeof(struct dirent *));
if (names == NULL)
goto cleanup_and_bail;
while ((d = readdir(dirp)) != NULL) {
if (select != NULL && !(*select)(d))
continue; /* just selected names */
/*
* Make a minimum size copy of the data
*/
p = (struct dirent *)malloc(DIRSIZ(d));
if (p == NULL)
goto cleanup_and_bail;
p->d_ino = d->d_ino;
p->d_reclen = d->d_reclen;
p->d_namlen = d->d_namlen;
strncpy(p->d_name, d->d_name, p->d_namlen + 1);
/*
* Check to make sure the array has space left and
* realloc the maximum size.
*/
if (++nitems >= arraysz) {
if (fstat(dirp->dd_fd, &stb) < 0)
goto cleanup_and_bail; /* just might have grown */
arraysz = stb.st_size / 12;
names = (struct dirent **)realloc((char *)names,
arraysz * sizeof(struct dirent *));
if (names == NULL)
goto cleanup_and_bail;
}
names[nitems-1] = p;
}
closedir(dirp);
if (nitems && dcomp != NULL){
qsort(names, nitems, sizeof(struct dirent *),
(int (*)(const void *, const void *)) dcomp);
}
*namelist = names;
return(nitems);
cleanup_and_bail:
if ( dirp )
closedir( dirp );
if ( names ) {
for (i=0; i < nitems; i++ )
free( names[i] );
free( names );
}
return(-1);
}
/*
* Alphabetic order comparison routine for those who want it.
*/
int
alphasort(
const void *d1,
const void *d2 )
{
return(strcmp((*(struct dirent **)d1)->d_name,
(*(struct dirent **)d2)->d_name));
}
#endif
-47
View File
@@ -1,47 +0,0 @@
/*
* seekdir() - POSIX 1003.1b - XXX
*
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#ifndef HAVE_SEEKDIR
#include <sys/param.h>
#include <dirent.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
void seekdir(
DIR *dirp,
long loc
)
{
off_t status;
if ( !dirp )
return;
status = lseek( dirp->dd_fd, loc, SEEK_SET );
/*
* This is not a nice way to error out, but we have no choice here.
*/
if ( status == -1 )
return;
dirp->dd_loc = 0;
}
#endif
-49
View File
@@ -1,49 +0,0 @@
/*
* telldir() - XXX
*
* COPYRIGHT (c) 1989-2010.
* On-Line Applications Research Corporation (OAR).
*
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.com/license/LICENSE.
*
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#ifndef HAVE_TELLDIR
#include <sys/param.h>
#include <dirent.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <rtems/libio_.h>
#include <rtems/seterr.h>
long telldir(
DIR *dirp
)
{
rtems_libio_t *iop;
if ( !dirp )
rtems_set_errno_and_return_minus_one( EBADF );
/*
* Get the file control block structure associated with the
* file descriptor
*/
iop = rtems_libio_iop( dirp->dd_fd );
if ( !iop )
rtems_set_errno_and_return_minus_one( EBADF );
return (long)( iop->offset );
}
#endif