correct error signalling for opendir() failure
[openssl.git] / crypto / err / err.c
index db78aa787935aa13adf9bbfab0233b0fcc23714f..8810d838c64f02a270c7bdba8ab21248b833633a 100644 (file)
  */
 
 #include <stdio.h>
-#include "lhash.h"
-#include "crypto.h"
+#include <stdarg.h>
+#include <openssl/lhash.h>
+#include <openssl/crypto.h>
 #include "cryptlib.h"
-#include "buffer.h"
-#include "err.h"
-#include "crypto.h"
+#include <openssl/buffer.h>
+#include <openssl/err.h>
+#include <openssl/crypto.h>
 
 
 static LHASH *error_hash=NULL;
 static LHASH *thread_hash=NULL;
 
-#ifndef NOPROTO
 static unsigned long err_hash(ERR_STRING_DATA *a);
 static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b);
 static unsigned long pid_hash(ERR_STATE *pid);
@@ -76,16 +76,6 @@ static int pid_cmp(ERR_STATE *a,ERR_STATE *pid);
 static unsigned long get_error_values(int inc,const char **file,int *line,
                                      const char **data,int *flags);
 static void ERR_STATE_free(ERR_STATE *s);
-#else
-static unsigned long err_hash();
-static int err_cmp();
-static unsigned long pid_hash();
-static int pid_cmp();
-static unsigned long get_error_values();
-static void ERR_STATE_free();
-ERR_STATE *s;
-#endif
-
 #ifndef NO_ERR
 static ERR_STRING_DATA ERR_str_libraries[]=
        {
@@ -126,6 +116,7 @@ static ERR_STRING_DATA ERR_str_functs[]=
 #ifdef WINDOWS
        {ERR_PACK(0,SYS_F_WSASTARTUP,0),        "WSAstartup"},
 #endif
+       {ERR_PACK(0,SYS_F_OPENDIR,0),           "opendir"},
        {0,NULL},
        };
 
@@ -151,7 +142,7 @@ static ERR_STRING_DATA ERR_str_reasons[]=
 {ERR_R_PKCS7_LIB                       ,"PKCS7 lib"},
 {ERR_R_PKCS12_LIB                      ,"PKCS12 lib"},
 {ERR_R_MALLOC_FAILURE                  ,"Malloc failure"},
-{ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED     ,"called a fuction you should not call"},
+{ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED     ,"called a function you should not call"},
 {ERR_R_PASSED_NULL_PARAMETER           ,"passed a null parameter"},
 {ERR_R_NESTED_ASN1_ERROR               ,"nested asn1 error"},
 {ERR_R_BAD_ASN1_OBJECT_HEADER          ,"bad asn1 object header"},
@@ -256,6 +247,25 @@ void ERR_put_error(int lib, int func, int reason, const char *file,
        {
        ERR_STATE *es;
 
+#ifdef _OSD_POSIX
+       /* In the BS2000-OSD POSIX subsystem, the compiler generates
+        * path names in the form "*POSIX(/etc/passwd)".
+        * This dirty hack strips them to something sensible.
+        * @@@ We shouldn't modify a const string, though.
+        */
+       if (strncmp(file,"*POSIX(", sizeof("*POSIX(")-1) == 0) {
+               char *end;
+
+               /* Skip the "*POSIX(" prefix */
+               file += sizeof("*POSIX(")-1;
+               end = &file[strlen(file)-1];
+               if (*end == ')')
+                       *end = '\0';
+               /* Optional: use the basename of the path only. */
+               if ((end = strrchr(file, '/')) != NULL)
+                       file = &end[1];
+       }
+#endif
        es=ERR_get_state();
 
        es->top=(es->top+1)%ERR_NUM_ERRORS;
@@ -591,10 +601,9 @@ void ERR_set_error_data(char *data, int flags)
        es->err_data_flags[es->top]=flags;
        }
 
-void ERR_add_error_data( VAR_PLIST(int , num))
-VAR_ALIST
-        {
-        VAR_BDEFN(args, int, num);
+void ERR_add_error_data(int num, ...)
+       {
+       va_list args;
        int i,n,s;
        char *str,*p,*a;
 
@@ -603,11 +612,11 @@ VAR_ALIST
        if (str == NULL) return;
        str[0]='\0';
 
-       VAR_INIT(args,int,num);
+       va_start(args, num);
        n=0;
        for (i=0; i<num; i++)
                {
-               VAR_ARG(args,char *,a);
+               a=va_arg(args, char*);
                /* ignore NULLs, thanks to Bob Beck <beck@obtuse.com> */
                if (a != NULL)
                        {
@@ -629,6 +638,6 @@ VAR_ALIST
                }
        ERR_set_error_data(str,ERR_TXT_MALLOCED|ERR_TXT_STRING);
 
-       VAR_END( args );
+       va_end(args);
        }