From f108a3613f5ce5a0389ba742b9994544ccdb6ed7 Mon Sep 17 00:00:00 2001 From: Marian Ohligs Date: Tue, 8 Nov 2011 21:49:00 +0100 Subject: [PATCH] add newlib support for readdir --- newlib/src/libgloss/metalsvm/Makefile.in | 3 +- newlib/src/libgloss/metalsvm/closedir.c | 10 ++-- .../libgloss/metalsvm/include/sys/dirent.h | 4 +- newlib/src/libgloss/metalsvm/opendir.c | 13 ++--- newlib/src/libgloss/metalsvm/readdir.c | 55 +++++++++++++++++++ 5 files changed, 70 insertions(+), 15 deletions(-) create mode 100644 newlib/src/libgloss/metalsvm/readdir.c diff --git a/newlib/src/libgloss/metalsvm/Makefile.in b/newlib/src/libgloss/metalsvm/Makefile.in index cc213e2e..05ead49f 100644 --- a/newlib/src/libgloss/metalsvm/Makefile.in +++ b/newlib/src/libgloss/metalsvm/Makefile.in @@ -64,7 +64,7 @@ METALSVM_BSP = libgloss.a METALSVM_OBJS = chown.o errno.o fork.o gettod.o kill.o open.o sbrk.o times.o write.o \ close.o execve.o fstat.o init.o link.o read.o stat.o unlink.o \ environ.o _exit.o getpid.o isatty.o lseek.o readlink.o symlink.o wait.o \ - dup.o dup2.o closedir.o opendir.o + dup.o dup2.o closedir.o opendir.o readdir.o #### Host specific Makefile fragment comes in here. @@ -110,6 +110,7 @@ dup.o: $(srcdir)/dup.c dup2.o: $(srcdir)/dup2.c opendir.o: $(srcdir)/opendir.c closedir.o: $(srcdir)/closedir.c +readdir.o: $(srcdir)/readdir.c install: $($(CPU)_INSTALL) $(INSTALL_DATA) $(CRT0) $(DESTDIR)$(tooldir)/lib${MULTISUBDIR}/$(CRT0) diff --git a/newlib/src/libgloss/metalsvm/closedir.c b/newlib/src/libgloss/metalsvm/closedir.c index 73b8545d..bcf83eaf 100644 --- a/newlib/src/libgloss/metalsvm/closedir.c +++ b/newlib/src/libgloss/metalsvm/closedir.c @@ -50,12 +50,12 @@ int _DEFUN (closedir, (dirp), DIR * dirp) { - int fd; + int fildes; - fd = dirp->dd_fd; + fildes = dirp->dd_fd; dirp->dd_fd = -1; dirp->dd_loc = 0; - (void)free((void *)dirp->dd_buf); - (void)free((void *)dirp); - return(close(fd)); + free((void *)dirp->dd_buf); + free((void *)dirp); + return(close(fildes)); } diff --git a/newlib/src/libgloss/metalsvm/include/sys/dirent.h b/newlib/src/libgloss/metalsvm/include/sys/dirent.h index 72804217..d12acba5 100644 --- a/newlib/src/libgloss/metalsvm/include/sys/dirent.h +++ b/newlib/src/libgloss/metalsvm/include/sys/dirent.h @@ -25,12 +25,12 @@ int closedir (DIR *); #include -struct dirent { +typedef struct dirent { long d_ino; off_t d_off; unsigned short d_reclen; /* we need better syntax for variable-sized arrays */ char d_name[1]; -}; +} dirent_t; #endif diff --git a/newlib/src/libgloss/metalsvm/opendir.c b/newlib/src/libgloss/metalsvm/opendir.c index 052b8476..e4ee63cc 100644 --- a/newlib/src/libgloss/metalsvm/opendir.c +++ b/newlib/src/libgloss/metalsvm/opendir.c @@ -50,15 +50,15 @@ _DEFUN (opendir, (name), const char *name) { DIR *dirp; - int fd; + int fildes; - fd = open(name, 0); + fildes = open(name, 0); - if (fd < 0) + if (fildes < 0) return NULL; dirp = (DIR *)malloc(sizeof(DIR)); if (dirp == NULL) { - close(fd); + close(fildes); return NULL; } @@ -66,12 +66,11 @@ _DEFUN (opendir, (name), dirp->dd_len = 512; if (dirp->dd_buf == NULL) { - close(fd); + close(fildes); return NULL; } - dirp->dd_fd = fd; + dirp->dd_fd = fildes; dirp->dd_loc = 0; - /* Set up seek point for rewinddir. */ dirp->dd_seek = 0; return dirp; diff --git a/newlib/src/libgloss/metalsvm/readdir.c b/newlib/src/libgloss/metalsvm/readdir.c new file mode 100644 index 00000000..0c32b69d --- /dev/null +++ b/newlib/src/libgloss/metalsvm/readdir.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2011, Marian Ohligs, Chair for Operating Systems, + * RWTH Aachen University + * + * 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 Chair for Operating Systems, + * RWTH Aachen University. + * 4. Neither the name of the Chair for Operating Systems, RWTH Aachen 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 ''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 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. + * + * This file is part of MetalSVM. + */ + +#include "config.h" +#include <_ansi.h> +#include <_syslist.h> +#include +#include +#undef errno +extern int errno; +#include "warning.h" +#include "syscall.h" + +dirent_t* +_DEFUN (readdir, (dirp), + DIR *dirp) +{ + dirent_t* dirent; + + read(dirp->dd_fd, dirent, 0); + + return dirent; +}