summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2009-03-01 16:41:57 +0100
committerJelmer Vernooij <jelmer@samba.org>2009-03-01 16:41:57 +0100
commit4903d20c215a01f70c242cb8cf4d455d0e352b7f (patch)
tree75e0ff6c58546ee4e1d68d3b677c7c75e56fcb68 /lib
parent9f6e2d64852026d118c717d80236177fd74331eb (diff)
parent09ac816b36e45fd537af2f7fe7c57a11f5c744f5 (diff)
downloadsamba-4903d20c215a01f70c242cb8cf4d455d0e352b7f.tar.gz
samba-4903d20c215a01f70c242cb8cf4d455d0e352b7f.tar.bz2
samba-4903d20c215a01f70c242cb8cf4d455d0e352b7f.zip
Merge branch 'master' of git://git.samba.org/samba into convenience
Diffstat (limited to 'lib')
-rw-r--r--lib/tevent/pytevent.c4
-rw-r--r--lib/util/util.c100
-rw-r--r--lib/util/util.h15
3 files changed, 117 insertions, 2 deletions
diff --git a/lib/tevent/pytevent.c b/lib/tevent/pytevent.c
index 3b45ba1928..fe7e7e3e38 100644
--- a/lib/tevent/pytevent.c
+++ b/lib/tevent/pytevent.c
@@ -29,7 +29,6 @@
#include <tevent.h>
#include <stdbool.h>
-#include "tevent_util.h"
typedef struct {
PyObject_HEAD
@@ -54,7 +53,8 @@ static PyObject *py_backend_list(PyObject *self)
PyObject *ret;
int i, len;
- len = ev_str_list_length(backends);
+ for (len = 0; backends[len]; len++);
+
ret = PyList_New(len);
for (i = 0; i < len; i++)
PyList_SetItem(ret, i, PyString_FromString(backends[i]));
diff --git a/lib/util/util.c b/lib/util/util.c
index 988d8f9fa0..1f31f55e8b 100644
--- a/lib/util/util.c
+++ b/lib/util/util.c
@@ -836,4 +836,104 @@ _PUBLIC_ size_t utf16_len_n(const void *src, size_t n)
return len;
}
+/**
+ * @file
+ * @brief String utilities.
+ **/
+
+static bool next_token_internal_talloc(TALLOC_CTX *ctx,
+ const char **ptr,
+ char **pp_buff,
+ const char *sep,
+ bool ltrim)
+{
+ char *s;
+ char *saved_s;
+ char *pbuf;
+ bool quoted;
+ size_t len=1;
+
+ *pp_buff = NULL;
+ if (!ptr) {
+ return(false);
+ }
+
+ s = (char *)*ptr;
+
+ /* default to simple separators */
+ if (!sep) {
+ sep = " \t\n\r";
+ }
+
+ /* find the first non sep char, if left-trimming is requested */
+ if (ltrim) {
+ while (*s && strchr_m(sep,*s)) {
+ s++;
+ }
+ }
+
+ /* nothing left? */
+ if (!*s) {
+ return false;
+ }
+
+ /* When restarting we need to go from here. */
+ saved_s = s;
+
+ /* Work out the length needed. */
+ for (quoted = false; *s &&
+ (quoted || !strchr_m(sep,*s)); s++) {
+ if (*s == '\"') {
+ quoted = !quoted;
+ } else {
+ len++;
+ }
+ }
+
+ /* We started with len = 1 so we have space for the nul. */
+ *pp_buff = talloc_array(ctx, char, len);
+ if (!*pp_buff) {
+ return false;
+ }
+
+ /* copy over the token */
+ pbuf = *pp_buff;
+ s = saved_s;
+ for (quoted = false; *s &&
+ (quoted || !strchr_m(sep,*s)); s++) {
+ if ( *s == '\"' ) {
+ quoted = !quoted;
+ } else {
+ *pbuf++ = *s;
+ }
+ }
+
+ *ptr = (*s) ? s+1 : s;
+ *pbuf = 0;
+
+ return true;
+}
+
+bool next_token_talloc(TALLOC_CTX *ctx,
+ const char **ptr,
+ char **pp_buff,
+ const char *sep)
+{
+ return next_token_internal_talloc(ctx, ptr, pp_buff, sep, true);
+}
+
+/*
+ * Get the next token from a string, return false if none found. Handles
+ * double-quotes. This version does not trim leading separator characters
+ * before looking for a token.
+ */
+
+bool next_token_no_ltrim_talloc(TALLOC_CTX *ctx,
+ const char **ptr,
+ char **pp_buff,
+ const char *sep)
+{
+ return next_token_internal_talloc(ctx, ptr, pp_buff, sep, false);
+}
+
diff --git a/lib/util/util.h b/lib/util/util.h
index 27f94cd685..1f6e3b193b 100644
--- a/lib/util/util.h
+++ b/lib/util/util.h
@@ -204,6 +204,21 @@ _PUBLIC_ void display_set_stderr(void);
/* The following definitions come from lib/util/util_str.c */
+bool next_token_talloc(TALLOC_CTX *ctx,
+ const char **ptr,
+ char **pp_buff,
+ const char *sep);
+
+/**
+ * Get the next token from a string, return false if none found. Handles
+ * double-quotes. This version does not trim leading separator characters
+ * before looking for a token.
+ */
+bool next_token_no_ltrim_talloc(TALLOC_CTX *ctx,
+ const char **ptr,
+ char **pp_buff,
+ const char *sep);
+
/**
Trim the specified elements off the front and back of a string.