(file) Return to strarr.c CVS log (file) (dir) Up to [OMI] / omi / base

 1 mike  1.1 /*
 2           **==============================================================================
 3           **
 4           ** Open Management Infrastructure (OMI)
 5           **
 6           ** Copyright (c) Microsoft Corporation
 7           ** 
 8           ** Licensed under the Apache License, Version 2.0 (the "License"); you may not 
 9           ** use this file except in compliance with the License. You may obtain a copy 
10           ** of the License at 
11           **
12           **     http://www.apache.org/licenses/LICENSE-2.0 
13           **
14           ** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15           ** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED 
16           ** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, 
17           ** MERCHANTABLITY OR NON-INFRINGEMENT. 
18           **
19           ** See the Apache 2 License for the specific language governing permissions 
20           ** and limitations under the License.
21           **
22 mike  1.1 **==============================================================================
23           */
24           
25           #include <stdlib.h>
26           #include <string.h>
27           #include "strarr.h"
28           #include "strings.h"
29           
30           char** StrArr()
31           {
32               return (char**)calloc(1, sizeof(char*));
33           }
34           
35           void StrArrCat(char*** self_, const char* str)
36           {
37               size_t len;
38               char** self = *self_;
39               
40               len = StrArrLen(self);
41               self = (char**)realloc(self, sizeof(char*) * (len + 2));
42           
43 mike  1.1     if (self)
44               {
45                   char* s = Strdup(str);
46                   self[len] = s;
47                   self[len+1] = NULL;
48               }
49           
50               *self_ = self;
51           }
52           
53           size_t StrArrLen(char** self)
54           {
55               char** p = self;
56           
57               while (*p)
58                   p++;
59           
60               return p - self;
61           }
62           
63           void StrArrFree(char** self)
64 mike  1.1 {
65               char** p = self;
66               while (*p)
67                   free(*p++);
68           
69               free(self);
70           }

ViewCVS 0.9.2