OSSP CVS Repository

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

ossp-pkg/cfg/cfg_util.c 1.4 -> 1.5

--- cfg_util.c   2004/07/17 07:37:55     1.4
+++ cfg_util.c   2004/11/20 12:54:07     1.5
@@ -37,7 +37,7 @@
 #include "cfg_global.h"
 #include "cfg_util.h"
 
-cfg_rc_t cfg_util_readfile(const char *filename, char **buf_ptr, size_t *buf_len)
+cfg_rc_t cfg_util_readfile(const char *filename, char **buf_ptr, size_t *buf_size, size_t *buf_used)
 {
     FILE *fp = NULL;
     size_t n;
@@ -45,16 +45,16 @@
 
     if (strcmp(filename, "-") == 0) {
         /* file is given on stdin */
-        (*buf_len) = 32;
-        if ((*buf_ptr = (char *)malloc(*buf_len)) == NULL)
+        (*buf_size) = 32;
+        if ((*buf_ptr = (char *)malloc(*buf_size)) == NULL)
             return CFG_ERR_SYS;
         cp = *buf_ptr;
-        while ((n = fread(cp, 1, (*buf_len)-(cp-(*buf_ptr)), stdin)) > 0) {
+        while ((n = fread(cp, 1, (*buf_size)-(cp-(*buf_ptr)), stdin)) > 0) {
             cp += n;
-            if (((*buf_ptr)+(*buf_len))-cp < (*buf_len)/8) {
-                (*buf_len) *= 2;
+            if (((*buf_ptr)+(*buf_size))-cp < (*buf_size)/8) {
+                (*buf_size) *= 2;
                 n = cp-(*buf_ptr);
-                if ((cp = (char *)realloc(*buf_ptr, *buf_len)) == NULL) {
+                if ((cp = (char *)realloc(*buf_ptr, *buf_size)) == NULL) {
                     free(*buf_ptr);
                     return CFG_ERR_SYS;
                 }
@@ -63,6 +63,7 @@
             }
         }
         *cp = '\0';
+        *buf_used = (cp - *buf_ptr);
     }
     else {
         /* file is given on filesystem */
@@ -81,11 +82,13 @@
                 return CFG_ERR_SYS;
             }
             (*buf_ptr)[n] = '\0';
-            (*buf_len) = n+1;
+            (*buf_size)   = n+1;
+            (*buf_used)   = n;
         }
         else {
-            (*buf_ptr) = strdup("");
-            (*buf_len) = 1;
+            (*buf_ptr)  = strdup("");
+            (*buf_size) = 1;
+            (*buf_used) = 0;
         }
         fclose(fp);
     }

CVSTrac 2.0.1