mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
Split libc/dirent/dir.cpp into multiple files.
This commit is contained in:
parent
d7467e98be
commit
ddce6045e0
13 changed files with 372 additions and 95 deletions
|
@ -22,7 +22,17 @@ aux/c++.o \
|
|||
aux/op-new.o \
|
||||
ctype/ctype.o \
|
||||
dirent/alphasort.o \
|
||||
dirent/dir.o \
|
||||
dirent/closedir.o \
|
||||
dirent/dclearerr.o \
|
||||
dirent/dcloseall.o \
|
||||
dirent/deof.o \
|
||||
dirent/derror.o \
|
||||
dirent/dirfd.o \
|
||||
dirent/dnewdir.o \
|
||||
dirent/dregister.o \
|
||||
dirent/dunregister.o \
|
||||
dirent/readdir.o \
|
||||
dirent/rewinddir.o \
|
||||
dirent/versionsort.o \
|
||||
errno/errno.o \
|
||||
fnmatch/fnmatch.o \
|
||||
|
|
37
libc/dirent/closedir.cpp
Normal file
37
libc/dirent/closedir.cpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*******************************************************************************
|
||||
|
||||
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/closedir.cpp
|
||||
Closes a directory stream.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <dirent.h>
|
||||
#include <DIR.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
extern "C" int closedir(DIR* dir)
|
||||
{
|
||||
int result = dir->close_func ? dir->close_func(dir->user) : 0;
|
||||
dunregister(dir);
|
||||
free(dir->entry);
|
||||
if ( dir->free_func )
|
||||
dir->free_func(dir);
|
||||
return result;
|
||||
}
|
31
libc/dirent/dclearerr.cpp
Normal file
31
libc/dirent/dclearerr.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*******************************************************************************
|
||||
|
||||
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/dclearerr.cpp
|
||||
Clears the error flag from a directory stream.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <dirent.h>
|
||||
#include <DIR.h>
|
||||
|
||||
extern "C" void dclearerr(DIR* dir)
|
||||
{
|
||||
dir->flags &= ~_DIR_ERROR;
|
||||
}
|
37
libc/dirent/dcloseall.cpp
Normal file
37
libc/dirent/dcloseall.cpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*******************************************************************************
|
||||
|
||||
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/dcloseall.cpp
|
||||
Closes all registered directory streams.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <dirent.h>
|
||||
#include <DIR.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern "C" { DIR* __firstdir = NULL; }
|
||||
|
||||
extern "C" int dcloseall(void)
|
||||
{
|
||||
int result = 0;
|
||||
while ( __firstdir )
|
||||
result |= closedir(__firstdir);
|
||||
return result ? EOF : 0;
|
||||
}
|
31
libc/dirent/deof.cpp
Normal file
31
libc/dirent/deof.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*******************************************************************************
|
||||
|
||||
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/deof.cpp
|
||||
Returns the end-of-file flag of a directory stream.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <dirent.h>
|
||||
#include <DIR.h>
|
||||
|
||||
extern "C" int deof(DIR* dir)
|
||||
{
|
||||
return dir->flags & _DIR_EOF;
|
||||
}
|
31
libc/dirent/derror.cpp
Normal file
31
libc/dirent/derror.cpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*******************************************************************************
|
||||
|
||||
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/derror.cpp
|
||||
Returns the error flag of a directory stream.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <dirent.h>
|
||||
#include <DIR.h>
|
||||
|
||||
extern "C" int derror(DIR* dir)
|
||||
{
|
||||
return dir->flags & _DIR_ERROR;
|
||||
}
|
34
libc/dirent/dirfd.cpp
Normal file
34
libc/dirent/dirfd.cpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*******************************************************************************
|
||||
|
||||
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/dirfd.cpp
|
||||
Returns the file descriptor associated with the directory stream.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <dirent.h>
|
||||
#include <DIR.h>
|
||||
#include <errno.h>
|
||||
|
||||
extern "C" int dirfd(DIR* dir)
|
||||
{
|
||||
if ( !dir->fd_func )
|
||||
return errno = EBADF, 0;
|
||||
return dir->fd_func(dir->user);
|
||||
}
|
44
libc/dirent/dnewdir.cpp
Normal file
44
libc/dirent/dnewdir.cpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*******************************************************************************
|
||||
|
||||
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/dnewdir.cpp
|
||||
Allocates and registers a new directory stream structure.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <dirent.h>
|
||||
#include <DIR.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static void dfreedir(DIR* dir)
|
||||
{
|
||||
free(dir);
|
||||
}
|
||||
|
||||
extern "C" DIR* dnewdir(void)
|
||||
{
|
||||
DIR* dir = (DIR*) calloc(sizeof(DIR), 1);
|
||||
if ( !dir )
|
||||
return NULL;
|
||||
dir->flags = 0;
|
||||
dir->free_func = dfreedir;
|
||||
dregister(dir);
|
||||
return dir;
|
||||
}
|
34
libc/dirent/dregister.cpp
Normal file
34
libc/dirent/dregister.cpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*******************************************************************************
|
||||
|
||||
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/dregister.cpp
|
||||
Registers an directory stream for later automatic closing.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <dirent.h>
|
||||
#include <DIR.h>
|
||||
|
||||
extern "C" void dregister(DIR* dir)
|
||||
{
|
||||
dir->flags |= _DIR_REGISTERED;
|
||||
if ( (dir->next = __firstdir) )
|
||||
dir->next->prev = dir;
|
||||
__firstdir = dir;
|
||||
}
|
39
libc/dirent/dunregister.cpp
Normal file
39
libc/dirent/dunregister.cpp
Normal 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/dunregister.cpp
|
||||
Unregisters an directory stream for later automatic closing.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <dirent.h>
|
||||
#include <DIR.h>
|
||||
|
||||
extern "C" void dunregister(DIR* dir)
|
||||
{
|
||||
if ( !(dir->flags & _DIR_REGISTERED) )
|
||||
return;
|
||||
if ( !dir->prev )
|
||||
__firstdir = dir->next;
|
||||
if ( dir->prev )
|
||||
dir->prev->next = dir->next;
|
||||
if ( dir->next )
|
||||
dir->next->prev = dir->prev;
|
||||
dir->flags &= ~_DIR_REGISTERED;
|
||||
}
|
|
@ -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,50 +17,24 @@
|
|||
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/dir.cpp
|
||||
DIR* is an interface allowing various directory backends.
|
||||
dirent/readdir.cpp
|
||||
Reads a directory entry from a directory stream into a DIR-specific buffer.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#include <dirent.h>
|
||||
#include <DIR.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
static DIR* firstdir = NULL;
|
||||
|
||||
extern "C" void dregister(DIR* dir)
|
||||
{
|
||||
dir->flags |= _DIR_REGISTERED;
|
||||
if ( !firstdir ) { firstdir = dir; return; }
|
||||
dir->next = firstdir;
|
||||
firstdir->prev = dir;
|
||||
firstdir = dir;
|
||||
}
|
||||
|
||||
extern "C" void dunregister(DIR* dir)
|
||||
{
|
||||
if ( !(dir->flags & _DIR_REGISTERED) )
|
||||
return;
|
||||
if ( !dir->prev )
|
||||
firstdir = dir->next;
|
||||
if ( dir->prev )
|
||||
dir->prev->next = dir->next;
|
||||
if ( dir->next )
|
||||
dir->next->prev = dir->prev;
|
||||
dir->flags &= ~_DIR_REGISTERED;
|
||||
}
|
||||
|
||||
extern "C" struct dirent* readdir(DIR* dir)
|
||||
{
|
||||
if ( !dir->read_func )
|
||||
{
|
||||
dir->flags |= _DIR_ERROR;
|
||||
errno = EBADF;
|
||||
return 0;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t size = dir->entrysize;
|
||||
|
@ -70,6 +44,7 @@ extern "C" struct dirent* readdir(DIR* dir)
|
|||
dir->flags |= _DIR_ERROR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ( 0 < status )
|
||||
{
|
||||
struct dirent* biggerdir = (struct dirent*) malloc(size);
|
||||
|
@ -94,66 +69,3 @@ extern "C" struct dirent* readdir(DIR* dir)
|
|||
|
||||
return dir->entry;
|
||||
}
|
||||
|
||||
extern "C" int closedir(DIR* dir)
|
||||
{
|
||||
int result = (dir->close_func) ? dir->close_func(dir->user) : 0;
|
||||
dunregister(dir);
|
||||
free(dir->entry);
|
||||
if ( dir->free_func )
|
||||
dir->free_func(dir);
|
||||
return result;
|
||||
}
|
||||
|
||||
extern "C" void rewinddir(DIR* dir)
|
||||
{
|
||||
if ( dir->rewind_func )
|
||||
dir->rewind_func(dir->user);
|
||||
dir->flags &= ~_DIR_EOF;
|
||||
}
|
||||
|
||||
extern "C" int dirfd(DIR* dir)
|
||||
{
|
||||
if ( !dir->fd_func )
|
||||
return errno = EBADF, 0;
|
||||
return dir->fd_func(dir->user);
|
||||
}
|
||||
|
||||
extern "C" void dclearerr(DIR* dir)
|
||||
{
|
||||
dir->flags &= ~_DIR_ERROR;
|
||||
}
|
||||
|
||||
extern "C" int derror(DIR* dir)
|
||||
{
|
||||
return dir->flags & _DIR_ERROR;
|
||||
}
|
||||
|
||||
extern "C" int deof(DIR* dir)
|
||||
{
|
||||
return dir->flags & _DIR_EOF;
|
||||
}
|
||||
|
||||
static void dfreedir(DIR* dir)
|
||||
{
|
||||
free(dir);
|
||||
}
|
||||
|
||||
extern "C" DIR* dnewdir(void)
|
||||
{
|
||||
DIR* dir = (DIR*) calloc(sizeof(DIR), 1);
|
||||
if ( !dir )
|
||||
return NULL;
|
||||
dir->flags = 0;
|
||||
dir->free_func = dfreedir;
|
||||
dregister(dir);
|
||||
return dir;
|
||||
}
|
||||
|
||||
extern "C" int dcloseall(void)
|
||||
{
|
||||
int result = 0;
|
||||
while ( firstdir )
|
||||
result |= closedir(firstdir);
|
||||
return result ? EOF : 0;
|
||||
}
|
33
libc/dirent/rewinddir.cpp
Normal file
33
libc/dirent/rewinddir.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*******************************************************************************
|
||||
|
||||
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/rewinddir.cpp
|
||||
Rewinds a directory stream to the start.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
#include <dirent.h>
|
||||
#include <DIR.h>
|
||||
|
||||
extern "C" void rewinddir(DIR* dir)
|
||||
{
|
||||
if ( dir->rewind_func )
|
||||
dir->rewind_func(dir->user);
|
||||
dir->flags &= ~_DIR_EOF;
|
||||
}
|
|
@ -86,6 +86,10 @@ int derror(DIR* dir);
|
|||
int deof(DIR* dif);
|
||||
#endif
|
||||
|
||||
#if defined(__is_sortix_libc)
|
||||
extern DIR* __firstdir;
|
||||
#endif
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue