diff options
Diffstat (limited to 'libio/iofdopen.c')
-rw-r--r-- | libio/iofdopen.c | 99 |
1 files changed, 56 insertions, 43 deletions
diff --git a/libio/iofdopen.c b/libio/iofdopen.c index f8bc76869ad..841e7032b80 100644 --- a/libio/iofdopen.c +++ b/libio/iofdopen.c @@ -1,26 +1,27 @@ -/* -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. */ +/* Copyright (C) 1993, 1994, 1997 Free Software Foundation, Inc. + 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> @@ -33,12 +34,19 @@ the executable file might be covered by the GNU General Public License. */ #endif _IO_FILE * -DEFUN(_IO_fdopen, (fd, mode), - int fd AND const char *mode) +_IO_fdopen (fd, mode) + int fd; + const char *mode; { int read_write; int posix_mode = 0; - struct _IO_FILE_plus *fp; + struct locked_FILE + { + struct _IO_FILE_plus fp; +#ifdef _IO_MTSAFE_IO + _IO_lock_t lock; +#endif + } *new_f; int fd_flags; switch (*mode++) @@ -54,9 +62,7 @@ DEFUN(_IO_fdopen, (fd, mode), read_write = _IO_NO_READS|_IO_IS_APPENDING; break; default: -#ifdef EINVAL - errno = EINVAL; -#endif + MAYBE_SET_EINVAL; return NULL; } if (mode[0] == '+' || (mode[0] == 'b' && mode[1] == '+')) @@ -96,26 +102,33 @@ DEFUN(_IO_fdopen, (fd, mode), } #endif - fp = (struct _IO_FILE_plus*)malloc(sizeof(struct _IO_FILE_plus)); - if (fp == NULL) + new_f = (struct locked_FILE *) malloc (sizeof (struct locked_FILE)); + if (new_f == NULL) return NULL; - _IO_init(&fp->file, 0); - _IO_JUMPS(&fp->file) = &_IO_file_jumps; - _IO_file_init(&fp->file); +#ifdef _IO_MTSAFE_IO + new_f->fp.file._lock = &new_f->lock; +#endif + _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 - fp->vtable = NULL; + new_f->fp.vtable = NULL; #endif - if (_IO_file_attach(&fp->file, fd) == NULL) + if (_IO_file_attach (&new_f->fp.file, fd) == NULL) { - _IO_un_link(&fp->file); - free (fp); + _IO_un_link (&new_f->fp.file); + free (new_f); return NULL; } - fp->file._flags &= ~_IO_DELETE_DONT_CLOSE; + new_f->fp.file._flags &= ~_IO_DELETE_DONT_CLOSE; - fp->file._IO_file_flags = - _IO_mask_flags(&fp->file, read_write, - _IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING); + 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*)fp; + return (_IO_FILE *) &new_f->fp; } + +#ifdef weak_alias +weak_alias (_IO_fdopen, fdopen) +#endif |