www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2000/09/14/14:51:43

From: Martin Str|mberg <ams AT ludd DOT luth DOT se>
Message-Id: <200009141851.UAA02531@father.ludd.luth.se>
Subject: Bug 000323
To: djgpp-workers AT delorie DOT com (DJGPP-WORKERS)
Date: Thu, 14 Sep 2000 20:51:24 +0200 (MET DST)
X-Mailer: ELM [version 2.4ME+ PL54 (25)]
MIME-Version: 1.0
Reply-To: djgpp-workers AT delorie DOT com

Here's patch (pasted so might not apply cleanly) that fixes bug 000323.

It's mostly for discussion. Am I overlooking/overdoing something?
(I know wc204.txi entry is missing.)


Right,

						MartinS

Index: include/libc/file.h
===================================================================
RCS file: /cvs/djgpp/djgpp/include/libc/file.h,v
retrieving revision 1.8
diff -p -u -r1.8 file.h
--- file.h      1999/06/27 16:27:44     1.8
+++ file.h      2000/09/14 18:46:13
@@ -93,6 +93,15 @@ static __inline__ int __putc(const int x
     else
       (p)->_flag |= _IONTERM;
   }
+
+  if( (p)->_flag & _IOAPPEND )
+  {
+    if( fseek((p), 0, SEEK_END) )
+    {
+      return 0;
+    }
+  }
+
   if(x=='\n' && __is_text_file(p))
     __putc_raw('\r',p);
   return __putc_raw(x,p);
Index: src/libc/ansi/stdio/fopen.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/fopen.c,v
retrieving revision 1.1
diff -p -u -r1.1 fopen.c
--- fopen.c     1995/08/23 07:49:24     1.1
+++ fopen.c     2000/09/14 18:46:14
@@ -55,8 +55,8 @@ fopen(const char *file, const char *mode
   if (fd < 0)
     return NULL;

-  if (*mode == 'a')
-    lseek(fd, 0, SEEK_END);
+  /*  if (*mode == 'a')
+    lseek(fd, 0, SEEK_END); */

   f->_cnt = 0;
   f->_file = fd;
@@ -67,6 +67,11 @@ fopen(const char *file, const char *mode
     f->_flag = _IOREAD;
   else
     f->_flag = _IOWRT;
+
+  if (*mode == 'a')
+  {
+    f->_flag |= _IOAPPEND;
+  }

   f->_base = f->_ptr = NULL;
   return f;
Index: src/libc/ansi/stdio/fprintf.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/fprintf.c,v
retrieving revision 1.1
diff -p -u -r1.1 fprintf.c
--- fprintf.c   1994/12/26 20:34:46     1.1
+++ fprintf.c   2000/09/14 18:46:14
@@ -8,6 +8,14 @@ fprintf(register FILE *iop, const char *
   int len;
   char localbuf[BUFSIZ];

+  if( iop->_flag & _IOAPPEND )
+  {
+    if( fseek(iop, 0, SEEK_END) )
+    {
+      return 0;
+    }
+  }
+
   if (iop->_flag & _IONBF)
   {
     iop->_flag &= ~_IONBF;
Index: src/libc/ansi/stdio/freopen.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/freopen.c,v
retrieving revision 1.3
diff -p -u -r1.3 freopen.c
--- freopen.c   1999/06/03 17:27:33     1.3
+++ freopen.c   2000/09/14 18:46:14
@@ -49,8 +49,8 @@ freopen(const char *file, const char *mo
   if (fd < 0)
     return NULL;

-  if (*mode == 'a')
-    lseek(fd, 0, SEEK_END);
+  /*  if (*mode == 'a')
+    lseek(fd, 0, SEEK_END);*/

   f->_cnt = 0;
   f->_file = fd;
@@ -61,6 +61,11 @@ freopen(const char *file, const char *mo
     f->_flag = _IOREAD;
   else
     f->_flag = _IOWRT;
+
+  if (*mode == 'a')
+  {
+    f->_flag |= _IOAPPEND;
+  }

   f->_base = f->_ptr = NULL;
   return f;
Index: src/libc/ansi/stdio/fwrite.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/fwrite.c,v
retrieving revision 1.5
diff -p -u -r1.5 fwrite.c
--- fwrite.c    2000/06/28 08:20:55     1.5
+++ fwrite.c    2000/09/14 18:46:15
@@ -24,6 +24,14 @@ fwrite(const void *vptr, size_t size, si
       f->_flag |= _IONTERM;
   }

+  if( f->_flag & _IOAPPEND )
+  {
+    if( fseek(f, 0, SEEK_END) )
+    {
+      return 0;
+    }
+  }
+
   s = size * count;
   if(!__is_text_file(f))
   {
Index: tests/libc/ansi/stdio/append.c
===================================================================
RCS file: /cvs/djgpp/djgpp/tests/libc/ansi/stdio/append.c,v
retrieving revision 1.1
diff -p -u -r1.1 append.c
--- append.c    1995/08/27 20:55:10     1.1
+++ append.c    2000/09/14 18:46:28
@@ -2,6 +2,8 @@
 #include <sys/types.h>
 #include <sys/stat.h>

+#define FILE_NAME "append.dat"
+
 int
 main(void)
 {
@@ -9,19 +11,29 @@ main(void)
   struct stat s;
   size_t len;

-  f = fopen("append.dat", "w");
+  f = fopen(FILE_NAME, "w");
   fprintf(f, "hello, there\n");
   fclose(f);
-  stat("append.dat", &s);
+  stat(FILE_NAME, &s);
   len = s.st_size;

-  f = fopen("append.dat", "a");
+  f = fopen(FILE_NAME, "a");
   fprintf(f, "hello, there\n");
   fclose(f);
-  stat("append.dat", &s);
+  stat(FILE_NAME, &s);
   if (s.st_size != len * 2)
+  {
+    printf("wrong size 1!\n");
+  }
+
+  f = fopen(FILE_NAME, "a+");
+  fseek(f, 0, SEEK_SET);
+  fprintf(f, "hello, there\n");
+  fclose(f);
+  stat(FILE_NAME, &s);
+  if (s.st_size != len * 3)
   {
-    printf("wrong size!\n");
+    printf("wrong size 2!\n");
   }

   return 0;

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019