libiberty.h (fopen_unlocked, [...]): Provide prototypes for new functions.

include:
	* libiberty.h (fopen_unlocked, fdopen_unlocked, freopen_unlocked):
	Provide prototypes for new functions.

libiberty:
	* Makefile.in (CFILES): Add fopen_unlocked.c.
	(REQUIRED_OFILES): Add ./fopen_unlocked.o.
	Regenerate dependencies.

	* configure.ac: Check for stdio_ext.h and __fsetlocking.

	* fopen_unlocked.c: New file.

	* functions.texi, configure, config.in: Regenerate.

From-SVN: r97977
This commit is contained in:
Kaveh R. Ghazi 2005-04-11 17:49:47 +00:00 committed by Kaveh Ghazi
parent f5f7d171c3
commit 78a7dc9032
9 changed files with 172 additions and 7 deletions

View File

@ -1,3 +1,8 @@
2005-04-11 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* libiberty.h (fopen_unlocked, fdopen_unlocked, freopen_unlocked):
Provide prototypes for new functions.
2005-03-29 Ian Lance Taylor <ian@airs.com> 2005-03-29 Ian Lance Taylor <ian@airs.com>
* libiberty.h: Fix indentation. * libiberty.h: Fix indentation.

View File

@ -48,6 +48,14 @@ extern "C" {
#include <stdio.h> #include <stdio.h>
/* Open and return a FILE pointer. If the OS supports it, ensure that
the stream is setup to avoid any multi-threaded locking. Otherwise
return the FILE pointer unchanged. */
extern FILE *fopen_unlocked (const char *path, const char *mode);
extern FILE *fdopen_unlocked (int fildes, const char *mode);
extern FILE *freopen_unlocked (const char *path, const char *mode, FILE *stream);
/* Build an argument vector from a string. Allocates memory using /* Build an argument vector from a string. Allocates memory using
malloc. Use freeargv to free the vector. */ malloc. Use freeargv to free the vector. */

View File

@ -1,3 +1,15 @@
2005-04-11 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* Makefile.in (CFILES): Add fopen_unlocked.c.
(REQUIRED_OFILES): Add ./fopen_unlocked.o.
Regenerate dependencies.
* configure.ac: Check for stdio_ext.h and __fsetlocking.
* fopen_unlocked.c: New file.
* functions.texi, configure, config.in: Regenerate.
2005-04-04 Ian Lance Taylor <ian@airs.com> 2005-04-04 Ian Lance Taylor <ian@airs.com>
* testsuite/test-pexecute.c (TEST_PEX_RUN): Move variable * testsuite/test-pexecute.c (TEST_PEX_RUN): Move variable

View File

@ -132,6 +132,7 @@ CFILES = alloca.c argv.c asprintf.c atexit.c \
cp-demint.c cplus-dem.c \ cp-demint.c cplus-dem.c \
dyn-string.c \ dyn-string.c \
fdmatch.c ffs.c fibheap.c floatformat.c fnmatch.c \ fdmatch.c ffs.c fibheap.c floatformat.c fnmatch.c \
fopen_unlocked.c \
getcwd.c getopt.c getopt1.c getpagesize.c getpwd.c getruntime.c \ getcwd.c getopt.c getopt1.c getpagesize.c getpwd.c getruntime.c \
gettimeofday.c \ gettimeofday.c \
hashtab.c hex.c \ hashtab.c hex.c \
@ -165,6 +166,7 @@ REQUIRED_OFILES = ./regex.o ./cplus-dem.o ./cp-demangle.o ./md5.o \
./choose-temp.o ./concat.o ./cp-demint.o \ ./choose-temp.o ./concat.o ./cp-demint.o \
./dyn-string.o \ ./dyn-string.o \
./fdmatch.o ./fibheap.o ./floatformat.o ./fnmatch.o \ ./fdmatch.o ./fibheap.o ./floatformat.o ./fnmatch.o \
./fopen_unlocked.o \
./getopt.o ./getopt1.o ./getpwd.o ./getruntime.o \ ./getopt.o ./getopt1.o ./getpwd.o ./getruntime.o \
./hashtab.o ./hex.o \ ./hashtab.o ./hex.o \
./lbasename.o ./lrealpath.o \ ./lbasename.o ./lrealpath.o \
@ -584,6 +586,13 @@ $(CONFIGURED_OFILES): stamp-picdir
else true; fi else true; fi
$(COMPILE.c) $(srcdir)/fnmatch.c $(OUTPUT_OPTION) $(COMPILE.c) $(srcdir)/fnmatch.c $(OUTPUT_OPTION)
./fopen_unlocked.o: $(srcdir)/fopen_unlocked.c config.h $(INCDIR)/ansidecl.h \
$(INCDIR)/libiberty.h
if [ x"$(PICFLAG)" != x ]; then \
$(COMPILE.c) $(PICFLAG) $(srcdir)/fopen_unlocked.c -o pic/$@; \
else true; fi
$(COMPILE.c) $(srcdir)/fopen_unlocked.c $(OUTPUT_OPTION)
./getcwd.o: $(srcdir)/getcwd.c config.h ./getcwd.o: $(srcdir)/getcwd.c config.h
if [ x"$(PICFLAG)" != x ]; then \ if [ x"$(PICFLAG)" != x ]; then \
$(COMPILE.c) $(PICFLAG) $(srcdir)/getcwd.c -o pic/$@; \ $(COMPILE.c) $(PICFLAG) $(srcdir)/getcwd.c -o pic/$@; \
@ -1041,7 +1050,7 @@ $(CONFIGURED_OFILES): stamp-picdir
else true; fi else true; fi
$(COMPILE.c) $(srcdir)/vsprintf.c $(OUTPUT_OPTION) $(COMPILE.c) $(srcdir)/vsprintf.c $(OUTPUT_OPTION)
./waitpid.o: $(srcdir)/waitpid.c config.h ./waitpid.o: $(srcdir)/waitpid.c config.h $(INCDIR)/ansidecl.h
if [ x"$(PICFLAG)" != x ]; then \ if [ x"$(PICFLAG)" != x ]; then \
$(COMPILE.c) $(PICFLAG) $(srcdir)/waitpid.c -o pic/$@; \ $(COMPILE.c) $(PICFLAG) $(srcdir)/waitpid.c -o pic/$@; \
else true; fi else true; fi

View File

@ -151,6 +151,9 @@
/* Define to 1 if you have the <stdint.h> header file. */ /* Define to 1 if you have the <stdint.h> header file. */
#undef HAVE_STDINT_H #undef HAVE_STDINT_H
/* Define to 1 if you have the <stdio_ext.h> header file. */
#undef HAVE_STDIO_EXT_H
/* Define to 1 if you have the <stdlib.h> header file. */ /* Define to 1 if you have the <stdlib.h> header file. */
#undef HAVE_STDLIB_H #undef HAVE_STDLIB_H
@ -322,6 +325,9 @@
/* Define if you have the _system_configuration variable. */ /* Define if you have the _system_configuration variable. */
#undef HAVE__SYSTEM_CONFIGURATION #undef HAVE__SYSTEM_CONFIGURATION
/* Define to 1 if you have the `__fsetlocking' function. */
#undef HAVE___FSETLOCKING
/* Define if the host machine stores words of multi-word integers in /* Define if the host machine stores words of multi-word integers in
big-endian order. */ big-endian order. */
#undef HOST_WORDS_BIG_ENDIAN #undef HOST_WORDS_BIG_ENDIAN

8
libiberty/configure vendored
View File

@ -3540,7 +3540,8 @@ host_makefile_frag=${frag}
for ac_header in sys/file.h sys/param.h limits.h stdlib.h malloc.h string.h unistd.h strings.h sys/time.h time.h sys/resource.h sys/stat.h sys/mman.h fcntl.h alloca.h sys/pstat.h sys/sysmp.h sys/sysinfo.h machine/hal_sysinfo.h sys/table.h sys/sysctl.h sys/systemcfg.h stdint.h
for ac_header in sys/file.h sys/param.h limits.h stdlib.h malloc.h string.h unistd.h strings.h sys/time.h time.h sys/resource.h sys/stat.h sys/mman.h fcntl.h alloca.h sys/pstat.h sys/sysmp.h sys/sysinfo.h machine/hal_sysinfo.h sys/table.h sys/sysctl.h sys/systemcfg.h stdint.h stdio_ext.h
do do
as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh` as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
echo "$as_me:$LINENO: checking for $ac_header" >&5 echo "$as_me:$LINENO: checking for $ac_header" >&5
@ -4818,7 +4819,7 @@ vars="sys_errlist sys_nerr sys_siglist"
checkfuncs="getrusage on_exit psignal strerror strsignal sysconf times sbrk gettimeofday" checkfuncs="getrusage on_exit psignal strerror strsignal sysconf times sbrk gettimeofday"
checkfuncs="$checkfuncs realpath canonicalize_file_name pstat_getstatic pstat_getdynamic sysmp" checkfuncs="$checkfuncs realpath canonicalize_file_name pstat_getstatic pstat_getdynamic sysmp"
checkfuncs="$checkfuncs getsysinfo table sysctl wait3 wait4" checkfuncs="$checkfuncs getsysinfo table sysctl wait3 wait4 __fsetlocking"
# These are neither executed nor required, but they help keep # These are neither executed nor required, but they help keep
# autoheader happy without adding a bunch of text to acconfig.h. # autoheader happy without adding a bunch of text to acconfig.h.
@ -4888,6 +4889,7 @@ if test "x" = "y"; then
for ac_func in asprintf atexit basename bcmp bcopy bsearch bzero calloc clock \ for ac_func in asprintf atexit basename bcmp bcopy bsearch bzero calloc clock \
@ -4898,7 +4900,7 @@ for ac_func in asprintf atexit basename bcmp bcopy bsearch bzero calloc clock \
vsprintf waitpid getrusage on_exit psignal strerror strsignal \ vsprintf waitpid getrusage on_exit psignal strerror strsignal \
sysconf times sbrk gettimeofday ffs snprintf vsnprintf \ sysconf times sbrk gettimeofday ffs snprintf vsnprintf \
pstat_getstatic pstat_getdynamic sysmp getsysinfo table sysctl wait3 wait4 \ pstat_getstatic pstat_getdynamic sysmp getsysinfo table sysctl wait3 wait4 \
realpath canonicalize_file_name realpath canonicalize_file_name __fsetlocking
do do
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
echo "$as_me:$LINENO: checking for $ac_func" >&5 echo "$as_me:$LINENO: checking for $ac_func" >&5

View File

@ -159,7 +159,7 @@ AC_SUBST_FILE(host_makefile_frag)
# It's OK to check for header files. Although the compiler may not be # It's OK to check for header files. Although the compiler may not be
# able to link anything, it had better be able to at least compile # able to link anything, it had better be able to at least compile
# something. # something.
AC_CHECK_HEADERS(sys/file.h sys/param.h limits.h stdlib.h malloc.h string.h unistd.h strings.h sys/time.h time.h sys/resource.h sys/stat.h sys/mman.h fcntl.h alloca.h sys/pstat.h sys/sysmp.h sys/sysinfo.h machine/hal_sysinfo.h sys/table.h sys/sysctl.h sys/systemcfg.h stdint.h) AC_CHECK_HEADERS(sys/file.h sys/param.h limits.h stdlib.h malloc.h string.h unistd.h strings.h sys/time.h time.h sys/resource.h sys/stat.h sys/mman.h fcntl.h alloca.h sys/pstat.h sys/sysmp.h sys/sysinfo.h machine/hal_sysinfo.h sys/table.h sys/sysctl.h sys/systemcfg.h stdint.h stdio_ext.h)
AC_HEADER_SYS_WAIT AC_HEADER_SYS_WAIT
AC_HEADER_TIME AC_HEADER_TIME
@ -268,7 +268,7 @@ vars="sys_errlist sys_nerr sys_siglist"
checkfuncs="getrusage on_exit psignal strerror strsignal sysconf times sbrk gettimeofday" checkfuncs="getrusage on_exit psignal strerror strsignal sysconf times sbrk gettimeofday"
checkfuncs="$checkfuncs realpath canonicalize_file_name pstat_getstatic pstat_getdynamic sysmp" checkfuncs="$checkfuncs realpath canonicalize_file_name pstat_getstatic pstat_getdynamic sysmp"
checkfuncs="$checkfuncs getsysinfo table sysctl wait3 wait4" checkfuncs="$checkfuncs getsysinfo table sysctl wait3 wait4 __fsetlocking"
# These are neither executed nor required, but they help keep # These are neither executed nor required, but they help keep
# autoheader happy without adding a bunch of text to acconfig.h. # autoheader happy without adding a bunch of text to acconfig.h.
@ -281,7 +281,7 @@ if test "x" = "y"; then
vsprintf waitpid getrusage on_exit psignal strerror strsignal \ vsprintf waitpid getrusage on_exit psignal strerror strsignal \
sysconf times sbrk gettimeofday ffs snprintf vsnprintf \ sysconf times sbrk gettimeofday ffs snprintf vsnprintf \
pstat_getstatic pstat_getdynamic sysmp getsysinfo table sysctl wait3 wait4 \ pstat_getstatic pstat_getdynamic sysmp getsysinfo table sysctl wait3 wait4 \
realpath canonicalize_file_name) realpath canonicalize_file_name __fsetlocking)
AC_DEFINE(HAVE_SYS_ERRLIST, 1, [Define if you have the sys_errlist variable.]) AC_DEFINE(HAVE_SYS_ERRLIST, 1, [Define if you have the sys_errlist variable.])
AC_DEFINE(HAVE_SYS_NERR, 1, [Define if you have the sys_nerr variable.]) AC_DEFINE(HAVE_SYS_NERR, 1, [Define if you have the sys_nerr variable.])
AC_DEFINE(HAVE_SYS_SIGLIST, 1, [Define if you have the sys_siglist variable.]) AC_DEFINE(HAVE_SYS_SIGLIST, 1, [Define if you have the sys_siglist variable.])

View File

@ -0,0 +1,93 @@
/* Implement fopen_unlocked and related functions.
Copyright (C) 2005 Free Software Foundation, Inc.
Written by Kaveh R. Ghazi <ghazi@caip.rutgers.edu>.
This file is part of the libiberty library.
Libiberty is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
Libiberty 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with libiberty; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/*
@deftypefn Extension FILE * fopen_unlocked (const char *@var{path}, const char * @var{mode})
Opens and returns a @code{FILE} pointer via @code{fopen}. If the
operating system supports it, ensure that the stream is setup to avoid
any multi-threaded locking. Otherwise return the @code{FILE} pointer
unchanged.
@end deftypefn
@deftypefn Extension FILE * fdopen_unlocked (int @var{fildes}, const char * @var{mode})
Opens and returns a @code{FILE} pointer via @code{fdopen}. If the
operating system supports it, ensure that the stream is setup to avoid
any multi-threaded locking. Otherwise return the @code{FILE} pointer
unchanged.
@end deftypefn
@deftypefn Extension FILE * freopen_unlocked (const char * @var{path}, const char * @var{mode}, FILE * @var{stream})
Opens and returns a @code{FILE} pointer via @code{freopen}. If the
operating system supports it, ensure that the stream is setup to avoid
any multi-threaded locking. Otherwise return the @code{FILE} pointer
unchanged.
@end deftypefn
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#ifdef HAVE_STDIO_EXT_H
#include <stdio_ext.h>
#endif
#include "libiberty.h"
FILE *
fopen_unlocked (const char *path, const char *mode)
{
FILE *const fp = fopen (path, mode);
#if defined(HAVE___FSETLOCKING) && defined(FSETLOCKING_BYCALLER)
if (fp)
__fsetlocking (fp, FSETLOCKING_BYCALLER);
#endif
return fp;
}
FILE *
fdopen_unlocked (int fildes, const char *mode)
{
FILE *const fp = fdopen (fildes, mode);
#if defined(HAVE___FSETLOCKING) && defined(FSETLOCKING_BYCALLER)
if (fp)
__fsetlocking (fp, FSETLOCKING_BYCALLER);
#endif
return fp;
}
FILE *
freopen_unlocked (const char *path, const char *mode, FILE *stream)
{
FILE *const fp = freopen (path, mode, stream);
#if defined(HAVE___FSETLOCKING) && defined(FSETLOCKING_BYCALLER)
if (fp)
__fsetlocking (fp, FSETLOCKING_BYCALLER);
#endif
return fp;
}

View File

@ -362,6 +362,16 @@ and inode numbers.
@end deftypefn @end deftypefn
@c fopen_unlocked.c:32
@deftypefn Extension FILE * fdopen_unlocked (int @var{fildes}, const char * @var{mode})
Opens and returns a @code{FILE} pointer via @code{fdopen}. If the
operating system supports it, ensure that the stream is setup to avoid
any multi-threaded locking. Otherwise return the @code{FILE} pointer
unchanged.
@end deftypefn
@c ffs.c:3 @c ffs.c:3
@deftypefn Supplemental int ffs (int @var{valu}) @deftypefn Supplemental int ffs (int @var{valu})
@ -421,6 +431,16 @@ Ignores case when performing the comparison.
@end deftypefn @end deftypefn
@c fopen_unlocked.c:23
@deftypefn Extension FILE * fopen_unlocked (const char *@var{path}, const char * @var{mode})
Opens and returns a @code{FILE} pointer via @code{fopen}. If the
operating system supports it, ensure that the stream is setup to avoid
any multi-threaded locking. Otherwise return the @code{FILE} pointer
unchanged.
@end deftypefn
@c argv.c:94 @c argv.c:94
@deftypefn Extension void freeargv (char **@var{vector}) @deftypefn Extension void freeargv (char **@var{vector})
@ -431,6 +451,16 @@ itself.
@end deftypefn @end deftypefn
@c fopen_unlocked.c:41
@deftypefn Extension FILE * freopen_unlocked (const char * @var{path}, const char * @var{mode}, FILE * @var{stream})
Opens and returns a @code{FILE} pointer via @code{freopen}. If the
operating system supports it, ensure that the stream is setup to avoid
any multi-threaded locking. Otherwise return the @code{FILE} pointer
unchanged.
@end deftypefn
@c getruntime.c:82 @c getruntime.c:82
@deftypefn Replacement long get_run_time (void) @deftypefn Replacement long get_run_time (void)