You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Dean Gaudet <dg...@arctic.org> on 1997/01/19 22:29:49 UTC

[PATCH] Re: ap_snprintf()

On Sun, 19 Jan 1997, Randy Terbush wrote:
> I deleted your patch thinking that was something that Jim would
> have to comment on. However, I'm thinking that we should perhaps
> apply it to give this a proper test.

I redid it against the latest version in the repository.

These are just changes to improve portability.  Remove __ identifiers
since they're claimed by ansi/posix for the c library and system files. 
Remove any prototypes.  Fix #includes.  This compiles fine with -DHAVE_CVT
or without.

BTW, I'm running with the buffer patches too (except mod_fastcgi.c has
been seriously changed in the repository such that the buffer-len patches
don't patch against it at all), but using Linux's native snprintf. 

Dean

Index: util_snprintf.c
===================================================================
RCS file: /export/home/cvs/apache/src/util_snprintf.c,v
retrieving revision 1.2
diff -u -r1.2 util_snprintf.c
--- util_snprintf.c	1997/01/18 21:28:15	1.2
+++ util_snprintf.c	1997/01/19 21:26:26
@@ -63,6 +63,9 @@
 #include <ctype.h>
 #include <sys/types.h>
 #include <stdarg.h>
+#include <string.h>
+#include <stdlib.h>
+#include <math.h>
 
 #ifdef HAVE_CVT
 
@@ -77,9 +80,6 @@
  * from GNU libc-4.6.27
  */
 
-#include <stdlib.h>
-#include <math.h>
-
 /*
  *    ap_ecvt converts to decimal
  *      the number of digits is specified by ndigit
@@ -273,12 +273,12 @@
 /*
  * Descriptor for buffer area
  */
-struct __buf_area {
+struct buf_area {
     char *buf_end;
     char *nextb;		/* pointer to next byte to read/write   */
 };
 
-typedef struct __buf_area __buffy;
+typedef struct buf_area buffy;
 
 /*
  * The INS_CHAR macro inserts a character in the buffer and writes
@@ -416,8 +416,6 @@
     register char *s = buf;
     register char *p;
     int decimal_point;
-    extern char *ap_ecvt(), *ap_fcvt();
-    char *strcpy(char *, const char *);
 
     if (format == 'f')
 	p = ap_fcvt(num, precision, &decimal_point, is_negative);
@@ -528,7 +526,7 @@
 /*
  * Do format conversion placing the output in buffer
  */
-static int __format_converter(register __buffy * odp, const char *fmt,
+static int format_converter(register buffy * odp, const char *fmt,
 			      va_list ap)
 {
     register char *sp;
@@ -566,11 +564,6 @@
     boolean_e adjust_width;
     bool_int is_negative;
 
-    extern char *ap_gcvt();
-    char *strchr(const char *, int);
-    int isascii(int);
-
-
     sp = odp->nextb;
     bep = odp->buf_end;
 
@@ -847,7 +840,7 @@
 		 * We print %<char> to help the user identify what
 		 * option is not understood.
 		 * This is also useful in case the user wants to pass
-		 * the output of __format_converter to another function
+		 * the output of format_converter to another function
 		 * that understands some other %<char> (like syslog).
 		 * Note that we can't point s inside fmt because the
 		 * unknown <char> could be preceded by width etc.
@@ -900,7 +893,7 @@
 static void strx_printv(int *ccp, char *buf, size_t len, const char *format,
 			va_list ap)
 {
-    __buffy od;
+    buffy od;
     int cc;
 
     /*
@@ -914,7 +907,7 @@
     /*
      * Do the conversion
      */
-    cc = __format_converter(&od, format, ap);
+    cc = format_converter(&od, format, ap);
     if (len == 0 || od.nextb <= od.buf_end)
 	*(od.nextb) = '\0';
     if (ccp)



Re: [PATCH] Re: ap_snprintf()

Posted by Dean Gaudet <dg...@arctic.org>.
On Sun, 19 Jan 1997, Alexei Kosut wrote:
> +1. Though it would be nice if you could give us context diffs.

D'ohh, what was I thinking.

Dean

Index: util_snprintf.c
===================================================================
RCS file: /export/home/cvs/apache/src/util_snprintf.c,v
retrieving revision 1.2
diff -c -3 -r1.2 util_snprintf.c
*** util_snprintf.c	1997/01/18 21:28:15	1.2
--- util_snprintf.c	1997/01/19 23:17:29
***************
*** 63,68 ****
--- 63,71 ----
  #include <ctype.h>
  #include <sys/types.h>
  #include <stdarg.h>
+ #include <string.h>
+ #include <stdlib.h>
+ #include <math.h>
  
  #ifdef HAVE_CVT
  
***************
*** 77,85 ****
   * from GNU libc-4.6.27
   */
  
- #include <stdlib.h>
- #include <math.h>
- 
  /*
   *    ap_ecvt converts to decimal
   *      the number of digits is specified by ndigit
--- 80,85 ----
***************
*** 273,284 ****
  /*
   * Descriptor for buffer area
   */
! struct __buf_area {
      char *buf_end;
      char *nextb;		/* pointer to next byte to read/write   */
  };
  
! typedef struct __buf_area __buffy;
  
  /*
   * The INS_CHAR macro inserts a character in the buffer and writes
--- 273,284 ----
  /*
   * Descriptor for buffer area
   */
! struct buf_area {
      char *buf_end;
      char *nextb;		/* pointer to next byte to read/write   */
  };
  
! typedef struct buf_area buffy;
  
  /*
   * The INS_CHAR macro inserts a character in the buffer and writes
***************
*** 416,423 ****
      register char *s = buf;
      register char *p;
      int decimal_point;
-     extern char *ap_ecvt(), *ap_fcvt();
-     char *strcpy(char *, const char *);
  
      if (format == 'f')
  	p = ap_fcvt(num, precision, &decimal_point, is_negative);
--- 416,421 ----
***************
*** 528,534 ****
  /*
   * Do format conversion placing the output in buffer
   */
! static int __format_converter(register __buffy * odp, const char *fmt,
  			      va_list ap)
  {
      register char *sp;
--- 526,532 ----
  /*
   * Do format conversion placing the output in buffer
   */
! static int format_converter(register buffy * odp, const char *fmt,
  			      va_list ap)
  {
      register char *sp;
***************
*** 566,576 ****
      boolean_e adjust_width;
      bool_int is_negative;
  
-     extern char *ap_gcvt();
-     char *strchr(const char *, int);
-     int isascii(int);
- 
- 
      sp = odp->nextb;
      bep = odp->buf_end;
  
--- 564,569 ----
***************
*** 847,853 ****
  		 * We print %<char> to help the user identify what
  		 * option is not understood.
  		 * This is also useful in case the user wants to pass
! 		 * the output of __format_converter to another function
  		 * that understands some other %<char> (like syslog).
  		 * Note that we can't point s inside fmt because the
  		 * unknown <char> could be preceded by width etc.
--- 840,846 ----
  		 * We print %<char> to help the user identify what
  		 * option is not understood.
  		 * This is also useful in case the user wants to pass
! 		 * the output of format_converter to another function
  		 * that understands some other %<char> (like syslog).
  		 * Note that we can't point s inside fmt because the
  		 * unknown <char> could be preceded by width etc.
***************
*** 900,906 ****
  static void strx_printv(int *ccp, char *buf, size_t len, const char *format,
  			va_list ap)
  {
!     __buffy od;
      int cc;
  
      /*
--- 893,899 ----
  static void strx_printv(int *ccp, char *buf, size_t len, const char *format,
  			va_list ap)
  {
!     buffy od;
      int cc;
  
      /*
***************
*** 914,920 ****
      /*
       * Do the conversion
       */
!     cc = __format_converter(&od, format, ap);
      if (len == 0 || od.nextb <= od.buf_end)
  	*(od.nextb) = '\0';
      if (ccp)
--- 907,913 ----
      /*
       * Do the conversion
       */
!     cc = format_converter(&od, format, ap);
      if (len == 0 || od.nextb <= od.buf_end)
  	*(od.nextb) = '\0';
      if (ccp)



Re: [PATCH] Re: ap_snprintf()

Posted by Alexei Kosut <ak...@nueva.pvt.k12.ca.us>.
On Sun, 19 Jan 1997, Dean Gaudet wrote:

> On Sun, 19 Jan 1997, Randy Terbush wrote:
> > I deleted your patch thinking that was something that Jim would
> > have to comment on. However, I'm thinking that we should perhaps
> > apply it to give this a proper test.
> 
> I redid it against the latest version in the repository.
> 
> These are just changes to improve portability.  Remove __ identifiers
> since they're claimed by ansi/posix for the c library and system files. 
> Remove any prototypes.  Fix #includes.  This compiles fine with -DHAVE_CVT
> or without.

+1. Though it would be nice if you could give us context diffs.

-- 
________________________________________________________________________
Alexei Kosut <ak...@nueva.pvt.k12.ca.us>      The Apache HTTP Server
URL: http://www.nueva.pvt.k12.ca.us/~akosut/   http://www.apache.org/