Let Configure figure out the diverse shared library and DSO extensions
[openssl.git] / crypto / dso / dso_vms.c
index 511858a68197b3d1609f27796a967a9cb151b6fa..a36234d0a2e7e51e3a95857e85408ddaa78ddd18 100644 (file)
@@ -1,4 +1,3 @@
-/* dso_vms.c -*- mode:C; c-file-style: "eay" -*- */
 /*
  * Written by Richard Levitte (richard@levitte.org) for the OpenSSL project
  * 2000.
@@ -60,7 +59,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
-#include "cryptlib.h"
+#include "internal/cryptlib.h"
 #include <openssl/dso.h>
 
 #ifndef OPENSSL_SYS_VMS
@@ -76,7 +75,7 @@ DSO_METHOD *DSO_METHOD_vms(void)
 # include <stsdef.h>
 # include <descrip.h>
 # include <starlet.h>
-# include "vms_rms.h"
+# include "../vms_rms.h"
 
 /* Some compiler options may mask the declaration of "_malloc32". */
 # if __INITIAL_POINTER_SIZE && defined _ANSI_C_SOURCE
@@ -95,13 +94,6 @@ static int vms_load(DSO *dso);
 static int vms_unload(DSO *dso);
 static void *vms_bind_var(DSO *dso, const char *symname);
 static DSO_FUNC_TYPE vms_bind_func(DSO *dso, const char *symname);
-# if 0
-static int vms_unbind_var(DSO *dso, char *symname, void *symptr);
-static int vms_unbind_func(DSO *dso, char *symname, DSO_FUNC_TYPE symptr);
-static int vms_init(DSO *dso);
-static int vms_finish(DSO *dso);
-static long vms_ctrl(DSO *dso, int cmd, long larg, void *parg);
-# endif
 static char *vms_name_converter(DSO *dso, const char *filename);
 static char *vms_merger(DSO *dso, const char *filespec1,
                         const char *filespec2);
@@ -112,11 +104,6 @@ static DSO_METHOD dso_meth_vms = {
     NULL,                       /* unload */
     vms_bind_var,
     vms_bind_func,
-/* For now, "unbind" doesn't exist */
-# if 0
-    NULL,                       /* unbind_var */
-    NULL,                       /* unbind_func */
-# endif
     NULL,                       /* ctrl */
     vms_name_converter,
     vms_merger,
@@ -172,29 +159,30 @@ static int vms_load(DSO *dso)
 # endif                         /* __INITIAL_POINTER_SIZE == 64 */
 
     const char *sp1, *sp2;      /* Search result */
+    const char *ext = NULL;    /* possible extension to add */
 
     if (filename == NULL) {
         DSOerr(DSO_F_VMS_LOAD, DSO_R_NO_FILENAME);
         goto err;
     }
 
-        /*-
-         * A file specification may look like this:
-         *
-         *      node::dev:[dir-spec]name.type;ver
-         *
-         * or (for compatibility with TOPS-20):
-         *
-         *      node::dev:<dir-spec>name.type;ver
-         *
-         * and the dir-spec uses '.' as separator.  Also, a dir-spec
-         * may consist of several parts, with mixed use of [] and <>:
-         *
-         *      [dir1.]<dir2>
-         *
-         * We need to split the file specification into the name and
-         * the rest (both before and after the name itself).
-         */
+    /*-
+     * A file specification may look like this:
+     *
+     *      node::dev:[dir-spec]name.type;ver
+     *
+     * or (for compatibility with TOPS-20):
+     *
+     *      node::dev:<dir-spec>name.type;ver
+     *
+     * and the dir-spec uses '.' as separator.  Also, a dir-spec
+     * may consist of several parts, with mixed use of [] and <>:
+     *
+     *      [dir1.]<dir2>
+     *
+     * We need to split the file specification into the name and
+     * the rest (both before and after the name itself).
+     */
     /*
      * Start with trying to find the end of a dir-spec, and save the position
      * of the byte after in sp1
@@ -213,12 +201,20 @@ static int vms_load(DSO *dso)
         sp1++;                  /* The byte after the found character */
     /* Now, let's see if there's a type, and save the position in sp2 */
     sp2 = strchr(sp1, '.');
+    /*
+     * If there is a period and the next character is a semi-colon,
+     * we need to add an extension
+     */
+    if (sp2 != NULL && sp2[1] == ';')
+        ext = ".EXE";
     /*
      * If we found it, that's where we'll cut.  Otherwise, look for a version
      * number and save the position in sp2
      */
-    if (sp2 == NULL)
+    if (sp2 == NULL) {
         sp2 = strchr(sp1, ';');
+        ext = ".EXE";
+    }
     /*
      * If there was still nothing to find, set sp2 to point at the end of the
      * string
@@ -233,7 +229,7 @@ static int vms_load(DSO *dso)
         goto err;
     }
 
-    p = DSO_MALLOC(sizeof(DSO_VMS_INTERNAL));
+    p = DSO_MALLOC(sizeof(*p));
     if (p == NULL) {
         DSOerr(DSO_F_VMS_LOAD, ERR_R_MALLOC_FAILURE);
         goto err;
@@ -244,6 +240,11 @@ static int vms_load(DSO *dso)
 
     strncpy(p->imagename, filename, sp1 - filename);
     p->imagename[sp1 - filename] = '\0';
+    if (ext) {
+        strcat(p->imagename, ext);
+        if (*sp2 == '.')
+            sp2++;
+    }
     strcat(p->imagename, sp2);
 
     p->filename_dsc.dsc$w_length = strlen(p->filename);
@@ -265,10 +266,8 @@ static int vms_load(DSO *dso)
     return (1);
  err:
     /* Cleanup! */
-    if (p != NULL)
-        OPENSSL_free(p);
-    if (filename != NULL)
-        OPENSSL_free(filename);
+    OPENSSL_free(p);
+    OPENSSL_free(filename);
     return (0);
 }
 
@@ -512,7 +511,7 @@ static char *vms_merger(DSO *dso, const char *filespec1,
     }
 
     merged = OPENSSL_malloc(nam.NAMX_ESL + 1);
-    if (!merged)
+    if (merged == NULL)
         goto malloc_err;
     strncpy(merged, nam.NAMX_ESA, nam.NAMX_ESL);
     merged[nam.NAMX_ESL] = '\0';
@@ -525,7 +524,8 @@ static char *vms_name_converter(DSO *dso, const char *filename)
 {
     int len = strlen(filename);
     char *not_translated = OPENSSL_malloc(len + 1);
-    strcpy(not_translated, filename);
+    if (not_translated != NULL)
+        strcpy(not_translated, filename);
     return (not_translated);
 }