1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-08-08 17:42:12 +03:00
1998-11-03  H.J. Lu  <hjl@gnu.org> 
 
	* libio/fileops.c (new_do_write): New function. 
	(_IO_new_do_write): Call new_do_write. 
	(_IO_new_file_xsputn): Likewise. 
 
	* libio/oldfileops.c (old_do_write): New function. 
	(_IO_old_do_write): Call old_do_write. 
	(_IO_old_file_xsputn): Likewise.
This commit is contained in:
Ulrich Drepper
1998-11-04 22:59:09 +00:00
parent 98b567ffae
commit 0720f75c4a
3 changed files with 66 additions and 28 deletions

View File

@@ -1,3 +1,13 @@
1998-11-03 H.J. Lu <hjl@gnu.org>
* libio/fileops.c (new_do_write): New function.
(_IO_new_do_write): Call new_do_write.
(_IO_new_file_xsputn): Likewise.
* libio/oldfileops.c (old_do_write): New function.
(_IO_old_do_write): Call old_do_write.
(_IO_old_file_xsputn): Likewise.
1998-11-04 Ulrich Drepper <drepper@cygnus.com> 1998-11-04 Ulrich Drepper <drepper@cygnus.com>
* time/mktime.c (__mktime_internal): Correct last change. We must * time/mktime.c (__mktime_internal): Correct last change. We must

View File

@@ -287,6 +287,8 @@ _IO_new_file_setbuf (fp, p, len)
return fp; return fp;
} }
static int new_do_write __P ((_IO_FILE *, const char *, _IO_size_t));
/* Write TO_DO bytes from DATA to FP. /* Write TO_DO bytes from DATA to FP.
Then mark FP as having empty buffers. */ Then mark FP as having empty buffers. */
@@ -295,10 +297,19 @@ _IO_new_do_write (fp, data, to_do)
_IO_FILE *fp; _IO_FILE *fp;
const char *data; const char *data;
_IO_size_t to_do; _IO_size_t to_do;
{
return (to_do == 0 || new_do_write (fp, data, to_do) == to_do)
? 0 : EOF;
}
static
int
new_do_write (fp, data, to_do)
_IO_FILE *fp;
const char *data;
_IO_size_t to_do;
{ {
_IO_size_t count; _IO_size_t count;
if (to_do == 0)
return 0;
if (fp->_flags & _IO_IS_APPENDING) if (fp->_flags & _IO_IS_APPENDING)
/* On a system without a proper O_APPEND implementation, /* On a system without a proper O_APPEND implementation,
you would need to sys_seek(0, SEEK_END) here, but is you would need to sys_seek(0, SEEK_END) here, but is
@@ -311,17 +322,17 @@ _IO_new_do_write (fp, data, to_do)
_IO_fpos64_t new_pos _IO_fpos64_t new_pos
= _IO_SYSSEEK (fp, fp->_IO_write_base - fp->_IO_read_end, 1); = _IO_SYSSEEK (fp, fp->_IO_write_base - fp->_IO_read_end, 1);
if (new_pos == _IO_pos_BAD) if (new_pos == _IO_pos_BAD)
return EOF; return 0;
fp->_offset = new_pos; fp->_offset = new_pos;
} }
count = _IO_SYSWRITE (fp, data, to_do); count = _IO_SYSWRITE (fp, data, to_do);
if (fp->_cur_column) if (fp->_cur_column && count)
fp->_cur_column = _IO_adjust_column (fp->_cur_column - 1, data, to_do) + 1; fp->_cur_column = _IO_adjust_column (fp->_cur_column - 1, data, count) + 1;
_IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base); _IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_buf_base; fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_buf_base;
fp->_IO_write_end = ((fp->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED)) fp->_IO_write_end = ((fp->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED))
? fp->_IO_buf_base : fp->_IO_buf_end); ? fp->_IO_buf_base : fp->_IO_buf_end);
return count != to_do ? EOF : 0; return count;
} }
int int
@@ -786,7 +797,7 @@ _IO_new_file_xsputn (f, data, n)
} }
if (to_do + must_flush > 0) if (to_do + must_flush > 0)
{ {
_IO_size_t block_size, dont_write; _IO_size_t block_size, do_write;
/* Next flush the (full) buffer. */ /* Next flush the (full) buffer. */
if (__overflow (f, EOF) == EOF) if (__overflow (f, EOF) == EOF)
return n - to_do; return n - to_do;
@@ -794,18 +805,21 @@ _IO_new_file_xsputn (f, data, n)
/* Try to maintain alignment: write a whole number of blocks. /* Try to maintain alignment: write a whole number of blocks.
dont_write is what gets left over. */ dont_write is what gets left over. */
block_size = f->_IO_buf_end - f->_IO_buf_base; block_size = f->_IO_buf_end - f->_IO_buf_base;
dont_write = block_size >= 128 ? to_do % block_size : 0; do_write = to_do - (block_size >= 128 ? to_do % block_size : 0);
count = to_do - dont_write; if (do_write)
if (_IO_new_do_write (f, s, count) == EOF) {
count = new_do_write (f, s, do_write);
to_do -= count;
if (count < do_write)
return n - to_do; return n - to_do;
to_do = dont_write; }
/* Now write out the remainder. Normally, this will fit in the /* Now write out the remainder. Normally, this will fit in the
buffer, but it's somewhat messier for line-buffered files, buffer, but it's somewhat messier for line-buffered files,
so we let _IO_default_xsputn handle the general case. */ so we let _IO_default_xsputn handle the general case. */
if (dont_write) if (to_do)
to_do -= _IO_default_xsputn (f, s+count, dont_write); to_do -= _IO_default_xsputn (f, s+do_write, to_do);
} }
return n - to_do; return n - to_do;
} }

View File

@@ -250,6 +250,8 @@ _IO_old_file_setbuf (fp, p, len)
return fp; return fp;
} }
static int old_do_write __P ((_IO_FILE *, const char *, _IO_size_t));
/* Write TO_DO bytes from DATA to FP. /* Write TO_DO bytes from DATA to FP.
Then mark FP as having empty buffers. */ Then mark FP as having empty buffers. */
@@ -258,10 +260,19 @@ _IO_old_do_write (fp, data, to_do)
_IO_FILE *fp; _IO_FILE *fp;
const char *data; const char *data;
_IO_size_t to_do; _IO_size_t to_do;
{
return (to_do == 0 || old_do_write (fp, data, to_do) == to_do)
? 0 : EOF;
}
static
int
old_do_write (fp, data, to_do)
_IO_FILE *fp;
const char *data;
_IO_size_t to_do;
{ {
_IO_size_t count; _IO_size_t count;
if (to_do == 0)
return 0;
if (fp->_flags & _IO_IS_APPENDING) if (fp->_flags & _IO_IS_APPENDING)
/* On a system without a proper O_APPEND implementation, /* On a system without a proper O_APPEND implementation,
you would need to sys_seek(0, SEEK_END) here, but is you would need to sys_seek(0, SEEK_END) here, but is
@@ -274,17 +285,17 @@ _IO_old_do_write (fp, data, to_do)
_IO_pos_t new_pos _IO_pos_t new_pos
= _IO_SYSSEEK (fp, fp->_IO_write_base - fp->_IO_read_end, 1); = _IO_SYSSEEK (fp, fp->_IO_write_base - fp->_IO_read_end, 1);
if (new_pos == _IO_pos_BAD) if (new_pos == _IO_pos_BAD)
return EOF; return 0;
fp->_old_offset = new_pos; fp->_old_offset = new_pos;
} }
count = _IO_SYSWRITE (fp, data, to_do); count = _IO_SYSWRITE (fp, data, to_do);
if (fp->_cur_column) if (fp->_cur_column && count)
fp->_cur_column = _IO_adjust_column (fp->_cur_column - 1, data, to_do) + 1; fp->_cur_column = _IO_adjust_column (fp->_cur_column - 1, data, count) + 1;
_IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base); _IO_setg (fp, fp->_IO_buf_base, fp->_IO_buf_base, fp->_IO_buf_base);
fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_buf_base; fp->_IO_write_base = fp->_IO_write_ptr = fp->_IO_buf_base;
fp->_IO_write_end = ((fp->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED)) fp->_IO_write_end = ((fp->_flags & (_IO_LINE_BUF+_IO_UNBUFFERED))
? fp->_IO_buf_base : fp->_IO_buf_end); ? fp->_IO_buf_base : fp->_IO_buf_end);
return count != to_do ? EOF : 0; return count;
} }
int int
@@ -684,7 +695,7 @@ _IO_old_file_xsputn (f, data, n)
} }
if (to_do + must_flush > 0) if (to_do + must_flush > 0)
{ {
_IO_size_t block_size, dont_write; _IO_size_t block_size, do_write;
/* Next flush the (full) buffer. */ /* Next flush the (full) buffer. */
if (__overflow (f, EOF) == EOF) if (__overflow (f, EOF) == EOF)
return n - to_do; return n - to_do;
@@ -692,18 +703,21 @@ _IO_old_file_xsputn (f, data, n)
/* Try to maintain alignment: write a whole number of blocks. /* Try to maintain alignment: write a whole number of blocks.
dont_write is what gets left over. */ dont_write is what gets left over. */
block_size = f->_IO_buf_end - f->_IO_buf_base; block_size = f->_IO_buf_end - f->_IO_buf_base;
dont_write = block_size >= 128 ? to_do % block_size : 0; do_write = to_do - (block_size >= 128 ? to_do % block_size : 0);
count = to_do - dont_write; if (do_write)
if (_IO_old_do_write (f, s, count) == EOF) {
count = old_do_write (f, s, do_write);
to_do -= count;
if (count < do_write)
return n - to_do; return n - to_do;
to_do = dont_write; }
/* Now write out the remainder. Normally, this will fit in the /* Now write out the remainder. Normally, this will fit in the
buffer, but it's somewhat messier for line-buffered files, buffer, but it's somewhat messier for line-buffered files,
so we let _IO_default_xsputn handle the general case. */ so we let _IO_default_xsputn handle the general case. */
if (dont_write) if (to_do)
to_do -= _IO_default_xsputn (f, s+count, dont_write); to_do -= _IO_default_xsputn (f, s+do_write, to_do);
} }
return n - to_do; return n - to_do;
} }