aboutsummaryrefslogtreecommitdiff
path: root/libio
diff options
context:
space:
mode:
Diffstat (limited to 'libio')
-rw-r--r--libio/Makefile6
-rw-r--r--libio/Versions4
-rw-r--r--libio/__fbufsize.c35
-rw-r--r--libio/__flbf.c32
-rw-r--r--libio/__fpending.c35
-rw-r--r--libio/__fpurge.c49
-rw-r--r--libio/__freadable.c32
-rw-r--r--libio/__freading.c33
-rw-r--r--libio/__fsetlocking.c42
-rw-r--r--libio/__fwritable.c32
-rw-r--r--libio/__fwriting.c32
-rw-r--r--libio/genops.c3
-rw-r--r--libio/libio.h1
-rw-r--r--libio/stdio_ext.h86
14 files changed, 421 insertions, 1 deletions
diff --git a/libio/Makefile b/libio/Makefile
index 4208de6aff..4bbdc31281 100644
--- a/libio/Makefile
+++ b/libio/Makefile
@@ -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 \
diff --git a/libio/Versions b/libio/Versions
index 8c1f35d57f..ea043064ff 100644
--- a/libio/Versions
+++ b/libio/Versions
@@ -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;
diff --git a/libio/__fbufsize.c b/libio/__fbufsize.c
new file mode 100644
index 0000000000..0791e8444f
--- /dev/null
+++ b/libio/__fbufsize.c
@@ -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;
+}
diff --git a/libio/__flbf.c b/libio/__flbf.c
new file mode 100644
index 0000000000..017b813b3d
--- /dev/null
+++ b/libio/__flbf.c
@@ -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;
+}
diff --git a/libio/__fpending.c b/libio/__fpending.c
new file mode 100644
index 0000000000..7005bc5efb
--- /dev/null
+++ b/libio/__fpending.c
@@ -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;
+}
diff --git a/libio/__fpurge.c b/libio/__fpurge.c
new file mode 100644
index 0000000000..dd83d9f520
--- /dev/null
+++ b/libio/__fpurge.c
@@ -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;
+ }
+}
diff --git a/libio/__freadable.c b/libio/__freadable.c
new file mode 100644
index 0000000000..79bdaa0ca9
--- /dev/null
+++ b/libio/__freadable.c
@@ -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;
+}
diff --git a/libio/__freading.c b/libio/__freading.c
new file mode 100644
index 0000000000..7206645ad8
--- /dev/null
+++ b/libio/__freading.c
@@ -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);
+}
diff --git a/libio/__fsetlocking.c b/libio/__fsetlocking.c
new file mode 100644
index 0000000000..d5d94e04ba
--- /dev/null
+++ b/libio/__fsetlocking.c
@@ -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;
+}
diff --git a/libio/__fwritable.c b/libio/__fwritable.c
new file mode 100644
index 0000000000..932b497caf
--- /dev/null
+++ b/libio/__fwritable.c
@@ -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;
+}
diff --git a/libio/__fwriting.c b/libio/__fwriting.c
new file mode 100644
index 0000000000..2cd9307e9e
--- /dev/null
+++ b/libio/__fwriting.c
@@ -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);
+}
diff --git a/libio/genops.c b/libio/genops.c
index 768996f8b4..42419bf508 100644
--- a/libio/genops.c
+++ b/libio/genops.c
@@ -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));
diff --git a/libio/libio.h b/libio/libio.h
index d26a5e5979..e662f48918 100644
--- a/libio/libio.h
+++ b/libio/libio.h
@@ -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
diff --git a/libio/stdio_ext.h b/libio/stdio_ext.h
new file mode 100644
index 0000000000..69d6a0ff2b
--- /dev/null
+++ b/libio/stdio_ext.h
@@ -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 */