diff options
author | Ulrich Drepper <drepper@redhat.com> | 1997-12-14 22:24:57 +0000 |
---|---|---|
committer | Ulrich Drepper <drepper@redhat.com> | 1997-12-14 22:24:57 +0000 |
commit | bd355af04fc1df69d4ebb6733be170b9baf0dfb5 (patch) | |
tree | 7c003a29de4031db7de6ddd8e86c43bd746891a0 /libio | |
parent | afe93c0bb33ca7f45b9b60c30067e7b84827e900 (diff) | |
download | glibc-bd355af04fc1df69d4ebb6733be170b9baf0dfb5.zip glibc-bd355af04fc1df69d4ebb6733be170b9baf0dfb5.tar.gz glibc-bd355af04fc1df69d4ebb6733be170b9baf0dfb5.tar.bz2 |
Update.cvs/libc-ud-971214
1997-12-14 21:33 Ulrich Drepper <drepper@cygnus.com>
* version.h (VERSION): Bump to 2.0.91.
* db2/makedb.c (process_input): Fix typo in message.
* sunrpc/rpcinfo.c (pmapdump): Unify messages.
* elf/dynamic-link.h: Pretty print.
* elf/rtld.c: Allow multiple preloading of a shared object.
* include/limits.h: Prevent multiple inclusion.
* malloc/Makefile (headers): Add mcheck.h.
(distribute): Remove it here.
* malloc/mcheck.h: Pretty print.
* malloc/mtrace.c (mallenv): Make `const'.
* malloc/mtrace.pl: Don't print table head for memory leaks if there
are none.
* manual/memory.texi: Update descriptor of malloc hooks.
* posix/Makefile (routines): Add waitid.
* posix/sys/types.h [__USE_SVID || __USE_POSIX]: Define id_t based
on __id_t.
* posix/sys/wait.h: Define idtype_t type.
Add prototype for waitid.
* signal/signal.h: Move definition of sigval_t to <bits/siginfo.h>.
* sysdeps/generic/waitid.c: Stub for waitid.
* sysdeps/generic/bits/siginfo.h: Define sigval_t. Arrange to work
the __need_siginfo_t defined.
* sysdeps/unix/sysv/linux/bits/siginfo: Likewise.
* sysdeps/generic/bits/types.h: Define __id_t.
Correct definition of __FDMASK.
* sysdeps/unix/sysv/linux/alpha/bits/types.h: Likewise.
* sysdeps/unix/sysv/linux/bits/types.h: Likewise.
* sysdeps/unix/sysv/linux/sparc/sparc64/bits/types.h: Likewise.
* sysdeps/posix/waitid.c: New file.
Provided by Zack Weinberg.
* rt/aio_misc.c: Rename __aio_free_req to __aio_free_request.
* sysdeps/alpha/dl-machine.h (ELF_MACHINE_RUNTIME_TRAMPOLINE):
Add missing parameters.
* sysdeps/generic/dl-sysdep.c: Don't call __libc_init_secure.
* sysdeps/generic/enbl-secure.c: Don't define __libc_uid.
* sysdeps/unix/sysv/linux/init-first.c: Define __libc_uid.
* sysdeps/unix/sysv/linux/sigqueue.c: Make sure __libc_uid is
initialized.
* sysdeps/i386/dl-machine.h: Little cleanup.
* sysdeps/i386/fpu/bits/mathinline.h: Use __signbit* inline functions.
(__finite): Mark function as const.
Add inline code for __ieee754_atan2.
* sysdeps/libm-ieee754/s_cacoshf.c: Add alternate implementation
(but don't use it now).
* sysdeps/libm-ieee754/s_catan.c: Use __ieee754_atan2 instead of
__atan.
* sysdeps/libm-ieee754/s_catanf.c: Likewise.
* sysdeps/libm-ieee754/s_catanl.c: Likewise.
* sysdeps/libm-ieee754/s_catanh.c: Likewise. Correct sign of
real part.
* sysdeps/libm-ieee754/s_catanhf.c: Likewise.
* sysdeps/libm-ieee754/s_catanhl.c: Likewise.
* sysdeps/libm-ieee754/s_clog10.c: Use factor to correct
__ieee754_atan2 to base 10.
* sysdeps/libm-ieee754/s_clog10f.c: Likewise.
* sysdeps/libm-ieee754/s_clog10l.c: Likewise.
* sysdeps/unix/sysv/linux/alpha/kernel_sigaction.h: Define as
old_kernel_sigaction.
* sysdeps/unix/sysv/linux/net/if_slip.h: Pretty print.
* wctype/Makefile (routines): Add wctype_l.
* wctype/wctype.h: Add declaration of __wctype_l.
* wctype/wctype_l.c: New file.
1997-12-10 00:38 Ulrich Drepper <drepper@cygnus.com>
* locale/C-ctype.c: Correct data for isw* functions.
* locale/programs/ld-ctype.c: Write 32bit char classes in correct
byte order.
* wctype/test_wctype.c: Add test for isw* functions.
* wctype/wctype.c: Return value with expected byte order.
* sysdeps/generic/_G_config.h: Define _G_HAVE_IO_FILE_OPEN.
* sysdeps/unix/sysv/linux/_G_config.h: Likewise.
Diffstat (limited to 'libio')
-rw-r--r-- | libio/Makefile | 5 | ||||
-rw-r--r-- | libio/fileops.c | 93 | ||||
-rw-r--r-- | libio/genops.c | 3 | ||||
-rw-r--r-- | libio/iofdopen.c | 33 | ||||
-rw-r--r-- | libio/iofgets.c | 7 | ||||
-rw-r--r-- | libio/iofopen.c | 18 | ||||
-rw-r--r-- | libio/iofopen64.c | 16 | ||||
-rw-r--r-- | libio/iogets.c | 7 | ||||
-rw-r--r-- | libio/iolibio.h | 2 | ||||
-rw-r--r-- | libio/iopopen.c | 4 | ||||
-rw-r--r-- | libio/iovdprintf.c | 24 | ||||
-rw-r--r-- | libio/libio.h | 21 | ||||
-rw-r--r-- | libio/libioP.h | 41 | ||||
-rw-r--r-- | libio/oldfileops.c | 3 | ||||
-rw-r--r-- | libio/oldiofclose.c | 1 | ||||
-rw-r--r-- | libio/oldiofdopen.c | 135 | ||||
-rw-r--r-- | libio/oldiofopen.c | 1 | ||||
-rw-r--r-- | libio/oldstdfiles.c | 29 | ||||
-rw-r--r-- | libio/stdfiles.c | 21 | ||||
-rw-r--r-- | libio/stdio.c | 6 |
20 files changed, 332 insertions, 138 deletions
diff --git a/libio/Makefile b/libio/Makefile index f3a66f3..0997b5d 100644 --- a/libio/Makefile +++ b/libio/Makefile @@ -43,7 +43,7 @@ all: # Make this the default target; it will be defined in Rules. include ../Makeconfig ifeq ($(versioning),yes) -routines += oldiofopen oldiofclose +routines += oldiofopen oldiofclose oldiofclose endif CPPFLAGS-.o += -DIO_DEBUG @@ -62,7 +62,8 @@ ifeq ($(versioning),yes) aux += oldfileops oldstdfiles endif -shared-only-routines = oldiofopen oldiofclose oldfileops oldstdfiles +shared-only-routines = oldiofopen oldiofdopen oldiofclose oldfileops \ + oldstdfiles distribute := iolibio.h libioP.h strfile.h Banner diff --git a/libio/fileops.c b/libio/fileops.c index a0cc2f7..d2377af 100644 --- a/libio/fileops.c +++ b/libio/fileops.c @@ -108,11 +108,10 @@ void _IO_file_init (fp) _IO_FILE *fp; { - struct _IO_FILE_complete *fc = (struct _IO_FILE_complete *) fp; /* POSIX.1 allows another file handle to be used to change the position of our file descriptor. Hence we actually don't know the actual position before we do the first fseek (and until a following fflush). */ - fc->_offset = _IO_pos_BAD; + fp->_offset = _IO_pos_BAD; fp->_IO_file_flags |= CLOSED_FILEBUF_FLAGS; _IO_link_in(fp); @@ -123,7 +122,6 @@ int _IO_file_close_it (fp) _IO_FILE *fp; { - struct _IO_FILE_complete *fc = (struct _IO_FILE_complete *) fp; int write_status, close_status; if (!_IO_file_is_open (fp)) return EOF; @@ -142,7 +140,7 @@ _IO_file_close_it (fp) _IO_un_link (fp); fp->_flags = _IO_MAGIC|CLOSED_FILEBUF_FLAGS; fp->_fileno = EOF; - fc->_offset = _IO_pos_BAD; + fp->_offset = _IO_pos_BAD; return close_status ? close_status : write_status; } @@ -161,6 +159,38 @@ _IO_file_finish (fp, dummy) _IO_default_finish (fp, 0); } +#if defined __GNUC__ && __GNUC__ >= 2 +__inline__ +#endif +_IO_FILE * +_IO_file_open (fp, filename, posix_mode, prot, read_write, is32not64) + _IO_FILE *fp; + const char *filename; + int posix_mode; + int prot; + int read_write; + int is32not64; +{ + int fdesc; +#ifdef _G_OPEN64 + fdesc = (is32not64 + ? open (filename, posix_mode, prot) + : _G_OPEN64 (filename, posix_mode, prot)); +#else + fdesc = open (filename, posix_mode, prot); +#endif + if (fdesc < 0) + return NULL; + fp->_fileno = fdesc; + _IO_mask_flags (fp, read_write,_IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING); + if (read_write & _IO_IS_APPENDING) + if (_IO_SEEKOFF (fp, (_IO_off64_t)0, _IO_seek_end, _IOS_INPUT|_IOS_OUTPUT) + == _IO_pos_BAD && errno != ESPIPE) + return NULL; + _IO_link_in (fp); + return fp; +} + _IO_FILE * _IO_file_fopen (fp, filename, mode, is32not64) _IO_FILE *fp; @@ -169,7 +199,7 @@ _IO_file_fopen (fp, filename, mode, is32not64) int is32not64; { int oflags = 0, omode; - int read_write, fdesc; + int read_write; int oprot = 0666; if (_IO_file_is_open (fp)) return 0; @@ -198,23 +228,8 @@ _IO_file_fopen (fp, filename, mode, is32not64) omode = O_RDWR; read_write &= _IO_IS_APPENDING; } -#ifdef _G_OPEN64 - fdesc = (is32not64 - ? open (filename, omode|oflags, oprot) - : _G_OPEN64 (filename, omode|oflags, oprot)); -#else - fdesc = open (filename, omode|oflags, oprot); -#endif - if (fdesc < 0) - return NULL; - fp->_fileno = fdesc; - _IO_mask_flags (fp, read_write,_IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING); - if (read_write & _IO_IS_APPENDING) - if (_IO_SEEKOFF (fp, (_IO_off64_t)0, _IO_seek_end, _IOS_INPUT|_IOS_OUTPUT) - == _IO_pos_BAD && errno != ESPIPE) - return NULL; - _IO_link_in (fp); - return fp; + return _IO_file_open (fp, filename, omode|oflags, oprot, read_write, + is32not64); } _IO_FILE * @@ -222,7 +237,6 @@ _IO_file_attach (fp, fd) _IO_FILE *fp; int fd; { - struct _IO_FILE_complete *fc = (struct _IO_FILE_complete *) fp; if (_IO_file_is_open (fp)) return NULL; fp->_fileno = fd; @@ -230,7 +244,7 @@ _IO_file_attach (fp, fd) fp->_flags |= _IO_DELETE_DONT_CLOSE; /* Get the current position of the file. */ /* We have to do that since that may be junk. */ - fc->_offset = _IO_pos_BAD; + fp->_offset = _IO_pos_BAD; if (_IO_SEEKOFF (fp, (_IO_off64_t)0, _IO_seek_cur, _IOS_INPUT|_IOS_OUTPUT) == _IO_pos_BAD && errno != ESPIPE) return NULL; @@ -262,7 +276,6 @@ _IO_do_write (fp, data, to_do) const char *data; _IO_size_t to_do; { - struct _IO_FILE_complete *fc = (struct _IO_FILE_complete *) fp; _IO_size_t count; if (to_do == 0) return 0; @@ -272,14 +285,14 @@ _IO_do_write (fp, data, to_do) is not needed nor desirable for Unix- or Posix-like systems. Instead, just indicate that offset (before and after) is unpredictable. */ - fc->_offset = _IO_pos_BAD; + fp->_offset = _IO_pos_BAD; else if (fp->_IO_read_end != fp->_IO_write_base) { _IO_fpos64_t new_pos = _IO_SYSSEEK (fp, fp->_IO_write_base - fp->_IO_read_end, 1); if (new_pos == _IO_pos_BAD) return EOF; - fc->_offset = new_pos; + fp->_offset = new_pos; } count = _IO_SYSWRITE (fp, data, to_do); if (fp->_cur_column) @@ -295,7 +308,6 @@ int _IO_file_underflow (fp) _IO_FILE *fp; { - struct _IO_FILE_complete *fc = (struct _IO_FILE_complete *) fp; _IO_ssize_t count; #if 0 /* SysV does not make this test; take it out for compatibility */ @@ -342,8 +354,8 @@ _IO_file_underflow (fp) fp->_IO_read_end += count; if (count == 0) return EOF; - if (fc->_offset != _IO_pos_BAD) - _IO_pos_adjust (fc->_offset, count); + if (fp->_offset != _IO_pos_BAD) + _IO_pos_adjust (fp->_offset, count); return *(unsigned char *) fp->_IO_read_ptr; } @@ -402,7 +414,6 @@ int _IO_file_sync (fp) _IO_FILE *fp; { - struct _IO_FILE_complete *fc = (struct _IO_FILE_complete *) fp; _IO_size_t delta; int retval = 0; @@ -429,7 +440,7 @@ _IO_file_sync (fp) retval = EOF; } if (retval != EOF) - fc->_offset = _IO_pos_BAD; + fp->_offset = _IO_pos_BAD; /* FIXME: Cleanup - can this be shared? */ /* setg(base(), ptr, ptr); */ _IO_cleanup_region_end (1); @@ -443,7 +454,6 @@ _IO_file_seekoff (fp, offset, dir, mode) int dir; int mode; { - struct _IO_FILE_complete *fc = (struct _IO_FILE_complete *) fp; _IO_fpos64_t result; _IO_off64_t delta, new_offset; long count; @@ -479,10 +489,10 @@ _IO_file_seekoff (fp, offset, dir, mode) case _IO_seek_cur: /* Adjust for read-ahead (bytes is buffer). */ offset -= fp->_IO_read_end - fp->_IO_read_ptr; - if (fc->_offset == _IO_pos_BAD) + if (fp->_offset == _IO_pos_BAD) goto dumb; /* Make offset absolute, assuming current pointer is file_ptr(). */ - offset += _IO_pos_as_off (fc->_offset); + offset += _IO_pos_as_off (fp->_offset); dir = _IO_seek_set; break; @@ -503,11 +513,11 @@ _IO_file_seekoff (fp, offset, dir, mode) /* At this point, dir==_IO_seek_set. */ /* If destination is within current buffer, optimize: */ - if (fc->_offset != _IO_pos_BAD && fp->_IO_read_base != NULL + if (fp->_offset != _IO_pos_BAD && fp->_IO_read_base != NULL && !_IO_in_backup (fp)) { /* Offset relative to start of main get area. */ - _IO_fpos64_t rel_offset = (offset - fc->_offset + _IO_fpos64_t rel_offset = (offset - fp->_offset + (fp->_IO_read_end - fp->_IO_read_base)); if (rel_offset >= 0) { @@ -581,7 +591,7 @@ _IO_file_seekoff (fp, offset, dir, mode) _IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base + delta, fp->_IO_buf_base + count); _IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base); - fc->_offset = result + count; + fp->_offset = result + count; _IO_mask_flags (fp, 0, _IO_EOF_SEEN); return offset; dumb: @@ -590,7 +600,7 @@ _IO_file_seekoff (fp, offset, dir, mode) result = _IO_SYSSEEK (fp, offset, dir); if (result != EOF) _IO_mask_flags (fp, 0, _IO_EOF_SEEN); - fc->_offset = result; + fp->_offset = result; _IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base); _IO_setp (fp, fp->_IO_buf_base, fp->_IO_buf_base); return result; @@ -643,7 +653,6 @@ _IO_file_write (f, data, n) const void *data; _IO_ssize_t n; { - struct _IO_FILE_complete *fc = (struct _IO_FILE_complete *) f; _IO_ssize_t to_do = n; while (to_do > 0) { @@ -657,8 +666,8 @@ _IO_file_write (f, data, n) data = (void *) ((char *) data + count); } n -= to_do; - if (fc->_offset >= 0) - fc->_offset += n; + if (f->_offset >= 0) + f->_offset += n; return n; } diff --git a/libio/genops.c b/libio/genops.c index 3776b9e..ea602ed 100644 --- a/libio/genops.c +++ b/libio/genops.c @@ -531,6 +531,9 @@ _IO_init (fp, flags) fp->_IO_save_end = NULL; fp->_markers = NULL; fp->_cur_column = 0; +#if _IO_JUMPS_OFFSET + fp->_vtable_offset = 0; +#endif #ifdef _IO_MTSAFE_IO _IO_lock_init (*fp->_lock); #endif diff --git a/libio/iofdopen.c b/libio/iofdopen.c index b650825..2ecbce3 100644 --- a/libio/iofdopen.c +++ b/libio/iofdopen.c @@ -34,7 +34,7 @@ #endif _IO_FILE * -_IO_fdopen (fd, mode) +_IO_new_fdopen (fd, mode) int fd; const char *mode; { @@ -42,7 +42,7 @@ _IO_fdopen (fd, mode) int posix_mode = 0; struct locked_FILE { - struct _IO_FILE_complete fp; + struct _IO_FILE_plus fp; #ifdef _IO_MTSAFE_IO _IO_lock_t lock; #endif @@ -106,29 +106,36 @@ _IO_fdopen (fd, mode) if (new_f == NULL) return NULL; #ifdef _IO_MTSAFE_IO - new_f->fp.plus.file._lock = &new_f->lock; + new_f->fp.file._lock = &new_f->lock; #endif - _IO_init (&new_f->fp.plus.file, 0); - _IO_JUMPS (&new_f->fp.plus.file) = &_IO_file_jumps; - _IO_file_init (&new_f->fp.plus.file); + _IO_init (&new_f->fp.file, 0); + _IO_JUMPS (&new_f->fp) = &_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.plus.file, fd) == NULL) + if (_IO_file_attach (&new_f->fp.file, fd) == NULL) { - _IO_un_link (&new_f->fp.plus.file); + _IO_un_link (&new_f->fp.file); free (new_f); return NULL; } - new_f->fp.plus.file._flags &= ~_IO_DELETE_DONT_CLOSE; + new_f->fp.file._flags &= ~_IO_DELETE_DONT_CLOSE; - new_f->fp.plus.file._IO_file_flags = - _IO_mask_flags (&new_f->fp.plus.file, read_write, + 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; } -#ifdef weak_alias -weak_alias (_IO_fdopen, fdopen) +#ifdef DO_VERSIONING +strong_alias (_IO_new_fdopen, __new_fdopen) +default_symbol_version (_IO_new_fdopen, _IO_fdopen, GLIBC_2.1); +default_symbol_version (__new_fdopen, fdopen, GLIBC_2.1); +#else +# ifdef weak_alias +weak_alias (_IO_new_fdopen, _IO_fdopen) +weak_alias (_IO_new_fdopen, fdopen) +# endif #endif diff --git a/libio/iofgets.c b/libio/iofgets.c index 74754d5..91db09f 100644 --- a/libio/iofgets.c +++ b/libio/iofgets.c @@ -34,11 +34,17 @@ _IO_fgets (buf, n, fp) { _IO_size_t count; char *result; + int old_error; CHECK_FILE (fp, NULL); if (n <= 0) return NULL; _IO_cleanup_region_start ((void (*) __P ((void *))) _IO_funlockfile, fp); _IO_flockfile (fp); + /* This is very tricky since a file descriptor may be in the + non-blocking mode. The error flag doesn't mean much in this + case. We return an error only when there is a new error. */ + old_error = fp->_IO_file_flags & _IO_ERR_SEEN; + fp->_IO_file_flags &= ~_IO_ERR_SEEN; count = _IO_getline (fp, buf, n - 1, '\n', 1); if (count == 0 || (fp->_IO_file_flags & _IO_ERR_SEEN)) result = NULL; @@ -47,6 +53,7 @@ _IO_fgets (buf, n, fp) buf[count] = '\0'; result = buf; } + fp->_IO_file_flags |= old_error; _IO_cleanup_region_end (1); return result; } diff --git a/libio/iofopen.c b/libio/iofopen.c index 59d1ce5..41da8f1 100644 --- a/libio/iofopen.c +++ b/libio/iofopen.c @@ -35,7 +35,7 @@ _IO_new_fopen (filename, mode) { struct locked_FILE { - struct _IO_FILE_complete fp; + struct _IO_FILE_plus fp; #ifdef _IO_MTSAFE_IO _IO_lock_t lock; #endif @@ -44,17 +44,17 @@ _IO_new_fopen (filename, mode) if (new_f == NULL) return NULL; #ifdef _IO_MTSAFE_IO - new_f->fp.plus.file._lock = &new_f->lock; + new_f->fp.file._lock = &new_f->lock; #endif - _IO_init (&new_f->fp.plus.file, 0); - _IO_JUMPS (&new_f->fp.plus.file) = &_IO_file_jumps; - _IO_file_init (&new_f->fp.plus.file); + _IO_init (&new_f->fp.file, 0); + _IO_JUMPS (&new_f->fp) = &_IO_file_jumps; + _IO_file_init (&new_f->fp.file); #if !_IO_UNIFIED_JUMPTABLES - new_f->fp.plus.vtable = NULL; + new_f->fp.vtable = NULL; #endif - if (_IO_file_fopen (&new_f->fp.plus.file, filename, mode, 0) != NULL) - return (_IO_FILE *) &new_f->fp.plus; - _IO_un_link (&new_f->fp.plus.file); + if (_IO_file_fopen (&new_f->fp.file, filename, mode, 0) != NULL) + return (_IO_FILE *) &new_f->fp; + _IO_un_link (&new_f->fp.file); free (new_f); return NULL; } diff --git a/libio/iofopen64.c b/libio/iofopen64.c index fc6ccc0..3572295 100644 --- a/libio/iofopen64.c +++ b/libio/iofopen64.c @@ -36,7 +36,7 @@ _IO_fopen64 (filename, mode) #ifdef _G_OPEN64 struct locked_FILE { - struct _IO_FILE_complete fp; + struct _IO_FILE_plus fp; #ifdef _IO_MTSAFE_IO _IO_lock_t lock; #endif @@ -45,17 +45,17 @@ _IO_fopen64 (filename, mode) if (new_f == NULL) return NULL; #ifdef _IO_MTSAFE_IO - new_f->fp.plus.file._lock = &new_f->lock; + new_f->fp.file._lock = &new_f->lock; #endif - _IO_init (&new_f->fp.plus.file, 0); - _IO_JUMPS (&new_f->fp.plus.file) = &_IO_file_jumps; - _IO_file_init (&new_f->fp.plus.file); + _IO_init (&new_f->fp.file, 0); + _IO_JUMPS (&new_f->fp) = &_IO_file_jumps; + _IO_file_init (&new_f->fp.file); #if !_IO_UNIFIED_JUMPTABLES new_f->fp.plus.vtable = NULL; #endif - if (_IO_file_fopen (&new_f->fp.plus.file, filename, mode, 1) != NULL) - return (_IO_FILE *) &new_f->fp.plus; - _IO_un_link (&new_f->fp.plus.file); + if (_IO_file_fopen (&new_f->fp.file, filename, mode, 1) != NULL) + return (_IO_FILE *) &new_f->fp; + _IO_un_link (&new_f->fp.file); free (new_f); return NULL; #else diff --git a/libio/iogets.c b/libio/iogets.c index 9e88ca1..a61699d 100644 --- a/libio/iogets.c +++ b/libio/iogets.c @@ -47,6 +47,11 @@ _IO_gets (buf) count = 0; else { + /* This is very tricky since a file descriptor may be in the + non-blocking mode. The error flag doesn't mean much in this + case. We return an error only when there is a new error. */ + int old_error = _IO_stdin->_IO_file_flags & _IO_ERR_SEEN; + _IO_stdin->_IO_file_flags &= ~_IO_ERR_SEEN; buf[0] = (char) ch; count = _IO_getline (_IO_stdin, buf + 1, INT_MAX, '\n', 0) + 1; if (_IO_stdin->_IO_file_flags & _IO_ERR_SEEN) @@ -54,6 +59,8 @@ _IO_gets (buf) retval = NULL; goto unlock_return; } + else + _IO_stdin->_IO_file_flags |= old_error; } buf[count] = 0; retval = buf; diff --git a/libio/iolibio.h b/libio/iolibio.h index 1eef384..ec54d63 100644 --- a/libio/iolibio.h +++ b/libio/iolibio.h @@ -11,6 +11,8 @@ extern int _IO_fclose __P((_IO_FILE*)); extern int _IO_new_fclose __P((_IO_FILE*)); extern int _IO_old_fclose __P((_IO_FILE*)); extern _IO_FILE *_IO_fdopen __P((int, const char*)); +extern _IO_FILE *_IO_old_fdopen __P((int, const char*)); +extern _IO_FILE *_IO_new_fdopen __P((int, const char*)); extern int _IO_fflush __P((_IO_FILE*)); extern int _IO_fgetpos __P((_IO_FILE*, _IO_fpos_t*)); extern int _IO_fgetpos64 __P((_IO_FILE*, _IO_fpos64_t*)); diff --git a/libio/iopopen.c b/libio/iopopen.c index a03cf63..3d2a796 100644 --- a/libio/iopopen.c +++ b/libio/iopopen.c @@ -74,7 +74,7 @@ extern int _IO_dup2 __P ((int fd, int fd2)); struct _IO_proc_file { - struct _IO_FILE_complete file; + struct _IO_FILE_plus file; /* Following fields must match those in class procbuf (procbuf.h) */ _IO_pid_t pid; struct _IO_proc_file *next; @@ -174,7 +174,7 @@ _IO_popen (command, mode) if (new_f == NULL) return NULL; #ifdef _IO_MTSAFE_IO - new_f->fpx.file.plus.file._lock = &new_f->lock; + new_f->fpx.file.file._lock = &new_f->lock; #endif fp = (_IO_FILE*)&new_f->fpx; _IO_init (fp, 0); diff --git a/libio/iovdprintf.c b/libio/iovdprintf.c index 04b40e7..a24d3b5 100644 --- a/libio/iovdprintf.c +++ b/libio/iovdprintf.c @@ -32,35 +32,35 @@ _IO_vdprintf (d, format, arg) const char *format; _IO_va_list arg; { - struct _IO_FILE_complete tmpfil; + struct _IO_FILE_plus tmpfil; #ifdef _IO_MTSAFE_IO _IO_lock_t lock; #endif int done; #ifdef _IO_MTSAFE_IO - tmpfil.plus.file._lock = &lock; + tmpfil.file._lock = &lock; #endif - _IO_init (&tmpfil.plus.file, 0); - _IO_JUMPS (&tmpfil.plus.file) = &_IO_file_jumps; - _IO_file_init (&tmpfil.plus.file); + _IO_init (&tmpfil.file, 0); + _IO_JUMPS (&tmpfil.file) = &_IO_file_jumps; + _IO_file_init (&tmpfil.file); #if !_IO_UNIFIED_JUMPTABLES tmpfil.vtable = NULL; #endif - if (_IO_file_attach (&tmpfil.plus.file, d) == NULL) + if (_IO_file_attach (&tmpfil.file, d) == NULL) { - _IO_un_link (&tmpfil.plus.file); + _IO_un_link (&tmpfil.file); return EOF; } - tmpfil.plus.file._flags &= ~_IO_DELETE_DONT_CLOSE; + tmpfil.file._flags &= ~_IO_DELETE_DONT_CLOSE; - tmpfil.plus.file._IO_file_flags = - _IO_mask_flags (&tmpfil.plus.file, _IO_NO_READS, + tmpfil.file._IO_file_flags = + _IO_mask_flags (&tmpfil.file, _IO_NO_READS, _IO_NO_READS+_IO_NO_WRITES+_IO_IS_APPENDING); - done = _IO_vfprintf (&tmpfil.plus.file, format, arg); + done = _IO_vfprintf (&tmpfil.file, format, arg); - _IO_FINISH (&tmpfil.plus.file); + _IO_FINISH (&tmpfil.file); return done; } diff --git a/libio/libio.h b/libio/libio.h index 0c12ff0..f6b3b22 100644 --- a/libio/libio.h +++ b/libio/libio.h @@ -212,22 +212,33 @@ struct _IO_FILE { #define __HAVE_COLUMN /* temporary */ /* 1+column number of pbase(); 0 is unknown. */ unsigned short _cur_column; - char _unused; + signed char _vtable_offset; char _shortbuf[1]; /* char* _save_gptr; char* _save_egptr; */ _IO_lock_t *_lock; +#ifdef _IO_USE_OLD_IO_FILE +}; + +struct _IO_FILE_complete +{ + struct _IO_FILE _file; +#endif +#if defined _G_IO_IO_FILE_VERSION && _G_IO_IO_FILE_VERSION == 0x20001 + _IO_off64_t _offset; + int _unused2[16]; /* Make sure we don't get into trouble again. */ +#endif }; #ifndef __cplusplus typedef struct _IO_FILE _IO_FILE; #endif -struct _IO_FILE_complete; -extern struct _IO_FILE_complete _IO_2_1_stdin_; -extern struct _IO_FILE_complete _IO_2_1_stdout_; -extern struct _IO_FILE_complete _IO_2_1_stderr_; +struct _IO_FILE_plus; +extern struct _IO_FILE_plus _IO_2_1_stdin_; +extern struct _IO_FILE_plus _IO_2_1_stdout_; +extern struct _IO_FILE_plus _IO_2_1_stderr_; #ifndef _LIBC #define _IO_stdin ((_IO_FILE*)(&_IO_2_1_stdin_)) #define _IO_stdout ((_IO_FILE*)(&_IO_2_1_stdout_)) diff --git a/libio/libioP.h b/libio/libioP.h index a69d75b..568bbe8 100644 --- a/libio/libioP.h +++ b/libio/libioP.h @@ -64,22 +64,34 @@ extern "C" { * object being acted on (i.e. the 'this' parameter). */ +#if (!defined _IO_USE_OLD_IO_FILE \ + && (!defined _G_IO_NO_BACKWARD_COMPAT || _G_IO_NO_BACKWARD_COMPAT == 0)) +# define _IO_JUMPS_OFFSET 1 +#endif + #define _IO_JUMPS(THIS) ((struct _IO_FILE_plus *) (THIS))->vtable +#if _IO_JUMPS_OFFSET +# define _IO_JUMPS_FUNC(THIS) \ + (*(struct _IO_jump_t **) ((void *) &((struct _IO_FILE_plus *) (THIS))->vtable\ + + (THIS)->_vtable_offset)) +#else +# define _IO_JUMPS_FUNC(THIS) _IO_JUMPS(THIS) +#endif #ifdef _G_USING_THUNKS # define JUMP_FIELD(TYPE, NAME) TYPE NAME -# define JUMP0(FUNC, THIS) _IO_JUMPS(THIS)->FUNC (THIS) -# define JUMP1(FUNC, THIS, X1) _IO_JUMPS(THIS)->FUNC (THIS, X1) -# define JUMP2(FUNC, THIS, X1, X2) _IO_JUMPS(THIS)->FUNC (THIS, X1, X2) -# define JUMP3(FUNC, THIS, X1,X2,X3) _IO_JUMPS(THIS)->FUNC (THIS, X1,X2, X3) +# define JUMP0(FUNC, THIS) _IO_JUMPS_FUNC(THIS)->FUNC (THIS) +# define JUMP1(FUNC, THIS, X1) _IO_JUMPS_FUNC(THIS)->FUNC (THIS, X1) +# define JUMP2(FUNC, THIS, X1, X2) _IO_JUMPS_FUNC(THIS)->FUNC (THIS, X1, X2) +# define JUMP3(FUNC, THIS, X1,X2,X3) _IO_JUMPS_FUNC(THIS)->FUNC (THIS, X1,X2, X3) # define JUMP_INIT(NAME, VALUE) VALUE # define JUMP_INIT_DUMMY JUMP_INIT(dummy, 0), JUMP_INIT (dummy2, 0) #else /* These macros will change when we re-implement vtables to use "thunks"! */ # define JUMP_FIELD(TYPE, NAME) struct { short delta1, delta2; TYPE pfn; } NAME -# define JUMP0(FUNC, THIS) _IO_JUMPS(THIS)->FUNC.pfn (THIS) -# define JUMP1(FUNC, THIS, X1) _IO_JUMPS(THIS)->FUNC.pfn (THIS, X1) -# define JUMP2(FUNC, THIS, X1, X2) _IO_JUMPS(THIS)->FUNC.pfn (THIS, X1, X2) -# define JUMP3(FUNC, THIS, X1,X2,X3) _IO_JUMPS(THIS)->FUNC.pfn (THIS, X1,X2,X3) +# define JUMP0(FUNC, THIS) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS) +# define JUMP1(FUNC, THIS, X1) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1) +# define JUMP2(FUNC, THIS, X1, X2) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1, X2) +# define JUMP3(FUNC, THIS, X1,X2,X3) _IO_JUMPS_FUNC(THIS)->FUNC.pfn (THIS, X1,X2,X3) # define JUMP_INIT(NAME, VALUE) {0, 0, VALUE} # define JUMP_INIT_DUMMY JUMP_INIT(dummy, 0) #endif @@ -267,17 +279,6 @@ struct _IO_FILE_plus const struct _IO_jump_t *vtable; }; -/* We had to extend _IO_FILE but this isn't easily possible without - compatibility problems. So we mimic the C++ way to do this which - especially takes care that the position of the vtable stays the - same. */ -struct _IO_FILE_complete -{ - struct _IO_FILE_plus plus; - _IO_off64_t _offset; - int _unused2[16]; /* Make sure we don't get into trouble again. */ -}; - /* Generic functions */ extern _IO_fpos64_t _IO_seekoff __P ((_IO_FILE *, _IO_off64_t, int, int)); @@ -374,6 +375,8 @@ extern int _IO_file_overflow __P ((_IO_FILE *, int)); #define _IO_file_is_open(__fp) ((__fp)->_fileno >= 0) extern void _IO_file_init __P ((_IO_FILE *)); extern _IO_FILE* _IO_file_attach __P ((_IO_FILE *, int)); +extern _IO_FILE* _IO_file_open __P ((_IO_FILE *, const char *, int, int, + int, int)); extern _IO_FILE* _IO_file_fopen __P ((_IO_FILE *, const char *, const char *, int)); extern _IO_ssize_t _IO_file_write __P ((_IO_FILE *, const void *, diff --git a/libio/oldfileops.c b/libio/oldfileops.c index eec9eed..a8237c6 100644 --- a/libio/oldfileops.c +++ b/libio/oldfileops.c @@ -32,6 +32,7 @@ #ifndef _POSIX_SOURCE # define _POSIX_SOURCE #endif +#define _IO_USE_OLD_IO_FILE #include "libioP.h" #include <fcntl.h> #include <sys/types.h> @@ -119,6 +120,8 @@ _IO_old_file_init (fp) fp->_IO_file_flags |= CLOSED_FILEBUF_FLAGS; _IO_link_in(fp); + fp->_vtable_offset = ((int) sizeof (struct _IO_FILE) + - (int) sizeof (struct _IO_FILE_complete)); fp->_fileno = -1; } diff --git a/libio/oldiofclose.c b/libio/oldiofclose.c index 5eed066..5f3e102 100644 --- a/libio/oldiofclose.c +++ b/libio/oldiofclose.c @@ -23,6 +23,7 @@ other reasons why the executable file might be covered by the GNU General Public License. */ +#define _IO_USE_OLD_IO_FILE #include "libioP.h" #ifdef __STDC__ #include <stdlib.h> diff --git a/libio/oldiofdopen.c b/libio/oldiofdopen.c new file mode 100644 index 0000000..e9c18d9 --- /dev/null +++ b/libio/oldiofdopen.c @@ -0,0 +1,135 @@ +/* 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. */ + +#define _IO_USE_OLD_IO_FILE +#ifdef __STDC__ +#include <stdlib.h> +#endif +#include "libioP.h" +#include <fcntl.h> + +#ifndef _IO_fcntl +#define _IO_fcntl fcntl +#endif + +_IO_FILE * +_IO_old_fdopen (fd, mode) + int fd; + const char *mode; +{ + int read_write; + int posix_mode = 0; + struct locked_FILE + { + struct _IO_FILE_plus fp; +#ifdef _IO_MTSAFE_IO + _IO_lock_t lock; +#endif + } *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: + MAYBE_SET_EINVAL; + 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; +#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) = &_IO_old_file_jumps; + _IO_old_file_init (&new_f->fp.file); +#if !_IO_UNIFIED_JUMPTABLES + new_f->fp.vtable = NULL; +#endif + if (_IO_old_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; +} + +strong_alias (_IO_old_fdopen, __old_fdopen) +symbol_version (_IO_old_fdopen, _IO_fdopen, GLIBC_2.0); +symbol_version (__old_fdopen, fdopen, GLIBC_2.0); diff --git a/libio/oldiofopen.c b/libio/oldiofopen.c index d0ffb02..5dffae8 100644 --- a/libio/oldiofopen.c +++ b/libio/oldiofopen.c @@ -23,6 +23,7 @@ other reasons why the executable file might be covered by the GNU General Public License. */ +#define _IO_USE_OLD_IO_FILE #include "libioP.h" #ifdef __STDC__ #include <stdlib.h> diff --git a/libio/oldstdfiles.c b/libio/oldstdfiles.c index 64c792f..baf6550 100644 --- a/libio/oldstdfiles.c +++ b/libio/oldstdfiles.c @@ -30,24 +30,24 @@ so the objects defined are not valid C++ objects. On the other hand, we don't need a C++ compiler to build this file.) */ +#define _IO_USE_OLD_IO_FILE #include "libioP.h" #ifdef _IO_MTSAFE_IO -#define DEF_STDFILE(INAME, NAME, FD, CHAIN, FLAGS) \ +#define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \ static _IO_lock_t _IO_stdfile_##FD##_lock = _IO_lock_initializer; \ - struct _IO_FILE_plus INAME \ + struct _IO_FILE_plus NAME \ = {FILEBUF_LITERAL(CHAIN, FLAGS, FD), &_IO_old_file_jumps}; #else -#define DEF_STDFILE(INAME, NAME, FD, CHAIN, FLAGS) \ - struct _IO_FILE_plus INAME \ +#define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \ + struct _IO_FILE_plus NAME \ = {FILEBUF_LITERAL(CHAIN, FLAGS, FD), &_IO_old_file_jumps}; #endif -DEF_STDFILE(_IO_stdin_, _IO_stdin_, 0, 0, _IO_NO_WRITES); -DEF_STDFILE(_IO_stdout_, _IO_stdout_, 1, &_IO_stdin_.file, - _IO_NO_READS); -DEF_STDFILE(_IO_stderr_, _IO_stderr_, 2, &_IO_stdout_.file, - _IO_NO_READS+_IO_UNBUFFERED); +DEF_STDFILE(_IO_stdin_, 0, 0, _IO_NO_WRITES); +DEF_STDFILE(_IO_stdout_, 1, &_IO_stdin_.file, _IO_NO_READS); +DEF_STDFILE(_IO_stderr_, 2, &_IO_stdout_.file, + _IO_NO_READS+_IO_UNBUFFERED); #if defined __GNUC__ && __GNUC__ >= 2 @@ -78,9 +78,14 @@ _IO_check_libio () if (&_IO_stdin_used == NULL) { /* We are using the old one. */ - stdin = &_IO_stdin_.file; - stdout = &_IO_stdout_.file; - stderr = _IO_list_all = &_IO_stderr_.file; + _IO_stdin = stdin = &_IO_stdin_.file; + _IO_stdout = stdout = &_IO_stdout_.file; + _IO_stderr = stderr = _IO_list_all = &_IO_stderr_.file; + _IO_stdin->_vtable_offset = _IO_stdout->_vtable_offset = + _IO_stderr->_vtable_offset = stdin->_vtable_offset = + stdout->_vtable_offset = stderr->_vtable_offset = + ((int) sizeof (struct _IO_FILE) + - (int) sizeof (struct _IO_FILE_complete)); } } diff --git a/libio/stdfiles.c b/libio/stdfiles.c index c70d474..8c09c2c 100644 --- a/libio/stdfiles.c +++ b/libio/stdfiles.c @@ -33,20 +33,19 @@ #include "libioP.h" #ifdef _IO_MTSAFE_IO -#define DEF_STDFILE(INAME, NAME, FD, CHAIN, FLAGS) \ +#define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \ static _IO_lock_t _IO_stdfile_##FD##_lock = _IO_lock_initializer; \ - struct _IO_FILE_complete INAME \ - = {{FILEBUF_LITERAL(CHAIN, FLAGS, FD), &_IO_file_jumps},}; + struct _IO_FILE_plus NAME \ + = {FILEBUF_LITERAL(CHAIN, FLAGS, FD), &_IO_file_jumps}; #else -#define DEF_STDFILE(INAME, NAME, FD, CHAIN, FLAGS) \ - struct _IO_FILE_complete INAME \ - = {{FILEBUF_LITERAL(CHAIN, FLAGS, FD), &_IO_file_jumps},}; +#define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \ + struct _IO_FILE_plus NAME \ + = {FILEBUF_LITERAL(CHAIN, FLAGS, FD), &_IO_file_jumps}; #endif -DEF_STDFILE(_IO_2_1_stdin_, _IO_stdin_, 0, 0, _IO_NO_WRITES); -DEF_STDFILE(_IO_2_1_stdout_, _IO_stdout_, 1, &_IO_2_1_stdin_.plus.file, - _IO_NO_READS); -DEF_STDFILE(_IO_2_1_stderr_, _IO_stderr_, 2, &_IO_2_1_stdout_.plus.file, +DEF_STDFILE(_IO_2_1_stdin_, 0, 0, _IO_NO_WRITES); +DEF_STDFILE(_IO_2_1_stdout_, 1, &_IO_2_1_stdin_.file, _IO_NO_READS); +DEF_STDFILE(_IO_2_1_stderr_, 2, &_IO_2_1_stdout_.file, _IO_NO_READS+_IO_UNBUFFERED); -_IO_FILE *_IO_list_all = &_IO_2_1_stderr_.plus.file; +_IO_FILE *_IO_list_all = &_IO_2_1_stderr_.file; diff --git a/libio/stdio.c b/libio/stdio.c index abea7f3..d4358c5 100644 --- a/libio/stdio.c +++ b/libio/stdio.c @@ -29,9 +29,9 @@ #undef stdin #undef stdout #undef stderr -FILE *stdin = &_IO_2_1_stdin_.plus.file; -FILE *stdout = &_IO_2_1_stdout_.plus.file; -FILE *stderr = &_IO_2_1_stderr_.plus.file; +FILE *stdin = &_IO_2_1_stdin_.file; +FILE *stdout = &_IO_2_1_stdout_.file; +FILE *stderr = &_IO_2_1_stderr_.file; #undef _IO_stdin #undef _IO_stdout |