diff options
author | Jakub Jelinek <jakub@redhat.com> | 2005-10-03 20:44:20 +0000 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2005-10-03 20:44:20 +0000 |
commit | a5a11654ea5ea89bfffb295fbb2f17cbb45839b6 (patch) | |
tree | 2078fd7b828ae3b4c030e6722c53bdc81542a511 /libio | |
parent | 6543cff055c298ea3ec718b356f6c2115e8797ae (diff) |
Updated to fedora-glibc-20051003T2040
Diffstat (limited to 'libio')
-rw-r--r-- | libio/fileops.c | 6 | ||||
-rw-r--r-- | libio/fmemopen.c | 2 | ||||
-rw-r--r-- | libio/iofclose.c | 4 | ||||
-rw-r--r-- | libio/iofgets.c | 10 | ||||
-rw-r--r-- | libio/iofgets_u.c | 10 | ||||
-rw-r--r-- | libio/iofgetws.c | 10 | ||||
-rw-r--r-- | libio/iofgetws_u.c | 10 | ||||
-rw-r--r-- | libio/iofopncook.c | 11 | ||||
-rw-r--r-- | libio/iogetline.c | 56 | ||||
-rw-r--r-- | libio/oldfileops.c | 6 | ||||
-rw-r--r-- | libio/oldiofclose.c | 4 |
11 files changed, 87 insertions, 42 deletions
diff --git a/libio/fileops.c b/libio/fileops.c index 3ad9b74011..74d5cd0dbc 100644 --- a/libio/fileops.c +++ b/libio/fileops.c @@ -1281,7 +1281,7 @@ _IO_new_file_xsputn (f, data, n) register const char *s = (const char *) data; _IO_size_t to_do = n; int must_flush = 0; - _IO_size_t count; + _IO_size_t count = 0; if (n <= 0) return 0; @@ -1290,7 +1290,6 @@ _IO_new_file_xsputn (f, data, n) (or the filebuf is unbuffered), use sys_write directly. */ /* First figure out how much space is available in the buffer. */ - count = f->_IO_write_end - f->_IO_write_ptr; /* Space available. */ if ((f->_flags & _IO_LINE_BUF) && (f->_flags & _IO_CURRENTLY_PUTTING)) { count = f->_IO_buf_end - f->_IO_write_ptr; @@ -1308,6 +1307,9 @@ _IO_new_file_xsputn (f, data, n) } } } + else if (f->_IO_write_end > f->_IO_write_ptr) + count = f->_IO_write_end - f->_IO_write_ptr; /* Space available. */ + /* Then fill the buffer. */ if (count > 0) { diff --git a/libio/fmemopen.c b/libio/fmemopen.c index 7c8769a130..b847f62c9a 100644 --- a/libio/fmemopen.c +++ b/libio/fmemopen.c @@ -127,7 +127,7 @@ fmemopen_write (void *cookie, const char *b, size_t s) if ((size_t) (c->pos + addnullc) == c->size) { __set_errno (ENOSPC); - return -1; + return 0; } s = c->size - c->pos - addnullc; } diff --git a/libio/iofclose.c b/libio/iofclose.c index a372ae2b24..aa2ba40064 100644 --- a/libio/iofclose.c +++ b/libio/iofclose.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993,1995,1997-2003,2004 Free Software Foundation, Inc. +/* Copyright (C) 1993,1995,1997-2004,2005 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -62,8 +62,8 @@ _IO_new_fclose (fp) status = INTUSE(_IO_file_close_it) (fp); else status = fp->_flags & _IO_ERR_SEEN ? -1 : 0; - _IO_FINISH (fp); _IO_release_lock (fp); + _IO_FINISH (fp); if (fp->_mode > 0) { #if _LIBC diff --git a/libio/iofgets.c b/libio/iofgets.c index 879cc975a3..601b1746a1 100644 --- a/libio/iofgets.c +++ b/libio/iofgets.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1995, 1996, 1997, 1998, 1999, 2002, 2003 +/* Copyright (C) 1993, 1995, 1996, 1997, 1998, 1999, 2002, 2003, 2005 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -41,6 +41,14 @@ _IO_fgets (buf, n, fp) CHECK_FILE (fp, NULL); if (n <= 0) return NULL; + if (__builtin_expect (n == 1, 0)) + { + /* Another irregular case: since we have to store a NUL byte and + there is only room for exactly one byte, we don't have to + read anything. */ + buf[0] = '\0'; + return buf; + } _IO_acquire_lock (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 diff --git a/libio/iofgets_u.c b/libio/iofgets_u.c index ded2a7c83c..4fb5b1c0fd 100644 --- a/libio/iofgets_u.c +++ b/libio/iofgets_u.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993,1995,1996,1997,1998,2002 Free Software Foundation, Inc. +/* Copyright (C) 1993,1995-1998,2002,2005 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -40,6 +40,14 @@ fgets_unlocked (buf, n, fp) CHECK_FILE (fp, NULL); if (n <= 0) return NULL; + if (__builtin_expect (n == 1, 0)) + { + /* Another irregular case: since we have to store a NUL byte and + there is only room for exactly one byte, we don't have to + read anything. */ + buf[0] = '\0'; + return buf; + } /* 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. */ diff --git a/libio/iofgetws.c b/libio/iofgetws.c index 654c051a28..775391137a 100644 --- a/libio/iofgetws.c +++ b/libio/iofgetws.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1995, 1996, 1997, 1998, 1999, 2001 +/* Copyright (C) 1993, 1995, 1996, 1997, 1998, 1999, 2001, 2005 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -41,6 +41,14 @@ fgetws (buf, n, fp) CHECK_FILE (fp, NULL); if (n <= 0) return NULL; + if (__builtin_expect (n == 1, 0)) + { + /* Another irregular case: since we have to store a NUL byte and + there is only room for exactly one byte, we don't have to + read anything. */ + buf[0] = L'\0'; + return buf; + } _IO_acquire_lock (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 diff --git a/libio/iofgetws_u.c b/libio/iofgetws_u.c index 1253564566..9fb8a5cac1 100644 --- a/libio/iofgetws_u.c +++ b/libio/iofgetws_u.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 95, 96, 97, 98, 99 Free Software Foundation, Inc. +/* Copyright (C) 1993, 95, 96, 97, 98, 99, 2005 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -40,6 +40,14 @@ fgetws_unlocked (buf, n, fp) CHECK_FILE (fp, NULL); if (n <= 0) return NULL; + if (__builtin_expect (n == 1, 0)) + { + /* Another irregular case: since we have to store a NUL byte and + there is only room for exactly one byte, we don't have to + read anything. */ + buf[0] = L'\0'; + return buf; + } /* 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. */ diff --git a/libio/iofopncook.c b/libio/iofopncook.c index 9c5503d1f2..976ff5093a 100644 --- a/libio/iofopncook.c +++ b/libio/iofopncook.c @@ -64,9 +64,16 @@ _IO_cookie_write (fp, buf, size) struct _IO_cookie_file *cfile = (struct _IO_cookie_file *) fp; if (cfile->__io_functions.write == NULL) - return -1; + { + fp->_flags |= _IO_ERR_SEEN; + return 0; + } + + _IO_ssize_t n = cfile->__io_functions.write (cfile->__cookie, buf, size); + if (n < size) + fp->_flags |= _IO_ERR_SEEN; - return cfile->__io_functions.write (cfile->__cookie, buf, size); + return n; } static _IO_off64_t diff --git a/libio/iogetline.c b/libio/iogetline.c index eca38cf773..022a444f77 100644 --- a/libio/iogetline.c +++ b/libio/iogetline.c @@ -1,4 +1,5 @@ -/* Copyright (C) 1993,1997,1998,2000,2001,2002 Free Software Foundation, Inc. +/* Copyright (C) 1993,1997,1998,2000,2001,2002,2005 + Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -73,7 +74,8 @@ _IO_getline_info (fp, buf, n, delim, extract_delim, eof) int c = __uflow (fp); if (c == EOF) { - if (eof) *eof = c; + if (eof) + *eof = c; break; } if (c == delim) @@ -89,31 +91,31 @@ _IO_getline_info (fp, buf, n, delim, extract_delim, eof) *ptr++ = c; n--; } - else - { - char *t; - if ((_IO_size_t) len >= n) - len = n; - t = (char *) memchr ((void *) fp->_IO_read_ptr, delim, len); - if (t != NULL) - { - _IO_size_t old_len = ptr-buf; - len = t - fp->_IO_read_ptr; - if (extract_delim >= 0) - { - ++t; - if (extract_delim > 0) - ++len; - } - memcpy ((void *) ptr, (void *) fp->_IO_read_ptr, len); - fp->_IO_read_ptr = t; - return old_len + len; - } - memcpy ((void *) ptr, (void *) fp->_IO_read_ptr, len); - fp->_IO_read_ptr += len; - ptr += len; - n -= len; - } + else + { + char *t; + if ((_IO_size_t) len >= n) + len = n; + t = (char *) memchr ((void *) fp->_IO_read_ptr, delim, len); + if (t != NULL) + { + _IO_size_t old_len = ptr-buf; + len = t - fp->_IO_read_ptr; + if (extract_delim >= 0) + { + ++t; + if (extract_delim > 0) + ++len; + } + memcpy ((void *) ptr, (void *) fp->_IO_read_ptr, len); + fp->_IO_read_ptr = t; + return old_len + len; + } + memcpy ((void *) ptr, (void *) fp->_IO_read_ptr, len); + fp->_IO_read_ptr += len; + ptr += len; + n -= len; + } } return ptr - buf; } diff --git a/libio/oldfileops.c b/libio/oldfileops.c index 2dd618215b..cd54ea5811 100644 --- a/libio/oldfileops.c +++ b/libio/oldfileops.c @@ -695,7 +695,7 @@ _IO_old_file_xsputn (f, data, n) register const char *s = (char *) data; _IO_size_t to_do = n; int must_flush = 0; - _IO_size_t count; + _IO_size_t count = 0; if (n <= 0) return 0; @@ -704,7 +704,6 @@ _IO_old_file_xsputn (f, data, n) (or the filebuf is unbuffered), use sys_write directly. */ /* First figure out how much space is available in the buffer. */ - count = f->_IO_write_end - f->_IO_write_ptr; /* Space available. */ if ((f->_flags & _IO_LINE_BUF) && (f->_flags & _IO_CURRENTLY_PUTTING)) { count = f->_IO_buf_end - f->_IO_write_ptr; @@ -722,6 +721,9 @@ _IO_old_file_xsputn (f, data, n) } } } + else if (f->_IO_write_end > f->_IO_write_ptr) + count = f->_IO_write_end - f->_IO_write_ptr; /* Space available. */ + /* Then fill the buffer. */ if (count > 0) { diff --git a/libio/oldiofclose.c b/libio/oldiofclose.c index 8dd321b054..62c3154118 100644 --- a/libio/oldiofclose.c +++ b/libio/oldiofclose.c @@ -1,4 +1,4 @@ -/* Copyright (C) 1993, 1995, 1997-2002, 2004 Free Software Foundation, Inc. +/* Copyright (C) 1993,1995,1997-2002,2004,2005 Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -58,8 +58,8 @@ _IO_old_fclose (fp) status = _IO_old_file_close_it (fp); else status = fp->_flags & _IO_ERR_SEEN ? -1 : 0; - _IO_FINISH (fp); _IO_release_lock (fp); + _IO_FINISH (fp); if (_IO_have_backup (fp)) INTUSE(_IO_free_backup_area) (fp); if (fp != _IO_stdin && fp != _IO_stdout && fp != _IO_stderr) |