You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Alexei Kosut <ak...@nueva.pvt.k12.ca.us> on 1997/01/18 22:14:56 UTC

util_snprintf.c

Please... move the #include <stdlib.h> and #include <math.h> to *above*
the redefinition of ecvt, fcvt and gcvt. If this is not done, this
file WILL NOT COMPILE on any OS that does not use the exact same
prototype as Apache for these functions. Which defeats the point of
having our own function names (though I don't see why all those
underscores are neccessary).

Thanks.

-- 
________________________________________________________________________
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/


Re: util_snprintf.c

Posted by Dean Gaudet <dg...@arctic.org>.
On Sat, 18 Jan 1997, Alexei Kosut wrote:

> Please... move the #include <stdlib.h> and #include <math.h> to *above*
> the redefinition of ecvt, fcvt and gcvt. If this is not done, this
> file WILL NOT COMPILE on any OS that does not use the exact same
> prototype as Apache for these functions. Which defeats the point of
> having our own function names (though I don't see why all those
> underscores are neccessary).

Actually __ are reserved by ansi/posix for the compiler and os.  I also
ran into a bunch of problems with the function prototypes littered around
the code.  I think it's more portable if we define ap_?cvt as our
functions and use #defines for them when -DHAVE_CVT.

I probably wasn't watching when discussion for this went around :)

Anyhow, here's my for the above.

Dean

Index: util_snprintf.c
===================================================================
RCS file: /export/home/cvs/apache/src/util_snprintf.c,v
retrieving revision 1.1
diff -u -r1.1 util_snprintf.c
--- util_snprintf.c	1997/01/18 19:17:21	1.1
+++ util_snprintf.c	1997/01/18 22:02:41
@@ -63,26 +63,23 @@
 #include <ctype.h>
 #include <sys/types.h>
 #include <stdarg.h>
+#include <string.h>
+#include <stdlib.h>
+#include <math.h>
 
-#ifndef HAVE_CVT	/* We should really use this anyway */
-
-/*
- * Take care of possible prototyping conflicts
- */
-#define ecvt	__ap_ecvt
-#define fcvt	__ap_fcvt
-#define gcvt	__ap_gcvt
+#ifdef HAVE_CVT
+#define ap_ecvt ecvt
+#define ap_fcvt fcvt
+#define ap_gcvt gcvt
+#else
 
 /*
  * cvt.c - IEEE floating point formatting routines for FreeBSD
  * from GNU libc-4.6.27
  */
 
-#include <stdlib.h>
-#include <math.h>
-
 /*
- *    __ap_ecvt converts to decimal
+ *    ap_ecvt converts to decimal
  *      the number of digits is specified by ndigit
  *      decpt is set to the position of the decimal point
  *      sign is set to 0 for positive, 1 for negative
@@ -91,7 +88,7 @@
 #define	NDIG	80
 
 static char *
-     __ap_cvt(double arg, int ndigits, int *decpt, int *sign, int eflag)
+     ap_cvt(double arg, int ndigits, int *decpt, int *sign, int eflag)
 {
     register int r2;
     double fi, fj;
@@ -166,30 +163,30 @@
 }
 
 static char *
-     __ap_ecvt(double arg, int ndigits, int *decpt, int *sign)
+     ap_ecvt(double arg, int ndigits, int *decpt, int *sign)
 {
-    return (__ap_cvt(arg, ndigits, decpt, sign, 1));
+    return (ap_cvt(arg, ndigits, decpt, sign, 1));
 }
 
 static char *
-     __ap_fcvt(double arg, int ndigits, int *decpt, int *sign)
+     ap_fcvt(double arg, int ndigits, int *decpt, int *sign)
 {
-    return (__ap_cvt(arg, ndigits, decpt, sign, 0));
+    return (ap_cvt(arg, ndigits, decpt, sign, 0));
 }
 
 /*
- * __ap_gcvt  - Floating output conversion to
+ * ap_gcvt  - Floating output conversion to
  * minimal length string
  */
 
 static char *
-     __ap_gcvt(double number, int ndigit, char *buf)
+     ap_gcvt(double number, int ndigit, char *buf)
 {
     int sign, decpt;
     register char *p1, *p2;
     register i;
 
-    p1 = __ap_ecvt(number, ndigit, &decpt, &sign);
+    p1 = ap_ecvt(number, ndigit, &decpt, &sign);
     p2 = buf;
     if (sign)
 	*p2++ = '-';
@@ -274,12 +271,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
@@ -417,13 +414,11 @@
     register char *s = buf;
     register char *p;
     int decimal_point;
-    char *ecvt(double, int, int *, int *), *fcvt(double, int, int *, int *);
-    char *strcpy(char *, const char *);
 
     if (format == 'f')
-	p = fcvt(num, precision, &decimal_point, is_negative);
+	p = ap_fcvt(num, precision, &decimal_point, is_negative);
     else			/* either e or E format */
-	p = ecvt(num, precision + 1, &decimal_point, is_negative);
+	p = ap_ecvt(num, precision + 1, &decimal_point, is_negative);
 
     /*
      * Check for Infinity and NaN
@@ -529,7 +524,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;
@@ -567,11 +562,6 @@
     boolean_e adjust_width;
     bool_int is_negative;
 
-    char *gcvt(double, int, char *);
-    char *strchr(const char *, int);
-    int isascii(int);
-
-
     sp = odp->nextb;
     bep = odp->buf_end;
 
@@ -776,7 +766,7 @@
 		/*
 		 * * We use &num_buf[ 1 ], so that we have room for the sign
 		 */
-		s = gcvt(va_arg(ap, double), precision, &num_buf[1]);
+		s = ap_gcvt(va_arg(ap, double), precision, &num_buf[1]);
 		if (*s == '-')
 		    prefix_char = *s++;
 		else if (print_sign)
@@ -848,7 +838,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.
@@ -901,7 +891,7 @@
 static void strx_printv(int *ccp, char *buf, size_t len, const char *format,
 			va_list ap)
 {
-    __buffy od;
+    buffy od;
     int cc;
 
     /*
@@ -915,7 +905,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)