OSSP CVS Repository

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

ossp-pkg/rc/rc_script.c 1.31 -> 1.32

--- rc_script.c  2003/06/18 14:35:29     1.31
+++ rc_script.c  2003/06/26 18:45:14     1.32
@@ -50,9 +50,9 @@
 
     pNew = (rc_script_t *)malloc(sizeof(rc_script_t));
     if (pNew) {
-        *pNew = malloc((strlen(scriptTostring(pOrig)) + 1) * sizeof(char));
+        *pNew = malloc((strlen(scriptGetdata(pOrig)) + 1) * sizeof(char));
         if (*pNew)
-            strcpy(*pNew, scriptTostring(pOrig));
+            strcpy(*pNew, scriptGetdata(pOrig));
         else
             RC_THROW(RC_ERR_MEM);
     }
@@ -85,6 +85,36 @@
 }
 
 /****************************************************
+* scriptAdd(rc_script_t *, rc_script_t *)           *
+* Add one script to another                         *
+****************************************************/
+rc_return_t scriptAdd(rc_script_t *pDest, rc_script_t *pSource)
+{
+    int nResize     = 0;
+    void *pvRealloc = NULL;
+
+    assert(pDest && pSource); /* Parameters must be valid */
+
+    /* Add 2 chars to ensure that a \0 precedes any strings */
+    nResize = strlen(*pDest) + strlen(*pSource) + sizeof (char) * 2;
+    /* Don't trust realloc(3) in this case */
+    if ((pvRealloc = calloc(1, (size_t)nResize)) == NULL)
+        return(RC_THROW(RC_ERR_MEM));
+
+    strcpy(pvRealloc, *pDest);
+    strcat(pvRealloc, *pSource);
+
+    /* Cleanup and deallocate */
+    if (*pDest) {
+        free(*pDest);
+        *pDest = NULL;
+    }
+
+    *pDest = pvRealloc; /* Put the new data in */
+    return(RC_THROW(RC_OK));
+}
+
+/****************************************************
 * scriptAppend(rc_script_t *, const char *, size_t) *
 * Append text to a script                           *
 ****************************************************/
@@ -138,8 +168,8 @@
     char *szUser       = NULL;
     char *szTemp       = NULL; /* Holds temporarily the pri and user strings */
     struct passwd *pPwd = NULL;
-    long  nPri         = 0;
-    long  nUid         = 0;
+    long nPri          = 0;
+    long nUid          = 0;
     int nUserbytes     = 0;
     int nTmp           = 0;
     int nOffset        = 0;
@@ -291,19 +321,35 @@
 }
 
 /************************************************
-* scriptTostring(rc_script_t *)                 *
+* scriptGetdata(rc_script_t *)                  *
 * Return the private script data as a string    *
 ************************************************/
-const char *scriptTostring(rc_script_t *pScript)
+const char *scriptGetdata(rc_script_t *pScript)
 {
+    assert(pScript);
+
     /* Don't remove this! It encapsulates the script object, */
     /*                    which might not be a simple string */
-    if (pScript && *pScript)
-        return(*pScript);
-    else
-        RC_THROW(RC_ERR_USE);   /* Script was never constructed */
+    return(*pScript);
+}
 
-    return(NULL); /* Not reached */
+/************************************************
+* scriptSetdata(rc_script_t *, const char *)    *
+* Set the private script data from a string     *
+************************************************/
+rc_return_t scriptSetdata(rc_script_t *pScript, const char *kszIn)
+{
+    assert(pScript && kszIn); /* Avoid idiots */
+
+    if (*pScript) {
+        free(*pScript);
+        *pScript = NULL;
+    }
+
+    *pScript = malloc((strlen(kszIn) + 1) * sizeof(char));
+    strcpy(*pScript, kszIn);
+
+    return(RC_THROW(RC_OK));
 }
 
 /************************************************
@@ -315,7 +361,7 @@
     /* Don't remove this! It encapsulates the script object, */
     /*                    which might not be a simple string */
     if (pScript) {
-        fprintf(stdout, "%s", scriptTostring(pScript));
+        fprintf(stdout, "%s", scriptGetdata(pScript));
         return(RC_THROW(RC_OK));
     }
     else
@@ -340,7 +386,7 @@
     /* Don't remove this! It encapsulates the script object, */
     /*                    which might not be a simple string */
     if (pStream) {
-        fprintf(pStream, "%s", scriptTostring(pScript));
+        fprintf(pStream, "%s", scriptGetdata(pScript));
         fclose(pStream);
         return(RC_THROW(RC_OK));
     }

CVSTrac 2.0.1