delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2002/05/29/15:55:33.1

Date: Wed, 29 May 2002 20:46:23 +0100
From: "Richard Dawe" <rich AT phekda DOT freeserve DOT co DOT uk>
Sender: rich AT phekda DOT freeserve DOT co DOT uk
To: djgpp-workers AT delorie DOT com
X-Mailer: Emacs 21.2.50 (via feedmail 8.3.emacs20_6 I) and Blat ver 1.8.6
Subject: Patches for building with gcc 3.1 - *printf(), confstr() chunk
Message-Id: <E17D9JB-0000RB-00@phekda.freeserve.co.uk>
Reply-To: djgpp-workers AT delorie DOT com

Hello.

Please find below some fixes to *printf() with regards to passing
va_lists to _doprnt(). I don't think there's anything controversial
here.

I've also included what I think we should do to confstr().
I don't think we need to call snprintf() just to truncate a string.

If there are no objections, I'd like to commit these patches.

Thanks, bye, Rich =]

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 -3 -r1.1 fprintf.c
--- src/libc/ansi/stdio/fprintf.c	1994/12/26 20:34:46	1.1
+++ src/libc/ansi/stdio/fprintf.c	2002/05/26 17:27:16
@@ -1,19 +1,24 @@
+/* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
+#include <stdarg.h>
 #include <stdio.h>
 #include <libc/file.h>
 
 int
 fprintf(register FILE *iop, const char *fmt, ...)
 {
+  va_list args;
   int len;
   char localbuf[BUFSIZ];
 
+  va_start(args, fmt);
+
   if (iop->_flag & _IONBF)
   {
     iop->_flag &= ~_IONBF;
     iop->_ptr = iop->_base = localbuf;
     iop->_bufsiz = BUFSIZ;
-    len = _doprnt(fmt, (&fmt)+1, iop);
+    len = _doprnt(fmt, args, iop);
     fflush(iop);
     iop->_flag |= _IONBF;
     iop->_base = NULL;
@@ -21,6 +26,9 @@ fprintf(register FILE *iop, const char *
     iop->_cnt = 0;
   }
   else
-    len = _doprnt(fmt, (&fmt)+1, iop);
+    len = _doprnt(fmt, args, iop);
+
+  va_end(args);
+
   return ferror(iop) ? EOF : len;
 }
Index: src/libc/ansi/stdio/printf.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/printf.c,v
retrieving revision 1.2
diff -p -u -3 -r1.2 printf.c
--- src/libc/ansi/stdio/printf.c	1998/01/01 23:05:02	1.2
+++ src/libc/ansi/stdio/printf.c	2002/05/26 17:27:19
@@ -1,14 +1,19 @@
+/* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
+#include <stdarg.h>
 #include <stdio.h>
 #include <libc/file.h>
 
 int
 printf(const char *fmt, ...)
 {
+  va_list args;
   int len;
 
-  len = _doprnt(fmt, (&fmt)+1, stdout);
+  va_start(args, fmt);
+  len = _doprnt(fmt, args, stdout);
+  va_end(args);
 
   /* People were confused when printf() didn't flush stdout,
      so we'll do it to reduce confusion */
Index: src/libc/ansi/stdio/sprintf.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdio/sprintf.c,v
retrieving revision 1.3
diff -p -u -3 -r1.3 sprintf.c
--- src/libc/ansi/stdio/sprintf.c	1999/08/04 19:58:22	1.3
+++ src/libc/ansi/stdio/sprintf.c	2002/05/26 17:27:31
@@ -1,5 +1,7 @@
+/* Copyright (C) 2002 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
 /* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
+#include <stdarg.h>
 #include <stdio.h>
 #include <limits.h>
 #include <libc/file.h>
@@ -7,13 +9,18 @@
 int
 sprintf(char *str, const char *fmt, ...)
 {
+  va_list args;
   FILE _strbuf;
   int len;
 
   _strbuf._flag = _IOWRT|_IOSTRG|_IONTERM;
   _strbuf._ptr = str;
   _strbuf._cnt = INT_MAX;
-  len = _doprnt(fmt, &(fmt)+1, &_strbuf);
+
+  va_start(args, fmt);
+  len = _doprnt(fmt, args, &_strbuf);
+  va_end(args);
+
   *_strbuf._ptr = 0;
   return len;
 }
Index: src/libc/posix/unistd/confstr.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/posix/unistd/confstr.c,v
retrieving revision 1.3
diff -p -u -3 -r1.3 confstr.c
--- src/libc/posix/unistd/confstr.c	2001/06/19 17:04:19	1.3
+++ src/libc/posix/unistd/confstr.c	2002/05/26 17:28:40
@@ -43,7 +43,7 @@ confstr(int name, char *buf, size_t len)
     case _CS_POSIX_V6_ILP32_OFF32_LDFLAGS:
     case _CS_POSIX_V6_ILP32_OFF32_LIBS:
     {
-      out_len = snprintf(buf, len, "");
+      buf[0] = 0;
       ++out_len;
       break;
     }

- Raw text -


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