From 78c6ee0090f4122bc25baaacb5546517ad4b7bc6 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 24 Nov 2007 17:27:54 +0100 Subject: Remove some globals (This used to be commit 31d0a846db08d845e6cdfd85def4ac1c34031e02) --- source3/lib/util_str.c | 73 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 23 deletions(-) (limited to 'source3/lib/util_str.c') diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index b862299519..f26c8b8a77 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -506,21 +506,6 @@ int strwicmp(const char *psz1, const char *psz2) return (*psz1 - *psz2); } - -/** - Convert a string to upper case, but don't modify it. -**/ - -char *strupper_static(const char *s) -{ - static char *str = NULL; - - SAFE_FREE(str); - str = SMB_STRDUP(s); - strupper_m(str); - return str; -} - /** Convert a string to "normal" form. **/ @@ -1147,7 +1132,7 @@ bool in_list(const char *s, const char *list, bool casesensitive) } /* this is used to prevent lots of mallocs of size 1 */ -static const char *null_string = ""; +static const char null_string[] = ""; /** Set a string value, allocing the space for the string @@ -1561,13 +1546,17 @@ static void split_at_last_component(char *path, char *front, char sep, Write an octal as a string. **/ -const char *octal_string(int i) +char *octal_string(int i) { - static char ret[64]; - if (i == -1) - return "-1"; - slprintf(ret, sizeof(ret)-1, "0%o", i); - return ret; + char *result; + if (i == -1) { + result = talloc_strdup(talloc_tos(), "-1"); + } + else { + result = talloc_asprintf(talloc_tos(), "0%o", i); + } + SMB_ASSERT(result != NULL); + return result; } @@ -2552,7 +2541,7 @@ void rfc1738_unescape(char *buf) } } -static const char *b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; +static const char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; /** * Decode a base64 string into a DATA_BLOB - simple and slow algorithm @@ -2860,6 +2849,44 @@ void sprintf_append(TALLOC_CTX *mem_ctx, char **string, ssize_t *len, *string = NULL; } +/* + * asprintf into a string and strupper_m it after that. + */ + +int asprintf_strupper_m(char **strp, const char *fmt, ...) +{ + va_list ap; + char *result; + int ret; + + va_start(ap, fmt); + ret = vasprintf(&result, fmt, ap); + va_end(ap); + + if (ret == -1) + return -1; + + strupper_m(result); + *strp = result; + return ret; +} + +char *talloc_asprintf_strupper_m(TALLOC_CTX *t, const char *fmt, ...) +{ + va_list ap; + char *ret; + + va_start(ap, fmt); + ret = talloc_vasprintf(t, fmt, ap); + va_end(ap); + + if (ret == NULL) { + return NULL; + } + strupper_m(ret); + return ret; +} + /* Returns the substring from src between the first occurrence of the char "front" and the first occurence of the char "back". -- cgit