1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Remove dcloseall() and fcloseall().

This commit is contained in:
Jonas 'Sortie' Termansen 2014-08-03 17:12:56 +02:00
parent b6b19c88fd
commit 5e60007904
10 changed files with 54 additions and 101 deletions

View file

@ -37,7 +37,6 @@ dirent/alphasort.o \
dirent/alphasort_r.o \
dirent/closedir.o \
dirent/dclearerr.o \
dirent/dcloseall.o \
dirent/deof.o \
dirent/derror.o \
dirent/dirfd.o \
@ -129,6 +128,7 @@ stdio/ftello.o \
stdio/ftello_unlocked.o \
stdio/ftrylockfile.o \
stdio/funlockfile.o \
stdio/funregister.o \
stdio/fwritable.o \
stdio/fwritable_unlocked.o \
stdio/fwrite.o \
@ -412,7 +412,6 @@ signal/signal.o \
signal/sigpending.o \
signal/sigprocmask.o \
signal/sigsuspend.o \
stdio/fcloseall.o \
stdio/fdio_install_fd.o \
stdio/fdio_install_path.o \
stdio/fdio.o \

View file

@ -23,17 +23,14 @@
*******************************************************************************/
#include <dirent.h>
#include <DIR.h>
#include <pthread.h>
extern "C" pthread_mutex_t __dirname_lock;
extern "C" void dregister(DIR* dir)
{
pthread_mutex_lock(&__dirname_lock);
pthread_mutex_lock(&__first_dir_lock);
dir->flags |= _DIR_REGISTERED;
if ( (dir->next = __firstdir) )
if ( (dir->next = __first_dir) )
dir->next->prev = dir;
__firstdir = dir;
pthread_mutex_unlock(&__dirname_lock);
__first_dir = dir;
pthread_mutex_unlock(&__first_dir_lock);
}

View file

@ -23,22 +23,19 @@
*******************************************************************************/
#include <dirent.h>
#include <DIR.h>
#include <pthread.h>
extern "C" { pthread_mutex_t __dirname_lock = PTHREAD_MUTEX_INITIALIZER; }
extern "C" void dunregister(DIR* dir)
{
if ( !(dir->flags & _DIR_REGISTERED) )
return;
pthread_mutex_lock(&__dirname_lock);
pthread_mutex_lock(&__first_dir_lock);
if ( !dir->prev )
__firstdir = dir->next;
__first_dir = dir->next;
if ( dir->prev )
dir->prev->next = dir->next;
if ( dir->next )
dir->next->prev = dir->prev;
dir->flags &= ~_DIR_REGISTERED;
pthread_mutex_unlock(&__dirname_lock);
pthread_mutex_unlock(&__first_dir_lock);
}

View file

@ -29,6 +29,8 @@
#include <sys/__/types.h>
#include <pthread.h>
__BEGIN_DECLS
#ifndef __size_t_defined
@ -64,6 +66,11 @@ struct DIR
int flags;
};
#if defined(__is_sortix_libc)
extern DIR* __first_dir;
extern __pthread_mutex_t __first_dir_lock;
#endif
__END_DECLS
#endif

View file

@ -31,6 +31,10 @@
#include <sortix/__/dirent.h>
#if defined(__is_sortix_libc)
#include <DIR.h>
#endif
__BEGIN_DECLS
#ifndef __dev_t_defined
@ -111,16 +115,11 @@ int versionsort_r(const struct dirent**, const struct dirent**, void*);
void dregister(DIR* dir);
void dunregister(DIR* dir);
DIR* dnewdir(void);
int dcloseall(void);
void dclearerr(DIR* dir);
int derror(DIR* dir);
int deof(DIR* dif);
#endif
#if defined(__is_sortix_libc)
extern DIR* __firstdir;
#endif
__END_DECLS
#endif

View file

@ -247,7 +247,6 @@ int vdprintf(int fildes, const char* __restrict format, __gnuc_va_list ap)
int asprintf(char** __restrict, const char* __restrict, ...)
__attribute__((__format__ (printf, 2, 3)));
void clearerr_unlocked(FILE* stream);
int fcloseall(void);
int feof_unlocked(FILE* stream);
int ferror_unlocked(FILE* stream);
int fflush_unlocked(FILE* stream);

View file

@ -1,35 +0,0 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013.
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/>.
stdio/fcloseall.cpp
Closes and flushes all open registered files.
*******************************************************************************/
#include <stdio.h>
extern "C" int fcloseall(void)
{
int result = 0;
// We do not lock __first_file_lock here because this function is called on
// process termination and only one thread can call exit(3).
while ( __first_file )
result |= fclose(__first_file);
return result ? EOF : 0;
}

View file

@ -1,6 +1,6 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013.
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013, 2014.
This file is part of the Sortix C Library.
@ -18,44 +18,19 @@
along with the Sortix C Library. If not, see <http://www.gnu.org/licenses/>.
stdio/fregister.cpp
Registers a FILE in the global list of open FILES, which allows the standard
library to close and flush all open files upon program exit.
Registers a FILE in the global list of open FILEs.
*******************************************************************************/
#include <pthread.h>
#include <stdio.h>
extern "C"
{
FILE* __first_file = NULL;
pthread_mutex_t __first_file_lock = PTHREAD_MUTEX_INITIALIZER;
}
extern "C" void fregister(FILE* fp)
{
pthread_mutex_lock(&__first_file_lock);
fp->flags |= _FILE_REGISTERED;
if ( __first_file )
{
fp->next = __first_file;
if ( (fp->next = __first_file) )
__first_file->prev = fp;
}
__first_file = fp;
pthread_mutex_unlock(&__first_file_lock);
}
extern "C" void funregister(FILE* fp)
{
if ( !(fp->flags & _FILE_REGISTERED) )
return;
pthread_mutex_lock(&__first_file_lock);
if ( !fp->prev )
__first_file = fp->next;
if ( fp->prev )
fp->prev->next = fp->next;
if ( fp->next )
fp->next->prev = fp->prev;
fp->flags &= ~_FILE_REGISTERED;
pthread_mutex_unlock(&__first_file_lock);
}

View file

@ -1,6 +1,6 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2014.
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013, 2014.
This file is part of the Sortix C Library.
@ -17,23 +17,25 @@
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.
stdio/funregister.cpp
Unregisters a FILE in the global list of open FILEs.
*******************************************************************************/
#include <dirent.h>
#include <DIR.h>
#include <pthread.h>
#include <stdio.h>
extern "C" { DIR* __firstdir = NULL; }
extern "C" int dcloseall(void)
extern "C" void funregister(FILE* fp)
{
int result = 0;
// We do not lock __firstdir_lock here because this function is called on
// process termination and only one thread can call exit(3).
while ( __firstdir )
result |= closedir(__firstdir);
return result ? EOF : 0;
if ( !(fp->flags & _FILE_REGISTERED) )
return;
pthread_mutex_lock(&__first_file_lock);
if ( !fp->prev )
__first_file = fp->next;
if ( fp->prev )
fp->prev->next = fp->next;
if ( fp->next )
fp->next->prev = fp->prev;
fp->flags &= ~_FILE_REGISTERED;
pthread_mutex_unlock(&__first_file_lock);
}

View file

@ -1,6 +1,6 @@
/*******************************************************************************
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012.
Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2014.
This file is part of the Sortix C Library.
@ -23,6 +23,8 @@
*******************************************************************************/
#include <dirent.h>
#include <DIR.h>
#include <FILE.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
@ -33,6 +35,11 @@ extern "C" { struct exit_handler* __exit_handler_stack = NULL; }
static pthread_mutex_t exit_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
static bool currently_exiting = false;
extern "C" { DIR* __first_dir = NULL; }
extern "C" { pthread_mutex_t __first_dir_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; }
extern "C" { FILE* __first_file = NULL; }
extern "C" { pthread_mutex_t __first_file_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; }
extern "C" void exit(int status)
{
// It's undefined behavior to call this function more than once: If more
@ -51,7 +58,13 @@ extern "C" void exit(int status)
__exit_handler_stack = __exit_handler_stack->next;
}
dcloseall();
fcloseall();
pthread_mutex_lock(&__first_dir_lock);
pthread_mutex_lock(&__first_file_lock);
while ( __first_dir )
closedir(__first_dir);
while ( __first_file )
fclose(__first_file);
_Exit(status);
}