0b410a16e4139b5648ae6296a6f04c66f528beb6 kent Thu Oct 28 14:49:40 2010 -0700 Adding catTwoStrings to common library. diff --git src/lib/common.c src/lib/common.c index 26336ef..75c9423 100644 --- src/lib/common.c +++ src/lib/common.c @@ -41,30 +41,41 @@ { int size = 0; if (s == NULL) return NULL; size = strlen(s); return cloneStringZExt(s, size, size); } char *cloneLongString(char *s) /* Make clone of long string. */ { size_t size = strlen(s); return cloneMem(s, size+1); } +char *catTwoStrings(char *a, char *b) +/* Allocate new string that is a concatenation of two strings. */ +{ +int aLen = strlen(a), bLen = strlen(b); +int len = aLen + bLen; +char *newBuf = needLargeMem(len+1); +memcpy(newBuf, a, aLen); +memcpy(newBuf+aLen, b, bLen); +newBuf[len] = 0; +return newBuf; +} /* fill a specified area of memory with zeroes */ void zeroBytes(void *vpt, int count) { char *pt = (char*)vpt; while (--count>=0) *pt++=0; } /* Reverse the order of the bytes. */ void reverseBytes(char *bytes, long length) { long halfLen = (length>>1); char *end = bytes+length; char c; @@ -944,31 +955,32 @@ return el; } void *slPairFindVal(struct slPair *list, char *name) /* Return value associated with name in list, or NULL if not found. */ { struct slPair *el = slPairFind(list, name); if (el == NULL) return NULL; return el->val; } struct slPair *slPairFromString(char *s) /* Return slPair list parsed from list in string s * name1=val1 name2=val2 ... - * Returns NULL if parse error */ + * Returns NULL if parse error. Free this up with + * slPairFreeValsAndList. */ { struct slPair *list = NULL; char *name; char *ss = cloneString(s); char *word = ss; while((name = nextWord(&word))) { char *val = strchr(name,'='); if (!val) { warn("missing equals sign in name=value pair: name=[%s] in string=[%s]\n", name, s); return NULL; } *val++ = 0; slPairAdd(&list, name, cloneString(val));