summaryrefslogtreecommitdiff
path: root/libio
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2004-11-10 09:02:52 +0000
committerJakub Jelinek <jakub@redhat.com>2004-11-10 09:02:52 +0000
commit3504bb650f48534549bbd0313dc15fa71455e302 (patch)
tree742dd9cbcee1147fb36bcc02816bec415544597e /libio
parentcbf4bcd2b3d53de274548dbf4c28017d1f07d5b2 (diff)
Updated to fedora-glibc-20041110T0839
Diffstat (limited to 'libio')
-rw-r--r--libio/Makefile2
-rw-r--r--libio/bug-ungetc3.c94
-rw-r--r--libio/fileops.c15
-rw-r--r--libio/ftello.c5
-rw-r--r--libio/ftello64.c5
-rw-r--r--libio/iofgetpos.c5
-rw-r--r--libio/iofgetpos64.c5
-rw-r--r--libio/ioftell.c7
-rw-r--r--libio/oldiofgetpos.c2
-rw-r--r--libio/oldiofgetpos64.c2
10 files changed, 126 insertions, 16 deletions
diff --git a/libio/Makefile b/libio/Makefile
index a9384b55a9..1d7611d252 100644
--- a/libio/Makefile
+++ b/libio/Makefile
@@ -54,7 +54,7 @@ tests = tst_swprintf tst_wprintf tst_swscanf tst_wscanf tst_getwc tst_putwc \
tst-freopen bug-rewind bug-rewind2 bug-ungetc bug-fseek \
tst-mmap-eofsync tst-mmap-fflushsync bug-mmap-fflush \
tst-mmap2-eofsync tst-mmap-offend bug-fopena+ bug-wfflush \
- bug-ungetc2 bug-ftell
+ bug-ungetc2 bug-ftell bug-ungetc3
test-srcs = test-freopen
all: # Make this the default target; it will be defined in Rules.
diff --git a/libio/bug-ungetc3.c b/libio/bug-ungetc3.c
new file mode 100644
index 0000000000..0c83c1161e
--- /dev/null
+++ b/libio/bug-ungetc3.c
@@ -0,0 +1,94 @@
+/* Test program for ungetc/ftell interaction bug. */
+
+#include <stdio.h>
+
+static void do_prepare (void);
+#define PREPARE(argc, argv) do_prepare ()
+static int do_test (void);
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
+
+static const char pattern[] = "12345";
+static char *temp_file;
+
+static void
+do_prepare (void)
+{
+ int fd = create_temp_file ("bug-ungetc.", &temp_file);
+ if (fd == -1)
+ {
+ printf ("cannot create temporary file: %m\n");
+ exit (1);
+ }
+ write (fd, pattern, sizeof (pattern));
+ close (fd);
+}
+
+static int
+do_one_test (int mode)
+{
+ FILE *f;
+
+ f = fopen (temp_file, "r");
+ if (f == NULL)
+ {
+ printf ("could not open temporary file: %m\n");
+ return 1;
+ }
+
+ if (mode == 1 && ftell (f) != 0)
+ {
+ printf ("first ftell returned wrong position %ld\n", ftell (f));
+ return 1;
+ }
+
+ if (fgetc (f) != '1' || fgetc (f) != '2')
+ {
+ puts ("fgetc failed");
+ return 1;
+ }
+
+ if (mode == 2 && ftell (f) != 2)
+ {
+ printf ("second ftell returned wrong position %ld\n", ftell (f));
+ return 1;
+ }
+
+ if (ungetc ('6', f) != '6')
+ {
+ puts ("ungetc failed");
+ return 1;
+ }
+
+ if (ftell (f) != 1)
+ {
+ printf ("third ftell returned wrong position %ld\n", ftell (f));
+ return 1;
+ }
+
+ if (fgetc (f) != '6')
+ {
+ puts ("fgetc failed");
+ return 1;
+ }
+
+ if (ftell (f) != 2)
+ {
+ printf ("fourth ftell returned wrong position %ld\n", ftell (f));
+ return 1;
+ }
+
+ fclose (f);
+
+ return 0;
+}
+
+static int
+do_test (void)
+{
+ int mode;
+ for (mode = 0; mode <= 2; mode++)
+ if (do_one_test (mode))
+ return 1;
+ return 0;
+}
diff --git a/libio/fileops.c b/libio/fileops.c
index 7d90cbaa2d..2d787d296f 100644
--- a/libio/fileops.c
+++ b/libio/fileops.c
@@ -635,7 +635,7 @@ mmap_remap_check (_IO_FILE *fp)
{
/* The file added some pages. We need to remap it. */
void *p;
-#if defined __linux__ /* XXX */
+#ifdef _G_HAVE_MREMAP
p = __mremap (fp->_IO_buf_base, ROUNDED (fp->_IO_buf_end
- fp->_IO_buf_base),
ROUNDED (st.st_size), MREMAP_MAYMOVE);
@@ -989,7 +989,18 @@ _IO_new_file_seekoff (fp, offset, dir, mode)
/* Adjust for read-ahead (bytes is buffer). */
offset -= fp->_IO_read_end - fp->_IO_read_ptr;
if (fp->_offset == _IO_pos_BAD)
- goto dumb;
+ {
+ if (mode != 0)
+ goto dumb;
+ else
+ {
+ result = _IO_SYSSEEK (fp, 0, dir);
+ if (result == EOF)
+ return result;
+
+ fp->_offset = result;
+ }
+ }
/* Make offset absolute, assuming current pointer is file_ptr(). */
offset += fp->_offset;
if (offset < 0)
diff --git a/libio/ftello.c b/libio/ftello.c
index 4975a0bd73..e58daacad4 100644
--- a/libio/ftello.c
+++ b/libio/ftello.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 1993, 1995-2001, 2002, 2003 Free Software Foundation, Inc.
+/* Copyright (C) 1993, 1995-2001, 2002, 2003, 2004
+ 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
@@ -39,7 +40,7 @@ ftello (fp)
CHECK_FILE (fp, -1L);
_IO_acquire_lock (fp);
pos = _IO_seekoff_unlocked (fp, 0, _IO_seek_cur, 0);
- if (_IO_in_backup (fp))
+ if (_IO_in_backup (fp) && pos != _IO_pos_BAD)
{
if (fp->_mode <= 0)
pos -= fp->_IO_save_end - fp->_IO_save_base;
diff --git a/libio/ftello64.c b/libio/ftello64.c
index 0275c0ca35..d39fc2d1b2 100644
--- a/libio/ftello64.c
+++ b/libio/ftello64.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 1993, 1995-2001, 2002, 2003 Free Software Foundation, Inc.
+/* Copyright (C) 1993, 1995-2001, 2002, 2003, 2004
+ 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,7 +41,7 @@ ftello64 (fp)
CHECK_FILE (fp, -1L);
_IO_acquire_lock (fp);
pos = _IO_seekoff_unlocked (fp, 0, _IO_seek_cur, 0);
- if (_IO_in_backup (fp))
+ if (_IO_in_backup (fp) && pos != _IO_pos_BAD)
{
if (fp->_mode <= 0)
pos -= fp->_IO_save_end - fp->_IO_save_base;
diff --git a/libio/iofgetpos.c b/libio/iofgetpos.c
index aff39bbed4..8b7ef9f34d 100644
--- a/libio/iofgetpos.c
+++ b/libio/iofgetpos.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 1993, 1995-2001, 2002, 2003 Free Software Foundation, Inc.
+/* Copyright (C) 1993, 1995-2001, 2002, 2003, 2004
+ 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,7 +41,7 @@ _IO_new_fgetpos (fp, posp)
CHECK_FILE (fp, EOF);
_IO_acquire_lock (fp);
pos = _IO_seekoff_unlocked (fp, 0, _IO_seek_cur, 0);
- if (_IO_in_backup (fp))
+ if (_IO_in_backup (fp) && pos != _IO_pos_BAD)
{
if (fp->_mode <= 0)
pos -= fp->_IO_save_end - fp->_IO_save_base;
diff --git a/libio/iofgetpos64.c b/libio/iofgetpos64.c
index be224ca103..10446857e7 100644
--- a/libio/iofgetpos64.c
+++ b/libio/iofgetpos64.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 1993, 1995-2001, 2002, 2003 Free Software Foundation, Inc.
+/* Copyright (C) 1993, 1995-2001, 2002, 2003, 2004
+ 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
@@ -41,7 +42,7 @@ _IO_new_fgetpos64 (fp, posp)
CHECK_FILE (fp, EOF);
_IO_acquire_lock (fp);
pos = _IO_seekoff_unlocked (fp, 0, _IO_seek_cur, 0);
- if (_IO_in_backup (fp))
+ if (_IO_in_backup (fp) && pos != _IO_pos_BAD)
{
if (fp->_mode <= 0)
pos -= fp->_IO_save_end - fp->_IO_save_base;
diff --git a/libio/ioftell.c b/libio/ioftell.c
index b991ef69ea..03e5f28404 100644
--- a/libio/ioftell.c
+++ b/libio/ioftell.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 1993,1995-2000,2001,2002,2003 Free Software Foundation, Inc.
+/* Copyright (C) 1993, 1995-2000, 2001, 2002, 2003, 2004
+ 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
@@ -38,7 +39,7 @@ _IO_ftell (fp)
CHECK_FILE (fp, -1L);
_IO_acquire_lock (fp);
pos = _IO_seekoff_unlocked (fp, 0, _IO_seek_cur, 0);
- if (_IO_in_backup (fp))
+ if (_IO_in_backup (fp) && pos != _IO_pos_BAD)
{
if (_IO_vtable_offset (fp) != 0 || fp->_mode <= 0)
pos -= fp->_IO_save_end - fp->_IO_save_base;
@@ -52,7 +53,7 @@ _IO_ftell (fp)
#endif
return -1L;
}
- if ((_IO_off64_t) (off_t) pos != pos)
+ if ((_IO_off64_t) (long int) pos != pos)
{
#ifdef EOVERFLOW
__set_errno (EOVERFLOW);
diff --git a/libio/oldiofgetpos.c b/libio/oldiofgetpos.c
index fbac21bdd4..6b14e1970f 100644
--- a/libio/oldiofgetpos.c
+++ b/libio/oldiofgetpos.c
@@ -42,7 +42,7 @@ _IO_old_fgetpos (fp, posp)
CHECK_FILE (fp, EOF);
_IO_acquire_lock (fp);
pos = _IO_seekoff_unlocked (fp, 0, _IO_seek_cur, 0);
- if (_IO_in_backup (fp))
+ if (_IO_in_backup (fp) && pos != _IO_pos_BAD)
pos -= fp->_IO_save_end - fp->_IO_save_base;
_IO_release_lock (fp);
if (pos == _IO_pos_BAD)
diff --git a/libio/oldiofgetpos64.c b/libio/oldiofgetpos64.c
index 996ad2075b..1c1adb3884 100644
--- a/libio/oldiofgetpos64.c
+++ b/libio/oldiofgetpos64.c
@@ -43,7 +43,7 @@ _IO_old_fgetpos64 (fp, posp)
CHECK_FILE (fp, EOF);
_IO_acquire_lock (fp);
pos = _IO_seekoff_unlocked (fp, 0, _IO_seek_cur, 0);
- if (_IO_in_backup (fp))
+ if (_IO_in_backup (fp) && pos != _IO_pos_BAD)
pos -= fp->_IO_save_end - fp->_IO_save_base;
_IO_release_lock (fp);
if (pos == _IO_pos_BAD)