+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>
* libiberty.h: Fix indentation.
#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
malloc. Use freeargv to free the vector. */
+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>
* testsuite/test-pexecute.c (TEST_PEX_RUN): Move variable
cp-demint.c cplus-dem.c \
dyn-string.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 \
gettimeofday.c \
hashtab.c hex.c \
./choose-temp.o ./concat.o ./cp-demint.o \
./dyn-string.o \
./fdmatch.o ./fibheap.o ./floatformat.o ./fnmatch.o \
+ ./fopen_unlocked.o \
./getopt.o ./getopt1.o ./getpwd.o ./getruntime.o \
./hashtab.o ./hex.o \
./lbasename.o ./lrealpath.o \
else true; fi
$(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
if [ x"$(PICFLAG)" != x ]; then \
$(COMPILE.c) $(PICFLAG) $(srcdir)/getcwd.c -o pic/$@; \
else true; fi
$(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 \
$(COMPILE.c) $(PICFLAG) $(srcdir)/waitpid.c -o pic/$@; \
else true; fi
/* Define to 1 if you have the <stdint.h> header file. */
#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. */
#undef HAVE_STDLIB_H
/* Define if you have the _system_configuration variable. */
#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
big-endian order. */
#undef HOST_WORDS_BIG_ENDIAN
-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
as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
echo "$as_me:$LINENO: checking for $ac_header" >&5
checkfuncs="getrusage on_exit psignal strerror strsignal sysconf times sbrk gettimeofday"
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
# autoheader happy without adding a bunch of text to acconfig.h.
+
for ac_func in asprintf atexit basename bcmp bcopy bsearch bzero calloc clock \
vsprintf waitpid getrusage on_exit psignal strerror strsignal \
sysconf times sbrk gettimeofday ffs snprintf vsnprintf \
pstat_getstatic pstat_getdynamic sysmp getsysinfo table sysctl wait3 wait4 \
- realpath canonicalize_file_name
+ realpath canonicalize_file_name __fsetlocking
do
as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
echo "$as_me:$LINENO: checking for $ac_func" >&5
# 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
# 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_TIME
checkfuncs="getrusage on_exit psignal strerror strsignal sysconf times sbrk gettimeofday"
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
# autoheader happy without adding a bunch of text to acconfig.h.
vsprintf waitpid getrusage on_exit psignal strerror strsignal \
sysconf times sbrk gettimeofday ffs snprintf vsnprintf \
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_NERR, 1, [Define if you have the sys_nerr variable.])
AC_DEFINE(HAVE_SYS_SIGLIST, 1, [Define if you have the sys_siglist variable.])
--- /dev/null
+/* 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;
+}
@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
@deftypefn Supplemental int ffs (int @var{valu})
@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
@deftypefn Extension void freeargv (char **@var{vector})
@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
@deftypefn Replacement long get_run_time (void)