Browse code

- conversion function to convert str to zero terminated string

Jan Janak authored on 17/07/2006 13:16:39
Showing 2 changed files
... ...
@@ -28,12 +28,16 @@
28 28
  *
29 29
  */
30 30
 
31
+
32
+#include <string.h>
31 33
 #include <sys/types.h>
32 34
 #include <pwd.h>
33 35
 #include <grp.h>
34 36
 #include <stdlib.h>
35 37
 #include <time.h>
36 38
 #include "ut.h"
39
+#include "mem/mem.h"
40
+
37 41
 
38 42
 /* converts a username into uid:gid,
39 43
  * returns -1 on error & 0 on success */
... ...
@@ -118,3 +122,22 @@ time_t _timegm(struct tm* t)
118 118
 	}
119 119
 	return (tl - (tb - tl));
120 120
 }
121
+
122
+
123
+/*
124
+ * Return str as zero terminated string allocated
125
+ * using pkg_malloc
126
+ */
127
+char* as_asciiz(str* s)
128
+{
129
+    char* r;
130
+
131
+    r = (char*)pkg_malloc(s->len + 1);
132
+    if (!r) {
133
+	ERR("Out of memory\n");
134
+	return 0;
135
+    }
136
+    memcpy(r, s->s, s->len);
137
+    r[s->len] = '\0';
138
+    return r;
139
+}
... ...
@@ -479,4 +479,11 @@ int group2gid(int* gid, char* group);
479 479
  */
480 480
 time_t _timegm(struct tm* t);
481 481
 
482
+
483
+/*
484
+ * Return str as zero terminated string allocated
485
+ * using pkg_malloc
486
+ */
487
+char* as_asciiz(str* s);
488
+
482 489
 #endif