add newlib support for readdir

This commit is contained in:
Marian Ohligs 2011-11-08 21:49:00 +01:00
parent c63fa01de6
commit f108a3613f
5 changed files with 70 additions and 15 deletions

View file

@ -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)

View file

@ -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));
}

View file

@ -25,12 +25,12 @@ int closedir (DIR *);
#include <sys/types.h>
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

View file

@ -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;

View file

@ -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 <COPYRIGHT HOLDER> ''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 <COPYRIGHT HOLDER> 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 <errno.h>
#include <dirent.h>
#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;
}