Split libc/dirent/fddir-sortix.cpp into multiple files.

This commit is contained in:
Jonas 'Sortie' Termansen 2014-01-03 19:33:12 +01:00
parent ddce6045e0
commit 5dd70aa4ff
3 changed files with 45 additions and 13 deletions

View File

@ -228,7 +228,8 @@ $(CPUDIR)/fork.o \
$(CPUDIR)/setjmp.o \
$(CPUDIR)/signal.o \
$(CPUDIR)/syscall.o \
dirent/fddir-sortix.o \
dirent/fdopendir.o \
dirent/opendir.o \
dirent/scandir.o \
dlfcn/dlfcn.o \
error/gnu_error.o \

View File

@ -1,6 +1,6 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011.
Copyright(C) Jonas 'Sortie' Termansen 2011, 2014.
This file is part of the Sortix C Library.
@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
dirent/fddir-sortix.cpp
dirent/fdopendir.cpp
Handles the file descriptor backend for the DIR* API on Sortix.
*******************************************************************************/
@ -126,7 +126,8 @@ extern "C" DIR* fdopendir(int fd)
return NULL;
DIR* dir = dnewdir();
if ( !dir ) { free(info); return NULL; }
if ( !dir )
return free(info), (DIR*) NULL;
int old_dflags = fcntl(fd, F_GETFD);
if ( 0 <= old_dflags )
@ -142,12 +143,3 @@ extern "C" DIR* fdopendir(int fd)
return dir;
}
extern "C" DIR* opendir(const char* path)
{
int fd = open(path, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
if ( fd < 0 ) { return NULL; }
DIR* dir = fdopendir(fd);
if ( !dir ) { close(fd); return NULL; }
return dir;
}

39
libc/dirent/opendir.cpp Normal file
View File

@ -0,0 +1,39 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2014.
This file is part of the Sortix C Library.
The Sortix 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 3 of the License, or (at your
option) any later version.
The Sortix 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 Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
dirent/opendir.cpp
Opens a stream for the directory specified by the path.
*******************************************************************************/
#include <dirent.h>
#include <fcntl.h>
#include <stddef.h>
#include <unistd.h>
extern "C" DIR* opendir(const char* path)
{
int fd = open(path, O_RDONLY | O_DIRECTORY | O_CLOEXEC);
if ( fd < 0 )
return NULL;
DIR* dir = fdopendir(fd);
if ( !dir )
return close(fd), (DIR*) NULL;
return dir;
}