4 * Copyright (c) Tuomo Valkonen 1999-2002.
6 * You may distribute and modify this library under the terms of either
7 * the Clarified Artistic License or the GNU LGPL, version 2.1 or later.
19 void *malloczero(size_t size)
32 void *remalloczero(void *ptr, size_t oldsize, size_t newsize)
37 p=realloc(ptr, newsize);
45 memset((char*)p+oldsize, 0, newsize-oldsize);
52 char *scopyn(const char *p, size_t l)
54 char *pn=ALLOC_N(char, l+1);
66 char *scopy(const char *p)
73 char *scat(const char *p1, const char *p2)
81 pn=ALLOC_N(char, l1+l2+1);
87 memcpy(pn+l1, p2, l2+1);
93 char *scat3(const char *p1, const char *p2, const char *p3)
102 pn=ALLOC_N(char, l1+l2+l3+1);
108 memcpy(pn+l1, p2, l2);
109 memcpy(pn+l1+l2, p3, l3+1);
115 char *scatn(const char *s1, ssize_t l1, const char *s2, ssize_t l2)
128 s=ALLOC_N(char, tlen);
134 memcpy(s+l1, s2, l2);
144 const char *simple_basename(const char *name)
148 p=name+strlen(name)-1;
150 /* Skip any trailing slashes */
168 void stripws(char *p)
185 const char *libtu_strcasestr(const char *str, const char *ptn)
189 for(s2=str, p2=ptn; ; s2++, p2++) {
192 if(toupper(*s2)!=toupper(*p2))
202 bool readf(FILE *f, void *buf, size_t n)
204 return fread(buf, 1, n, f)!=1;
208 bool writef(FILE *f, const void *buf, size_t n)
210 return fwrite(buf, 1, n, f)!=1;