Use asprintf for string construction
[openafs.git] / src / util / dirpath.c
index 5a1a7d3..b307184 100644 (file)
 #include <afs/param.h>
 
 #include <roken.h>
+#include <afs/opr.h>
 
 #include <stddef.h>
 #include <ctype.h>
 #include <limits.h>
 
-#include "afs_assert.h"
 #include "afsutil.h"
 #include "fileutil.h"
 
+#include <afs/opr.h>
+
 #ifdef AFS_PTHREAD_ENV
 #include <pthread.h>
 static pthread_once_t dirInit_once = PTHREAD_ONCE_INIT;
@@ -329,6 +331,9 @@ initDirPathArray(void)
     pathp = dirPathArray[AFSDIR_SERVER_BOZINIT_FILEPATH_ID];
     AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_BOSCONFIG_DIR, AFSDIR_BOZINIT_FILE);
 
+    pathp = dirPathArray[AFSDIR_SERVER_BOZRXBIND_FILEPATH_ID];
+    AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_BOSCONFIG_DIR, AFSDIR_BOZRXBIND_FILE);
+
     pathp = dirPathArray[AFSDIR_SERVER_BOSVR_FILEPATH_ID];
     AFSDIR_SERVER_FILEPATH(pathp, AFSDIR_BOSSERVER_DIR, AFSDIR_BOSVR_FILE);
 
@@ -551,12 +556,9 @@ ConstructLocalPath(const char *cpath, const char *relativeTo,
            status = EINVAL;
        } else {
            /* fully qualified path; just make a copy */
-           newPath = (char *)malloc(strlen(cpath) + 1);
-           if (!newPath) {
+           newPath = strdup(cpath);
+           if (!newPath)
                status = ENOMEM;
-           } else {
-               (void)strcpy(newPath, cpath);
-           }
        }
 
     } else {
@@ -640,20 +642,12 @@ ConstructLocalPath(const char *cpath, const char *relativeTo,
 
     LocalizePathHead(&cpath, &relativeTo);
     if (*cpath == '/') {
-       newPath = (char *)malloc(strlen(cpath) + 1);
-       if (!newPath) {
-           status = ENOMEM;
-       } else {
-           strcpy(newPath, cpath);
-       }
+       newPath = strdup(cpath);
     } else {
-       newPath = (char *)malloc(strlen(relativeTo) + 1 + strlen(cpath) + 1);
-       if (!newPath) {
-           status = ENOMEM;
-       } else {
-           sprintf(newPath, "%s/%s", relativeTo, cpath);
-       }
+       asprintf(&newPath, "%s/%s", relativeTo, cpath);
     }
+    if (newPath == NULL)
+       status = ENOMEM;
 
     if (status == 0) {
        FilepathNormalize(newPath);