/* **============================================================================== ** ** Open Management Infrastructure (OMI) ** ** Copyright (c) Microsoft Corporation ** ** Licensed under the Apache License, Version 2.0 (the "License"); you may not ** use this file except in compliance with the License. You may obtain a copy ** of the License at ** ** http://www.apache.org/licenses/LICENSE-2.0 ** ** THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY ** KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED ** WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE, ** MERCHANTABLITY OR NON-INFRINGEMENT. ** ** See the Apache 2 License for the specific language governing permissions ** and limitations under the License. ** **============================================================================== */ #include #include #include "strarr.h" #include "strings.h" char** StrArr() { return (char**)calloc(1, sizeof(char*)); } void StrArrCat(char*** self_, const char* str) { size_t len; char** self = *self_; len = StrArrLen(self); self = (char**)realloc(self, sizeof(char*) * (len + 2)); if (self) { char* s = Strdup(str); self[len] = s; self[len+1] = NULL; } *self_ = self; } size_t StrArrLen(char** self) { char** p = self; while (*p) p++; return p - self; } void StrArrFree(char** self) { char** p = self; while (*p) free(*p++); free(self); }