OSSP CVS Repository

ossp - Difference in ossp-pkg/rc/rc_util.c versions 1.3 and 1.4
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/rc/rc_util.c 1.3 -> 1.4

--- rc_util.c    2002/03/26 17:11:06     1.3
+++ rc_util.c    2002/05/23 18:03:20     1.4
@@ -27,6 +27,9 @@
 **  rc_util.c: Run-command processor ISO C source file
 */
 
+#include <stdlib.h>
+#include <string.h>
+
 #include "rc.h"         /* Error definitions  */
 #include "rc_const.h"   /* String definitions */
 
@@ -42,3 +45,45 @@
     else if (rv == RC_ERR_INT) return RC_ERRSTR_INT;
     else                       return RC_ERRSTR_UNK;
 }
+
+/* Vector copy constructor */
+char **vectorCopy(const char **kpszVec)
+{
+    int nSecs  = 0;
+    int nIndex = 0;
+    char **pszTemp = NULL;
+
+    if (kpszVec) {
+        for (nSecs = 0; kpszVec[nSecs]; nSecs++);   /* Count the sections */
+        pszTemp = malloc(sizeof (char **) * nSecs + 1);
+
+        for (nIndex = 0; kpszVec[nIndex]; nIndex++) {           /* Copy loop */
+            pszTemp[nIndex] = malloc(strlen(kpszVec[nIndex]));  /* for each  */
+            memcpy(pszTemp[nIndex], kpszVec[nIndex],            /* element   */
+                   strlen(kpszVec[nIndex]));                    /* in vector */
+        }
+        pszTemp[nIndex] = NULL; /* Used later to find the end of the array */
+        return(pszTemp);        /* Success */
+    }
+    else
+        RC_THROW(RC_ERR_USE);   /* Incoming vector is NULL? */
+
+    return(NULL);               /* Failure */
+}
+
+/* Vector destructor */
+rc_return_t vectorDel(char **pszVec)
+{
+    int i;
+    assert(pszVec);                 /* Check for unallocated incoming */
+
+    for (i = 0; pszVec[i]; i++) {   /* Loop through elements   */
+        free(pszVec[i]);            /* of vector, deallocating */
+        pszVec[i] = NULL;           /* along the way           */
+    }
+
+    free(pszVec);                   /* Free the vector itself  */
+    pszVec = NULL;
+
+    return(RC_THROW(RC_OK));
+}

CVSTrac 2.0.1