Update.
authorUlrich Drepper <drepper@redhat.com>
Fri, 1 Sep 2000 08:56:06 +0000 (08:56 +0000)
committerUlrich Drepper <drepper@redhat.com>
Fri, 1 Sep 2000 08:56:06 +0000 (08:56 +0000)
* 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.

17 files changed:
ChangeLog
libio/Makefile
libio/Versions
libio/__fbufsize.c [new file with mode: 0644]
libio/__flbf.c [new file with mode: 0644]
libio/__fpending.c [new file with mode: 0644]
libio/__fpurge.c [new file with mode: 0644]
libio/__freadable.c [new file with mode: 0644]
libio/__freading.c [new file with mode: 0644]
libio/__fsetlocking.c [new file with mode: 0644]
libio/__fwritable.c [new file with mode: 0644]
libio/__fwriting.c [new file with mode: 0644]
libio/genops.c
libio/libio.h
libio/stdio_ext.h [new file with mode: 0644]
linuxthreads/ChangeLog
linuxthreads/lockfile.c

index fa98f85..cf36d9b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
 
index 4208de6..4bbdc31 100644 (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   \
index 8c1f35d..ea04306 100644 (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;
diff --git a/libio/__fbufsize.c b/libio/__fbufsize.c
new file mode 100644 (file)
index 0000000..0791e84
--- /dev/null
@@ -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 (file)
index 0000000..017b813
--- /dev/null
@@ -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 (file)
index 0000000..7005bc5
--- /dev/null
@@ -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 (file)
index 0000000..dd83d9f
--- /dev/null
@@ -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 (file)
index 0000000..79bdaa0
--- /dev/null
@@ -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 (file)
index 0000000..7206645
--- /dev/null
@@ -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 (file)
index 0000000..d5d94e0
--- /dev/null
@@ -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 (file)
index 0000000..932b497
--- /dev/null
@@ -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 (file)
index 0000000..2cd9307
--- /dev/null
@@ -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);
+}
index 768996f..42419bf 100644 (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));
 
index d26a5e5..e662f48 100644 (file)
 #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 (file)
index 0000000..69d6a0f
--- /dev/null
@@ -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 */
index 57bb848..e55344b 100644 (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
index a7836b8..0ef02f8 100644 (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
 }