* libio/Makefile (headers): Add stdio_ext.h.
	(routines): Add __fbufsize, __freading, __fwriting, __freadable,
	__fwritable, __flbf, __fpurge, __fpending, and __fsetlocking.
	* libio/Versions [libc] (GLIBC_2.2): Add __fbufsize, __freading,
	__fwriting, __freadable, __fwritable, __flbf, __fpurge, __fpending,
	__fsetlocking, and _flushlbf.
	* libio/__fbufsize.c: New file.
	* libio/__flbf.c: New file.
	* libio/__fpending.c: New file.
	* libio/__fpurge.c: New file.
	* libio/__freadable.c: New file.
	* libio/__freading.c: New file.
	* libio/__fsetlocking.c: New file.
	* libio/__fwritable.c: New file.
	* libio/__fwriting.c: New file.
	* libio/stdio_ext.h: New file.
	* libio/genops.c (_IO_flush_all_linebuffered): Add alias _flushlbf.
	* libio/libio.h (_IO_USER_LOCK): Define.
This commit is contained in:
Ulrich Drepper 2000-09-01 08:56:06 +00:00
parent 6f7fa17e40
commit a91d3cd37b
17 changed files with 443 additions and 16 deletions

View File

@ -1,5 +1,24 @@
2000-09-01 Ulrich Drepper <drepper@redhat.com>
* libio/Makefile (headers): Add stdio_ext.h.
(routines): Add __fbufsize, __freading, __fwriting, __freadable,
__fwritable, __flbf, __fpurge, __fpending, and __fsetlocking.
* libio/Versions [libc] (GLIBC_2.2): Add __fbufsize, __freading,
__fwriting, __freadable, __fwritable, __flbf, __fpurge, __fpending,
__fsetlocking, and _flushlbf.
* libio/__fbufsize.c: New file.
* libio/__flbf.c: New file.
* libio/__fpending.c: New file.
* libio/__fpurge.c: New file.
* libio/__freadable.c: New file.
* libio/__freading.c: New file.
* libio/__fsetlocking.c: New file.
* libio/__fwritable.c: New file.
* libio/__fwriting.c: New file.
* libio/stdio_ext.h: New file.
* libio/genops.c (_IO_flush_all_linebuffered): Add alias _flushlbf.
* libio/libio.h (_IO_USER_LOCK): Define.
* iconv/gconv_open.c (__gconv_open): Set res to __GCONV_NOMEM is
malloc fails.

View File

@ -21,7 +21,8 @@
#
subdir := libio
headers := stdio.h libio.h _G_config.h bits/stdio.h bits/stdio-lock.h
headers := stdio.h libio.h _G_config.h bits/stdio.h bits/stdio-lock.h \
stdio_ext.h
routines := \
filedoalloc iofclose iofdopen iofflush iofgetpos iofgets iofopen \
@ -41,6 +42,9 @@ routines := \
iovdprintf vscanf vsnprintf obprintf fcloseall fseeko ftello \
freopen64 fseeko64 ftello64 \
\
__fbufsize __freading __fwriting __freadable __fwritable __flbf \
__fpurge __fpending __fsetlocking \
\
libc_fatal fmemopen
tests = tst_swprintf tst_wprintf tst_swscanf tst_wscanf tst_getwc tst_putwc \

View File

@ -118,6 +118,10 @@ libc {
_IO_iter_begin; _IO_iter_end; _IO_iter_next; _IO_iter_file;
_IO_list_lock; _IO_list_unlock; _IO_list_resetlock;
# Functions to access FILE internals.
__fbufsize; __freading; __fwriting; __freadable; __fwritable; __flbf;
__fpurge; __fpending; __fsetlocking; _flushlbf;
# f*
fgetpos; fgetpos64; fgetwc; fgetwc_unlocked; fgetws; fgetws_unlocked;
fputwc; fputwc_unlocked; fputws; fputws_unlocked; fsetpos; fsetpos64;

35
libio/__fbufsize.c Normal file
View File

@ -0,0 +1,35 @@
/* Copyright (C) 2000 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. */
#include <stdio_ext.h>
size_t
__fbufsize (FILE *fp)
{
if (fp->_mode > 0)
return fp->_wide_data->_IO_buf_end - fp->_wide_data->_IO_buf_base;
else
return fp->_IO_buf_end - fp->_IO_buf_base;
}

32
libio/__flbf.c Normal file
View File

@ -0,0 +1,32 @@
/* Copyright (C) 2000 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. */
#include <stdio_ext.h>
int
__flbf (FILE *fp)
{
return fp->_flags & _IO_LINE_BUF;
}

35
libio/__fpending.c Normal file
View File

@ -0,0 +1,35 @@
/* Copyright (C) 2000 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. */
#include <stdio_ext.h>
size_t
__fpending (FILE *fp)
{
if (fp->_mode > 0)
return fp->_wide_data->_IO_write_ptr - fp->_wide_data->_IO_write_base;
else
return fp->_IO_write_ptr - fp->_IO_write_base;
}

49
libio/__fpurge.c Normal file
View File

@ -0,0 +1,49 @@
/* Copyright (C) 2000 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. */
#include <stdio_ext.h>
void
__fpurge (FILE *fp)
{
if (fp->_mode > 0)
{
/* Wide-char stream. */
if (_IO_in_wbackup (fp))
_IO_free_wbackup_area (fp);
fp->_wide_data->_IO_read_end = fp->_wide_data->_IO_read_ptr;
fp->_wide_data->_IO_write_ptr = fp->_wide_data->_IO_write_base;
}
else
{
/* Byte stream. */
if (_IO_in_backup (fp))
_IO_free_backup_area (fp);
fp->_IO_read_end = fp->_IO_read_ptr;
fp->_IO_write_ptr = fp->_IO_write_base;
}
}

32
libio/__freadable.c Normal file
View File

@ -0,0 +1,32 @@
/* Copyright (C) 2000 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. */
#include <stdio_ext.h>
int
__freadable (FILE *fp)
{
return (fp->_flags & _IO_NO_READS) == 0;
}

33
libio/__freading.c Normal file
View File

@ -0,0 +1,33 @@
/* Copyright (C) 2000 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. */
#include <stdio_ext.h>
int
__freading (FILE *fp)
{
return ((fp->_flags & _IO_NO_WRITES)
|| (fp->_flags & _IO_CURRENTLY_PUTTING) == 0);
}

42
libio/__fsetlocking.c Normal file
View File

@ -0,0 +1,42 @@
/* Copyright (C) 2000 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. */
#include <stdio_ext.h>
int
__fsetlocking (FILE *fp, int type)
{
int result = ((fp->_flags & _IO_USER_LOCK)
? FSETLOCKING_BYCALLER : FSETLOCKING_INTERNAL);
if (type != FSETLOCKING_QUERY)
{
fp->_flags &= ~_IO_USER_LOCK;
if (type == FSETLOCKING_BYCALLER)
fp->_flags |= _IO_USER_LOCK;
}
return result;
}

32
libio/__fwritable.c Normal file
View File

@ -0,0 +1,32 @@
/* Copyright (C) 2000 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. */
#include <stdio_ext.h>
int
__fwritable (FILE *fp)
{
return (fp->_flags & _IO_NO_WRITES) == 0;
}

32
libio/__fwriting.c Normal file
View File

@ -0,0 +1,32 @@
/* Copyright (C) 2000 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. */
#include <stdio_ext.h>
int
__fwriting (FILE *fp)
{
return fp->_flags & (_IO_NO_READS | _IO_CURRENTLY_PUTTING);
}

View File

@ -774,6 +774,9 @@ _IO_flush_all_linebuffered ()
if ((fp->_flags & _IO_NO_WRITES) == 0 && fp->_flags & _IO_LINE_BUF)
_IO_OVERFLOW (fp, EOF);
}
#ifdef _LIBC
weak_alias (_IO_flush_all_linebuffered, _flushlbf)
#endif
static void _IO_unbuffer_write __P ((void));

View File

@ -133,6 +133,7 @@
#define _IO_IS_APPENDING 0x1000
#define _IO_IS_FILEBUF 0x2000
#define _IO_BAD_SEEN 0x4000
#define _IO_USER_LOCK 0x8000
/* These are "formatting flags" matching the iostream fmtflags enum values. */
#define _IO_SKIPWS 01

86
libio/stdio_ext.h Normal file
View File

@ -0,0 +1,86 @@
/* Functions to access FILE structure internals.
Copyright (C) 2000 Free Software Foundation, Inc.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* This header contains the same definitions as the header of the same name
on Sun's Solaris OS. */
#ifndef _STDIO_EXT_H
#define _STDIO_EXT_H 1
#include <stdio.h>
enum
{
/* Query current state of the locking status. */
FSETLOCKING_QUERY = 0,
#define FSETLOCKING_QUERY FSETLOCKING_QUERY
/* The library protects all uses of the stream functions, except for
uses of the *_unlocked functions, by calls equivalent to flockfile(). */
FSETLOCKING_INTERNAL,
#define FSETLOCKING_INTERNAL FSETLOCKING_INTERNAL
/* The user will take care of locking. */
FSETLOCKING_BYCALLER
#define FSETLOCKING_BYCALLER FSETLOCKING_BYCALLER
};
__BEGIN_DECLS
/* Return the size of the buffer of FP in bytes currently in use by
the given stream. */
extern size_t __fbufsize (FILE *__fp);
/* Return non-zero value iff the stream FP is opened readonly, or if the
last operation on the stream was a read operation. */
extern int __freading (FILE *__fp);
/* Return non-zero value iff the stream FP is opened write-only or
append-only, or if the last operation on the stream was a write
operation. */
extern int __fwriting (FILE *__fp);
/* Return non-zero value iff stream FP is not opened write-only or
append-only. */
extern int __freadable (FILE *__fp);
/* Return non-zero value iff stream FP is not opened read-only. */
extern int __fwritable (FILE *__fp);
/* Return non-zero value iff the stream FP is line-buffered. */
extern int __flbf (FILE *__fp);
/* Discard all pending buffered I/O on the stream FP. */
extern void __fpurge (FILE *__fp);
/* Return amount of output in bytes pending on a stream FP. */
extern size_t __fpending (FILE *__fp);
/* Flush all line-buffered files. */
extern void _flushlbf (void);
/* Set locking statis of stream FP to TYPE. */
extern int __fsetlocking (FILE *__fp, int __type);
__END_DECLS
#endif /* stdio_ext.h */

View File

@ -1,10 +1,3 @@
2000-09-01 Ulrich Drepper <drepper@redhat.com>
* lockfile.c (__flockfile): If _IO_USER_LOCK bit is set don't do
anything.
(__funlockfile): Likewise.
(__ftrylockfile): If _IO_USER_LOCK bit is set return always 0.
2000-08-30 Ulrich Drepper <drepper@redhat.com>
* manager.c (pthread_allocate_stack): Clear descriptor only if not

View File

@ -29,8 +29,7 @@ void
__flockfile (FILE *stream)
{
#ifdef USE_IN_LIBIO
if ((stream->_flags & _IO_USER_LOCK) == 0)
__pthread_mutex_lock (stream->_lock);
__pthread_mutex_lock (stream->_lock);
#else
#endif
}
@ -45,8 +44,7 @@ void
__funlockfile (FILE *stream)
{
#ifdef USE_IN_LIBIO
if ((stream->_flags & _IO_USER_LOCK) == 0)
__pthread_mutex_unlock (stream->_lock);
__pthread_mutex_unlock (stream->_lock);
#else
#endif
}
@ -61,10 +59,7 @@ int
__ftrylockfile (FILE *stream)
{
#ifdef USE_IN_LIBIO
if ((stream->_flags & _IO_USER_LOCK) == 0)
return __pthread_mutex_trylock (stream->_lock);
else
return 0;
return __pthread_mutex_trylock (stream->_lock);
#else
#endif
}