httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Trawick <trawi...@bellsouth.net>
Subject [PATCH] another lame ap_strerror() implementation
Date Tue, 18 Apr 2000 11:20:59 GMT
[I'm eager for comments, but in light of the fact that I'm in a hurry
to put something in the library which people can build on, please use
the string "showstopper" in any comments which describe issues you
think should be resolved before commit.  Disagreements with the
interface or with the file placement are good examples of things that
should be resolved prior to commit.]

Since the smart people don't have time to play with it, I thought I'd
try once again, leaving out any details which could possibly be
controversial.  Note that some of the uncontroversial details which I
omitted don't actually work today due to inconsistencies in error
handling in APR.  Frankly, about the only real details included are
the interface and where the code lives, but sadly that is an
improvement over the current situation.  IMHO, the important thing is
to put this in the library and get people to use it so that they'll be
so annoyed when they get a meaningless message that they'll go fix the
failing APR function (to return the right error code) or ap_strerror()
(to return the right string).

There is no OS/2 implementation because I can't figure out why there
is hardly anything in misc/os2.  I'll give the OS/2 folks a few days
after this is committed to give me instructions or post/commit a
solution themselves before I change Apache's http_log.c to use
ap_strerror().

There is no Win32 implementation enclosed, but there will be an
initial implementation when I commit.  At the moment, I'm worried that
the random number generator in the RTL may not be good enough to use
in the Win32 implementation for determining the type of error code
which was passed to ap_strerror() and whether or not an offset should
be subtracted.  More research is required on this issue.

Have fun...

? misc/unix/strerror.c

/* ====================================================================
 * The Apache Software License, Version 1.1
 *
 * Copyright (c) 2000 The Apache Software Foundation.  All rights
 * reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *
 * 3. The end-user documentation included with the redistribution,
 *    if any, must include the following acknowledgment:
 *       "This product includes software developed by the
 *        Apache Software Foundation (http://www.apache.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The names "Apache" and "Apache Software Foundation" must
 *    not be used to endorse or promote products derived from this
 *    software without prior written permission. For written
 *    permission, please contact apache@apache.org.
 *
 * 5. Products derived from this software may not be called "Apache",
 *    nor may "Apache" appear in their name, without prior written
 *    permission of the Apache Software Foundation.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * ====================================================================
 *
 * This software consists of voluntary contributions made by many
 * individuals on behalf of the Apache Software Foundation.  For more
 * information on the Apache Software Foundation, please see
 * <http://www.apache.org/>.
 */

#include "apr_config.h"
#include "apr_lib.h"
#include "apr_errno.h"

#include <string.h>

char *ap_strerror(ap_status_t status, char *buf, size_t buf_size)
{
    ap_cpystrn(buf, strerror(status), buf_size);
    return buf;
}

Index: include/apr_errno.h
===================================================================
RCS file: /cvs/apache/apache-2.0/src/lib/apr/include/apr_errno.h,v
retrieving revision 1.23
diff -u -r1.23 apr_errno.h
--- apr_errno.h	2000/04/08 06:58:41	1.23
+++ apr_errno.h	2000/04/18 11:08:42
@@ -78,7 +78,7 @@
 typedef int ap_status_t;
 
 int ap_canonical_error(ap_status_t err);
-const char *ap_strerror(ap_status_t err);
+char *ap_strerror(ap_status_t err, char *buf, size_t buf_size);
 
 #define APR_OS2_STATUS(e) (e == 0 ? APR_SUCCESS : e + APR_OS_START_SYSERR)
 
Index: misc/beos/misc_common.c
===================================================================
RCS file: /cvs/apache/apache-2.0/src/lib/apr/misc/beos/misc_common.c,v
retrieving revision 1.3
diff -u -r1.3 misc_common.c
--- misc_common.c	2000/04/05 11:24:17	1.3
+++ misc_common.c	2000/04/18 11:08:43
@@ -59,3 +59,5 @@
 #include "../unix/getopt.c"
 
 #include "../unix/otherchild.c"
+
+#include "../unix/strerror.c"
Index: misc/unix/Makefile.in
===================================================================
RCS file: /cvs/apache/apache-2.0/src/lib/apr/misc/unix/Makefile.in,v
retrieving revision 1.12
diff -u -r1.12 Makefile.in
--- Makefile.in	2000/04/15 19:05:13	1.12
+++ Makefile.in	2000/04/18 11:08:43
@@ -15,7 +15,7 @@
 
 #LIB=libmisc.a
 
-OBJS=start.o getopt.o otherchild.o error.o rand.o
+OBJS=start.o getopt.o otherchild.o error.o rand.o strerror.o
 
 .c.o:
 	$(CC) $(CFLAGS) -c $(INCLUDES) $<
Index: test/client.c
===================================================================
RCS file: /cvs/apache/apache-2.0/src/lib/apr/test/client.c,v
retrieving revision 1.10
diff -u -r1.10 client.c
--- client.c	2000/04/16 16:59:39	1.10
+++ client.c	2000/04/18 11:08:45
@@ -68,6 +68,7 @@
     ap_status_t stat;
     char datasend[STRLEN] = "Send data test";
     char datarecv[STRLEN];
+    char msgbuf[80];
     char *local_ipaddr, *remote_ipaddr;
     char *dest = "127.0.0.1";
     ap_uint32_t local_port, remote_port;
@@ -124,13 +125,12 @@
 
     fprintf(stdout, "\tClient:  Connecting to socket.......");
 
-    do {
-      stat = ap_connect(sock, dest);
-    } while (stat == APR_ECONNREFUSED);
+    stat = ap_connect(sock, dest);
 
     if (stat != APR_SUCCESS) {
         ap_close_socket(sock);
-        fprintf(stderr, "Could not connect  %d\n", stat);
+        fprintf(stderr, "Could not connect: %s (%d)\n", 
+		ap_strerror(stat, msgbuf, sizeof(msgbuf)), stat);
         fflush(stderr);
         exit(-1);
     }
@@ -166,7 +166,8 @@
 
     if ((stat = ap_recv(sock, datarecv, &length)) != APR_SUCCESS) {
         ap_close_socket(sock);
-        fprintf(stderr, "Problem receiving data: %d\n", stat);
+        fprintf(stderr, "Problem receiving data: %s (%d)\n", 
+		ap_strerror(stat, msgbuf, sizeof(msgbuf)), stat);
         exit(-1);
     }
     if (strcmp(datarecv, "Recv data test")) {

-- 
Jeff Trawick | trawick@ibm.net | PGP public key at web site:
     http://www.geocities.com/SiliconValley/Park/9289/
          Born in Roswell... married an alien...

Mime
View raw message