summaryrefslogtreecommitdiff
path: root/source3/lib/util_str.c
diff options
context:
space:
mode:
authorVolker Lendecke <vl@sernet.de>2007-11-24 17:27:54 +0100
committerVolker Lendecke <vl@sernet.de>2007-12-05 14:39:07 +0100
commit78c6ee0090f4122bc25baaacb5546517ad4b7bc6 (patch)
tree7b45cf85ff927e70552782b65bd73e50a637195f /source3/lib/util_str.c
parent66af0700396a5a5245aa25c95d70a620025b29c9 (diff)
downloadsamba-78c6ee0090f4122bc25baaacb5546517ad4b7bc6.tar.gz
samba-78c6ee0090f4122bc25baaacb5546517ad4b7bc6.tar.bz2
samba-78c6ee0090f4122bc25baaacb5546517ad4b7bc6.zip
Remove some globals
(This used to be commit 31d0a846db08d845e6cdfd85def4ac1c34031e02)
Diffstat (limited to 'source3/lib/util_str.c')
-rw-r--r--source3/lib/util_str.c73
1 files changed, 50 insertions, 23 deletions
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
@@ -2861,6 +2850,44 @@ void sprintf_append(TALLOC_CTX *mem_ctx, char **string, ssize_t *len,
}
/*
+ * 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".
Mallocs the return string which must be freed. Not for use