edf5b2d716
Sat Sep 7 05:15:45 1996 Ulrich Drepper <drepper@cygnus.com> * libio/iofdopen: Initialize _lock field only if _IO_MTSAFE_IO. * libio/iofopen: Likewise. * libio/iofopncook.c: Likewise. * libio/iopopen.c: Likewise. * libio/iovsprintf.c: Likewise. * libio/iovsscanf.c: Likewise. * libio/memstream.c: Likewise. * libio/vasprintf.c: Likewise. * libio/vdprintf.c: Likewise. * libio/vsnprintf.c: Likewise. Sat Sep 7 03:55:47 1996 Ulrich Drepper <drepper@cygnus.com> * Makeconfig (soversions.mk): Also use shlib-versions files in add-on directories. * config.make.in (config-defines): Remove. Not used anymore. (defines): New variable. Initiliazed by @DEFINES@. * configure.in: Add AC_SUBST(DEFINES). * libio/Makefile (routines): When compiling reentrant libc add clearerr_u, feof_u, ferror_u, fputc_u, getc_u, getchar_u, iofflush_u, putc_u, putchar_u, ioflockfile. (CPPFLAGS): Add -D_IO_MTSAFE_IO for reentrant libc. * sysdeps/stub/libc-lock.h: Add stubs for __libc_cleanup_region_start and __libc_cleanup_region_end. * sysdeps/unix/i386/sysdep.S [_LIBC_REENTRANT]: Set errno using __errno_location function. * sysdeps/unix/sysv/linux/i386/sysdep.S [_LIBC_REENTRANT]: Set errno using __errno_location function. (__errno_location): New function. * sysdeps/unix/sysv/linux/i386/sysdep.h [PIC]: Add second syscall_error handler for reentrant libc. * sysdeps/unix/opendir.c: Remove unneeded `;'. * libio.h [_IO_MTSAFE_IO]: Include <pthread.h>. [!_IO_MTSAFE_IO]: Define _IO_flockfile and _IO_funlockfile as empty macros. * libioP.h: Include <libc-lock.h>. * libio/stdio.h: Add prototypes for *_locked and *_unlocked functions. * libio/clearerr.c: Use _IO_ protected versions of flockfile and funlockfile to be namespace clean. * libio/genops.c: Use __libc_lock_* macros for handling lock. * libio/iofdopen: Add initialization of _lock in _IO_FILE. * libio/iofopen: Likewise. * libio/iofopncook.c: Likewise. * libio/iopopen.c: Likewise. * libio/iovsprintf.c: Likewise. * libio/iovsscanf.c: Likewise. * libio/memstream.c: Likewise. * libio/vasprintf.c: Likewise. * libio/vdprintf.c: Likewise. * libio/vsnprintf.c: Likewise. * libio/fgetc.c: Use __libc_cleanup_region_* macros instead of flockfile etc. * libio/fputc.c: Likewise. * libio/freopen.c: Likewise. * libio/fseek.c: Likewise. * libio/getc.c: Likewise. * libio/getchar.c: Likewise. * libio/iofclose.c: Likewise. * libio/iofflush.c: Likewise. * libio/iofgetpos.c: Likewise. * libio/iofgets.c: Likewise. * libio/iofputs.c: Likewise. * libio/iofread.c: Likewise. * libio/iofsetpos.c: Likewise. * libio/ioftell.c: Likewise. * libio/iofwrite.c: Likewise. * libio/iogetdelim.c: Likewise. * libio/iogets.c: Likewise. * libio/ioputs.c: Likewise. * libio/iosetbuffer.c: Likewise. * libio/iosetvbuf.c: Likewise. * libio/ioungetc.c: Likewise. * libio/putc.c: Likewise. * libio/putchar.c: Likewise. * libio/rewind.c: Likewise. * stdio-common/vfprintf.c: Likewise. * stdio-common/vfscanf.c: Likewise. * libio/clearerr_u.c: Correct alias name. * libio/ferror_u.c: Likewise. * libio/fileno.c: Likewise. * libio/fputc_u.c: Likewise. * libio/getc.c: Likewise. * libio/getc_u.c: Likewise. * libio/getchar.c: Likewise. * libio/getchar_u.c: Likewise. * libio/putc.c: Likewise. * libio/putchar.c: Likewise. * libio/feof_u.c: Undefine macro with name of function before definition of function itself. * libio/ioflockfile.c: New file. Implementation of flockfile and funlockfile. * libio/putchar_u.c: Fix typo. Use stdout instead of fp. * malloc/malloc.h: Don't include <libc-lock.h> and don't declare _malloc_loc. * malloc/free.c: Include <libc-lock.h>. * malloc/realloc.c: Likewise. * malloc/malloc-find.c: Likewise. * malloc/malloc-size.c: Likewise. * malloc/malloc-walk.c: Likewise. * malloc/memalign.c: Likewise. * malloc/malloc.c: Likewise. * sysdeps/i386/dl-machine.h: Correct clearing of _dl_starting_up. Fri Sep 6 19:38:49 1996 Ulrich Drepper <drepper@cygnus.com> * sysdeps/stub/libc-lock.h: Define __libc_lock_critical_start and __libc_lock_critical_end as empty macros. * malloc/malloc.h: Don't include <libc-lock.h> and don't declare __libc_malloc_lock. * malloc/free.c: Include <libc-lock.h>. * malloc/malloc-find.c: Likewise. * malloc/malloc-size.c: Likewise. * malloc/malloc-walk.c: Likewise. * malloc/malloc.c: Likewise. * malloc/memalign.c: Likewise. * malloc/realloc.c: Likewise. * Makefile: Undo change from Mon Sep 2 22:15:14 1996. No more extra_solibs pass. * Rules: Likewise. * extra-lib.mk: Likewise. * manual/Makefile: Likewise. * db/Makefile (makedb): Choose dependecies based on build-shared. Patch by Andres Schwab. * sysdeps/posix/sysconf.c: Don't use PTHREAD_DESTRUCTOR_ITERATIONS but _POSIX_THREAD_DESTRUCTOR_ITERATIONS. * sysdeps/unix/sysv/linux/errnos.h: New file. * sysdeps/unix/sysv/linux/schedbits.h: New file. * sysdeps/unix/sysv/linux/waitflags.h: New file. * sysdeps/unix/sysv/linux/gnu/types.h: Add definition of `key_t'. Fri Sep 6 08:26:31 1996 Andreas Schwab <schwab@issan.informatik.uni-dortmund.de> * rpm/template: Fix typo in %build section. Fri Sep 6 03:31:07 1996 Ulrich Drepper <drepper@cygnus.com> * sysdeps/unix/sysv/linux/errnos.h: Don't define errno macro when building libc without thread support. * resolv/netdb.h: Likewise for h_errno macro. Thu Sep 5 23:01:48 1996 Ulrich Drepper <drepper@cygnus.com> * libc-symbols.h: Add new macro weak_const_function. It's like weak_function, but the function is additionally marked as const. * features.h: Only include <sys/cdefs.h> if !__ASSEMBLER__. Thu Sep 5 22:55:49 1996 Richard Henderson <rth@tamu.edu> * inet/herrno.c (__h_errno_location): New function. (h_errno): Make strong_alias __h_errno so that we can access the variable even if `h_errno' is a macro. * resolv/netdb.h: Define macro h_errno to access thread specific version of h_errno variable. Declare alias __h_errno for h_errno. * resolv/res_query (h_errno): Remove definition. * sysdeps/unix/sysv/linux/errnos.h [!__ASSEMBLER__ && __USE_REENTRANT]: Add macro `errno' to get thread specific variable. * sysdeps/unix/alpha/sysdep.S [_LIBC_REENTRANT]: Set errno using __errno_location function. (__errno_location): New function. Thu Sep 5 21:08:44 1996 Ulrich Drepper <drepper@cygnus.com> * posix/gnu/types.h: Remove definition of key_t. * sysdeps/generic/gnu/types.h: Move it to here. * sysdeps/unix/sysv/linux/gnu/types.h: Add Linux specific definition of key_t. * sysdeps/unix/sysv/linux/waitflags.h: New file. Linux specific definitions. * sysdeps/unix/sysv/linux/schedbits.h: New file. Include clone prototypes and associated flags. Thu Sep 5 08:58:47 1996 Richard Henderson <rth@tamu.edu> * sysdeps/alpha/elf/start.S: Make _start global again. hertz. here. Wed Sep 4 16:16:13 1996 Ulrich Drepper <drepper@cygnus.com> * sysdeps/mach/hurd/send.c (__send): De-ANSI-fy. * sysdeps/mach/hurd/sendto.c (sendto): Likewise.
130 lines
3.7 KiB
C
130 lines
3.7 KiB
C
/*
|
|
Copyright (C) 1993, 1994 Free Software Foundation
|
|
|
|
This file is part of the GNU IO Library. This library is free
|
|
software; you can redistribute it and/or modify it under the
|
|
terms of the GNU General Public License as published by the
|
|
Free Software Foundation; either version 2, or (at your option)
|
|
any later version.
|
|
|
|
This 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 General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this library; see the file COPYING. If not, write to the Free
|
|
Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
As a special exception, if you link this library with files
|
|
compiled with a GNU compiler to produce an executable, this does not cause
|
|
the resulting executable to be covered by the GNU General Public License.
|
|
This exception does not however invalidate any other reasons why
|
|
the executable file might be covered by the GNU General Public License. */
|
|
|
|
#ifdef __STDC__
|
|
#include <stdlib.h>
|
|
#endif
|
|
#include "libioP.h"
|
|
#include <fcntl.h>
|
|
|
|
#ifndef _IO_fcntl
|
|
#define _IO_fcntl fcntl
|
|
#endif
|
|
|
|
_IO_FILE *
|
|
_IO_fdopen (fd, mode)
|
|
int fd;
|
|
const char *mode;
|
|
{
|
|
int read_write;
|
|
int posix_mode = 0;
|
|
struct locked_FILE
|
|
{
|
|
struct _IO_FILE_plus fp;
|
|
_IO_lock_t lock;
|
|
} *new_f;
|
|
int fd_flags;
|
|
|
|
switch (*mode++)
|
|
{
|
|
case 'r':
|
|
read_write = _IO_NO_WRITES;
|
|
break;
|
|
case 'w':
|
|
read_write = _IO_NO_READS;
|
|
break;
|
|
case 'a':
|
|
posix_mode = O_APPEND;
|
|
read_write = _IO_NO_READS|_IO_IS_APPENDING;
|
|
break;
|
|
default:
|
|
#ifdef EINVAL
|
|
errno = EINVAL;
|
|
#endif
|
|
return NULL;
|
|
}
|
|
if (mode[0] == '+' || (mode[0] == 'b' && mode[1] == '+'))
|
|
read_write &= _IO_IS_APPENDING;
|
|
#ifdef F_GETFL
|
|
fd_flags = _IO_fcntl (fd, F_GETFL);
|
|
#ifndef O_ACCMODE
|
|
#define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR)
|
|
#endif
|
|
if (fd_flags == -1
|
|
|| ((fd_flags & O_ACCMODE) == O_RDONLY && !(read_write & _IO_NO_WRITES))
|
|
|| ((fd_flags & O_ACCMODE) == O_WRONLY && !(read_write & _IO_NO_READS)))
|
|
return NULL;
|
|
|
|
/* The May 93 draft of P1003.4/D14.1 (redesignated as 1003.1b)
|
|
[System Application Program Interface (API) Amendment 1:
|
|
Realtime Extensions], Rationale B.8.3.3
|
|
Open a Stream on a File Descriptor says:
|
|
|
|
Although not explicitly required by POSIX.1, a good
|
|
implementation of append ("a") mode would cause the
|
|
O_APPEND flag to be set.
|
|
|
|
(Historical implementations [such as Solaris2] do a one-time
|
|
seek in fdopen.)
|
|
|
|
However, we do not turn O_APPEND off if the mode is "w" (even
|
|
though that would seem consistent) because that would be more
|
|
likely to break historical programs.
|
|
*/
|
|
if ((posix_mode & O_APPEND) && !(fd_flags & O_APPEND))
|
|
{
|
|
#ifdef F_SETFL
|
|
if (_IO_fcntl (fd, F_SETFL, fd_flags | O_APPEND) == -1)
|
|
#endif
|
|
return NULL;
|
|
}
|
|
#endif
|
|
|
|
new_f = (struct locked_FILE *) malloc (sizeof (struct locked_FILE));
|
|
if (new_f == NULL)
|
|
return NULL;
|
|
new_f->fp.file._lock = &new_f->lock;
|
|
_IO_init (&new_f->fp.file, 0);
|
|
_IO_JUMPS (&new_f->fp.file) = &_IO_file_jumps;
|
|
_IO_file_init (&new_f->fp.file);
|
|
#if !_IO_UNIFIED_JUMPTABLES
|
|
new_f->fp.vtable = NULL;
|
|
#endif
|
|
if (_IO_file_attach (&new_f->fp.file, fd) == NULL)
|
|
{
|
|
_IO_un_link (&new_f->fp.file);
|
|
free (new_f);
|
|
return NULL;
|
|
}
|
|
new_f->fp.file._flags &= ~_IO_DELETE_DONT_CLOSE;
|
|
|
|
new_f->fp.file._IO_file_flags =
|
|
_IO_mask_flags (&new_f->fp.file, read_write,
|
|
_IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING);
|
|
|
|
return (_IO_FILE *) &new_f->fp;
|
|
}
|
|
|
|
weak_alias (_IO_fdopen, fdopen)
|