return (result);
}
-static char *
-next_token(char **stringp, const char *delim) {
- char *res;
-
- do {
- res = strsep(stringp, delim);
- if (res == NULL)
- break;
- } while (*res == '\0');
- return (res);
-}
-
static isc_result_t
parse_uint(isc_uint32_t *uip, const char *value, isc_uint32_t max,
const char *desc) {
static void
plus_option(char *option) {
isc_result_t result;
- char option_store[256];
- char *cmd, *value, *ptr;
+ char *cmd, *value, *last;
isc_boolean_t state = ISC_TRUE;
- strlcpy(option_store, option, sizeof(option_store));
- ptr = option_store;
- cmd = next_token(&ptr,"=");
+ cmd = strtok_r(option, "=", &last);
if (cmd == NULL) {
- printf(";; Invalid option %s\n", option_store);
+ printf(";; Invalid option %s\n", option);
return;
- }
- value = ptr;
+ }
if (strncasecmp(cmd, "no", 2)==0) {
cmd += 2;
state = ISC_FALSE;
}
+ value = strtok_r(NULL, "\0", &last);
+
#define FULLCHECK(A) \
do { \
size_t _l = strlen(cmd); \
*/
static void
-plus_option(const char *option, isc_boolean_t is_batchfile,
+plus_option(char *option, isc_boolean_t is_batchfile,
dig_lookup_t *lookup)
{
isc_result_t result;
- char option_store[256];
- char *cmd, *value, *ptr, *code;
+ char *cmd, *value, *last, *code;
isc_uint32_t num;
isc_boolean_t state = ISC_TRUE;
size_t n;
- strlcpy(option_store, option, sizeof(option_store));
- ptr = option_store;
- cmd = next_token(&ptr, "=");
- if (cmd == NULL) {
- printf(";; Invalid option %s\n", option_store);
+ if ((cmd = strtok_r(option, "=", &last)) == NULL) {
+ printf(";; Invalid option %s\n", option);
return;
}
- value = ptr;
if (strncasecmp(cmd, "no", 2)==0) {
cmd += 2;
state = ISC_FALSE;
}
+ /* parse the rest of the string */
+ value = strtok_r(NULL, "", &last);
#define FULLCHECK(A) \
do { \
"specified");
goto exit_or_usage;
}
- code = next_token(&value, ":");
- save_opt(lookup, code, value);
+ char *extra;
+ code = strtok_r(value, ":", &last);
+ extra = strtok_r(NULL, "\0", &last);
+ save_opt(lookup, code, extra);
break;
default:
goto invalid_option;
isc_boolean_t config_only, int argc, char **argv,
isc_boolean_t *firstarg)
{
- char opt, *value, *ptr, *ptr2, *ptr3;
+ char opt, *value, *ptr, *ptr2, *ptr3, *last;
isc_result_t result;
isc_boolean_t value_from_next;
isc_textregion_t tr;
value);
return (value_from_next);
case 'y':
- ptr = next_token(&value, ":"); /* hmac type or name */
- if (ptr == NULL) {
+ if ((ptr = strtok_r(value, ":", &last)) == NULL) {
usage();
}
- ptr2 = next_token(&value, ":"); /* name or secret */
- if (ptr2 == NULL)
+ if ((ptr2 = strtok_r(NULL, ":", &last)) == NULL) { /* name or secret */
usage();
- ptr3 = next_token(&value, ":"); /* secret or NULL */
- if (ptr3 != NULL) {
+ }
+ if ((ptr3 = strtok_r(NULL, ":", &last)) != NULL) { /* secret or NULL */
parse_hmac(ptr);
ptr = ptr2;
ptr2 = ptr3;
#endif
digestbits = 0;
}
+ /* XXXONDREJ: FIXME */
strlcpy(keynametext, ptr, sizeof(keynametext));
strlcpy(keysecret, ptr2, sizeof(keysecret));
return (value_from_next);
char **rv;
#ifndef NOPOSIX
char *homedir;
- char rcfile[256];
+ char rcfile[PATH_MAX];
#endif
- char *input;
- int i;
+ char *last;
isc_boolean_t need_clone = ISC_TRUE;
/*
homedir = getenv("HOME");
if (homedir != NULL) {
unsigned int n;
- n = snprintf(rcfile, sizeof(rcfile), "%s/.digrc",
- homedir);
- if (n < sizeof(rcfile))
+ n = snprintf(rcfile, sizeof(rcfile), "%s/.digrc", homedir);
+ if (n < sizeof(rcfile)) {
batchfp = fopen(rcfile, "r");
+ }
}
if (batchfp != NULL) {
- while (fgets(batchline, sizeof(batchline),
- batchfp) != 0) {
+ while (fgets(batchline, sizeof(batchline), batchfp) != 0) {
debug("config line %s", batchline);
- bargc = 1;
- input = batchline;
- bargv[bargc] = next_token(&input, " \t\r\n");
- while ((bargc < 62) && (bargv[bargc] != NULL)) {
- bargc++;
- bargv[bargc] =
- next_token(&input, " \t\r\n");
+ for (bargc = 1, bargv[bargc] = strtok_r(batchline, " \t\r\n", &last);
+ bargc < 62 && bargv[bargc];
+ bargv[++bargc] = strtok_r(NULL, " \t\r\n", &last))
+ {
+ debug(".digrc argv %d: %s", bargc, bargv[bargc]);
}
-
bargv[0] = argv[0];
argv0 = argv[0];
-
- for(i = 0; i < bargc; i++)
- debug(".digrc argv %d: %s",
- i, bargv[i]);
- parse_args(ISC_TRUE, ISC_TRUE, bargc,
- (char **)bargv);
+ parse_args(ISC_TRUE, ISC_TRUE, bargc, (char **)bargv);
}
fclose(batchfp);
}
/* Processing '-f batchfile'. */
lookup = clone_lookup(default_lookup, ISC_TRUE);
need_clone = ISC_FALSE;
- } else
+ } else {
lookup = default_lookup;
+ }
rc = argc;
rv = argv;
if (batchline[0] == '\r' || batchline[0] == '\n'
|| batchline[0] == '#' || batchline[0] == ';')
goto next_line;
- input = batchline;
- bargv[bargc] = next_token(&input, " \t\r\n");
- while ((bargc < 14) && (bargv[bargc] != NULL)) {
- bargc++;
- bargv[bargc] = next_token(&input, " \t\r\n");
+ for (bargc = 1, bargv[bargc] = strtok_r(batchline, " \t\r\n", &last);
+ (bargc < 14) && bargv[bargc];
+ bargc++, bargv[bargc] = strtok_r(NULL, " \t\r\n", &last)) {
+ debug("batch argv %d: %s", bargc, bargv[bargc]);
}
bargv[0] = argv[0];
argv0 = argv[0];
- for(i = 0; i < bargc; i++)
- debug("batch argv %d: %s", i, bargv[i]);
parse_args(ISC_TRUE, ISC_FALSE, bargc, (char **)bargv);
return;
}
char batchline[MXNAME];
int bargc;
char *bargv[16];
- char *input;
- int i;
if (batchname == NULL) {
isc_app_shutdown();
}
if (fgets(batchline, sizeof(batchline), batchfp) != 0) {
+ char *last;
debug("batch line %s", batchline);
- bargc = 1;
- input = batchline;
- bargv[bargc] = next_token(&input, " \t\r\n");
- while ((bargc < 14) && (bargv[bargc] != NULL)) {
- bargc++;
- bargv[bargc] = next_token(&input, " \t\r\n");
+ for (bargc = 1, bargv[bargc] = strtok_r(batchline, " \t\r\n", &last);
+ bargc < 14 && bargv[bargc];
+ bargc++, bargv[bargc] = strtok_r(NULL, " \t\r\n", &last))
+ {
+ debug("batch argv %d: %s", bargc, bargv[bargc]);
}
bargv[0] = argv0;
- for(i = 0; i < bargc; i++)
- debug("batch argv %d: %s", i, bargv[i]);
parse_args(ISC_TRUE, ISC_FALSE, bargc, (char **)bargv);
start_lookup();
} else {
static isc_boolean_t
next_origin(dig_lookup_t *oldlookup);
-char *
-next_token(char **stringp, const char *delim) {
- char *res;
-
- do {
- res = strsep(stringp, delim);
- if (res == NULL)
- break;
- } while (*res == '\0');
- return (res);
-}
-
static int
count_dots(char *string) {
char *s;
void
set_search_domain(char *domain);
-char *
-next_token(char **stringp, const char *delim);
-
/*
* Routines to be defined in dig.c, host.c, and nslookup.c. and
* then assigned to the appropriate function pointer
static void
do_next_command(char *input) {
- char *ptr, *arg;
+ char *ptr, *arg, *last;
- ptr = next_token(&input, " \t\r\n");
- if (ptr == NULL)
+ if ((ptr = strtok_r(input, " \t\r\n", &last)) == NULL) {
return;
- arg = next_token(&input, " \t\r\n");
+ }
+ arg = strtok_r(NULL, " \t\r\n", &last);
if ((strcasecmp(ptr, "set") == 0) &&
(arg != NULL))
setoption(arg);
return ((n == 0) ? ISC_R_SUCCESS : ISC_R_FAILURE);
}
-static char *
-next_token(char **stringp, const char *delim) {
- char *res;
-
- do {
- res = strsep(stringp, delim);
- if (res == NULL)
- break;
- } while (*res == '\0');
- return (res);
-}
-
void
named_os_shutdownmsg(char *command, isc_buffer_t *text) {
- char *input, *ptr;
+ char *last, *ptr;
pid_t pid;
- input = command;
/* Skip the command name. */
- ptr = next_token(&input, " \t");
- if (ptr == NULL)
+ if ((ptr = strtok_r(command, " \t", &last)) == NULL) {
return;
+ }
- ptr = next_token(&input, " \t");
- if (ptr == NULL)
+ if ((ptr = strtok_r(NULL, " \t", &last)) == NULL) {
return;
+ }
- if (strcmp(ptr, "-p") != 0)
+ if (strcmp(ptr, "-p") != 0) {
return;
+ }
#ifdef HAVE_LINUXTHREADS
pid = mainpid;
stdout);
}
-static char *
-next_token(char **stringp, const char *delim) {
- char *res;
-
- do {
- res = strsep(stringp, delim);
- if (res == NULL)
- break;
- } while (*res == '\0');
- return (res);
-}
-
ISC_PLATFORM_NORETURN_PRE static void
fatal(const char *format, ...)
ISC_FORMAT_PRINTF(1, 2) ISC_PLATFORM_NORETURN_POST;
plus_option(char *option, struct query *query, isc_boolean_t global)
{
isc_result_t result;
- char option_store[256];
- char *cmd, *value, *ptr, *code;
+ char *cmd, *value, *last, *code;
isc_uint32_t num;
isc_boolean_t state = ISC_TRUE;
size_t n;
- strlcpy(option_store, option, sizeof(option_store));
- ptr = option_store;
- cmd = next_token(&ptr, "=");
- if (cmd == NULL) {
- printf(";; Invalid option %s\n", option_store);
+ if ((cmd = strtok_r(option, "=", &last)) == NULL) {
+ printf(";; Invalid option %s\n", option);
return;
}
- value = ptr;
if (strncasecmp(cmd, "no", 2) == 0) {
cmd += 2;
state = ISC_FALSE;
}
+ /* parse the rest of the string */
+ value = strtok_r(NULL, "", &last);
#define FULLCHECK(A) \
do { \
fatal("ednsopt no "
"code point "
"specified");
- code = next_token(&value, ":");
+ code = strtok_r(value, ":", &last);
save_opt(query, code, value);
break;
default:
char *bargv[64];
int rc;
char **rv;
- char *input;
isc_boolean_t global = ISC_TRUE;
/*
fatal("couldn't open batch file '%s'", batchname);
}
while (fgets(batchline, sizeof(batchline), batchfp) != 0) {
- bargc = 1;
+ char *last;
if (batchline[0] == '\r' || batchline[0] == '\n'
|| batchline[0] == '#' || batchline[0] == ';')
continue;
- input = batchline;
- bargv[bargc] = next_token(&input, " \t\r\n");
- while ((bargc < 14) && (bargv[bargc] != NULL)) {
- bargc++;
- bargv[bargc] = next_token(&input, " \t\r\n");
+ for (bargc = 1, bargv[bargc] = strtok_r(batchline, " \t\r\n", &last);
+ (bargc < 14) && bargv[bargc];
+ bargc++, bargv[bargc] = strtok_r(NULL, " \t\r\n", &last))
+ {
+ /* empty body */
}
bargv[0] = argv[0];
GENRANDOMLIB
ISC_PLATFORM_NEEDSTRTOUL
ISC_PLATFORM_NEEDMEMMOVE
-ISC_PLATFORM_NEEDSTRSEP
ISC_IRS_GETNAMEINFOSOCKLEN
ISC_IRS_NEEDADDRINFO
ISC_PLATFORM_HAVETFO
# Check for some other useful functions that are not ever-present.
#
-# We test for strsep() using AC_TRY_LINK instead of AC_CHECK_FUNC
-# because AIX 4.3.3 with patches for bos.adt.include to version 4.3.3.77
-# reportedly defines strsep() without declaring it in <string.h> when
-# -D_LINUX_SOURCE_COMPAT is not defined [RT #2190], and
-# AC_CHECK_FUNC() incorrectly succeeds because it declares
-# the function itself.
-{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for correctly declared strsep()" >&5
-$as_echo_n "checking for correctly declared strsep()... " >&6; }
-cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h. */
-#include <string.h>
-int
-main ()
-{
-char *sp; char *foo = strsep(&sp, ".");
- ;
- return 0;
-}
-_ACEOF
-if ac_fn_c_try_link "$LINENO"; then :
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }; ISC_PLATFORM_NEEDSTRSEP="#undef ISC_PLATFORM_NEEDSTRSEP"
-else
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }; ISC_PLATFORM_NEEDSTRSEP="#define ISC_PLATFORM_NEEDSTRSEP 1"
-fi
-rm -f core conftest.err conftest.$ac_objext \
- conftest$ac_exeext conftest.$ac_ext
-
-
ac_fn_c_check_func "$LINENO" "memmove" "ac_cv_func_memmove"
if test "x$ac_cv_func_memmove" = xyes; then :
ISC_PLATFORM_NEEDMEMMOVE="#undef ISC_PLATFORM_NEEDMEMMOVE"
# Check for some other useful functions that are not ever-present.
#
-# We test for strsep() using AC_TRY_LINK instead of AC_CHECK_FUNC
-# because AIX 4.3.3 with patches for bos.adt.include to version 4.3.3.77
-# reportedly defines strsep() without declaring it in <string.h> when
-# -D_LINUX_SOURCE_COMPAT is not defined [RT #2190], and
-# AC_CHECK_FUNC() incorrectly succeeds because it declares
-# the function itself.
-AC_MSG_CHECKING(for correctly declared strsep())
-AC_TRY_LINK([#include <string.h>], [char *sp; char *foo = strsep(&sp, ".");],
- [AC_MSG_RESULT(yes); ISC_PLATFORM_NEEDSTRSEP="#undef ISC_PLATFORM_NEEDSTRSEP"],
- [AC_MSG_RESULT(no); ISC_PLATFORM_NEEDSTRSEP="#define ISC_PLATFORM_NEEDSTRSEP 1"])
-AC_SUBST(ISC_PLATFORM_NEEDSTRSEP)
-
AC_CHECK_FUNC(memmove,
[ISC_PLATFORM_NEEDMEMMOVE="#undef ISC_PLATFORM_NEEDMEMMOVE"],
[ISC_PLATFORM_NEEDMEMMOVE="#define ISC_PLATFORM_NEEDMEMMOVE 1"])
int
getzone(DB *dbp, const DBT *pkey, const DBT *pdata, DBT *skey) {
- char *tmp;
- char *left;
- char *right;
- int result=0;
+ char *token, *last;
UNUSED(dbp);
UNUSED(pkey);
- /* Allocate memory to use in parsing the string */
- tmp = right = malloc(pdata->size + 1);
-
- /* verify memory was allocated */
- if (right == NULL) {
- result = BDBparseErr;
- goto getzone_cleanup;
- }
-
- /* copy data string into newly allocated memory */
- strncpy(right, pdata->data, pdata->size);
- right[pdata->size] = '\0';
-
- /* split string at the first space */
- left = isc_string_separate(&right, " ");
+ if ((token = strtok_r(pdata->data, " ", &last)) == NULL) {
+ return BDBparseErr;
+ }
/* copy string for "zone" secondary index */
- skey->data = strdup(left);
- if (skey->data == NULL) {
- result = BDBparseErr;
- goto getzone_cleanup;
+ if ((skey->data = strdup(token)) == NULL) {
+ return BDBparseErr;
}
/* set required values for BDB */
skey->size = strlen(skey->data);
skey->flags = DB_DBT_APPMALLOC;
- getzone_cleanup:
-
- /* cleanup memory */
- if (tmp != NULL)
- free(tmp);
-
- return result;
+ return 0;
}
/*%
int
gethost(DB *dbp, const DBT *pkey, const DBT *pdata, DBT *skey) {
- char *tmp;
- char *left;
- char *right;
- int result=0;
+ char *token, *last;
UNUSED(dbp);
UNUSED(pkey);
- /* allocate memory to use in parsing the string */
- tmp = right = malloc(pdata->size + 1);
-
- /* verify memory was allocated */
- if (tmp == NULL) {
- result = BDBparseErr;
- goto gethost_cleanup;
- }
-
- /* copy data string into newly allocated memory */
- strncpy(right, pdata->data, pdata->size);
- right[pdata->size] = '\0';
-
- /* we don't care about left string. */
- /* memory of left string will be freed when tmp is freed. */
- isc_string_separate(&right, " ");
-
- /* verify right still has some characters left */
- if (right == NULL) {
- result = BDBparseErr;
- goto gethost_cleanup;
+ /* we don't care about first token. */
+ if ((token = strtok_r(right, " ", &last)) == NULL) {
+ return BDBparseErr;
}
/* get "host" from data string */
- left = isc_string_separate(&right, " ");
+ if ((token = strtok_r(NULL, " ", &last)) == NULL) {
+ return BDBparseErr;
+ }
+
/* copy string for "host" secondary index */
- skey->data = strdup(left);
- if (skey->data == NULL) {
- result = BDBparseErr;
- goto gethost_cleanup;
+ if ((skey->data = strdup(token)) == NULL) {
+ return BDBparseErr;
}
/* set required values for BDB */
skey->size = strlen(skey->data);
skey->flags = DB_DBT_APPMALLOC;
- gethost_cleanup:
-
- /* cleanup memory */
- if (tmp != NULL)
- free(tmp);
-
- return result;
+ return 0;
}
/*%
* split string at the first "$". set query segment to
* left portion
*/
+ char *last = NULL;
tseg->sql = isc_mem_strdup(mctx,
- isc_string_separate(&right_str,
- "$"));
+ strtok_r(right_str, "$", &last));
if (tseg->sql == NULL) {
/* no memory, clean everything up. */
result = ISC_R_NOMEMORY;
}
/* loop through the string and chop it up */
- while (right_str != NULL) {
+ for (token = strtok_r(right_str, "$", &temp_str);
+ token;
+ token = strtok_r(NULL, "$", &temp_str))
+ {
/* allocate memory for tseg */
tseg = calloc(1, sizeof(query_segment_t));
if (tseg == NULL) { /* no memory, clean everything up. */
result = ISC_R_NOMEMORY;
goto cleanup;
}
- tseg->cmd = NULL;
tseg->direct = ISC_FALSE;
/* initialize the query segment link */
DLZ_LINK_INIT(tseg, link);
* split string at the first "$". set query segment to
* left portion
*/
- tseg->cmd = strdup(strsep(&right_str, "$"));
+ tseg->cmd = strdup(token);
if (tseg->cmd == NULL) {
/* no memory, clean everything up. */
result = ISC_R_NOMEMORY;
}
/* we don't need temp_str any more */
- free(temp_str);
+ free(right_str);
+ right_str = NULL;
/*
* add checks later to verify zone and record are found if
* necessary.
cleanup:
/* get rid of temp_str */
- if (temp_str != NULL)
- free(temp_str);
+ if (right_str != NULL) {
+ free(right_str);
+ }
flag_fail:
/* get rid of what was build of the query list */
return (error);
}
-static char *
-irs_strsep(char **stringp, const char *delim) {
- char *string = *stringp;
- char *s;
- const char *d;
- char sc, dc;
-
- if (string == NULL)
- return (NULL);
-
- for (s = string; *s != '\0'; s++) {
- sc = *s;
- for (d = delim; (dc = *d) != '\0'; d++)
- if (sc == dc) {
- *s++ = '\0';
- *stringp = s;
- return (string);
- }
- }
- *stringp = NULL;
- return (string);
-}
-
static void
set_order(int family, int (**net_order)(const char *, int, struct addrinfo **,
int, int))
} else {
order = getenv("NET_ORDER");
found = 0;
- while (order != NULL) {
- /*
- * We ignore any unknown names.
- */
- tok = irs_strsep(&order, ":");
+ char *last;
+ for (tok = strtok_r(order, ":", &last);
+ tok;
+ tok = strtok_r(NULL, ":", &last))
+ {
if (strcasecmp(tok, "inet6") == 0) {
- if ((found & FOUND_IPV6) == 0)
+ if ((found & FOUND_IPV6) == 0) {
*net_order++ = add_ipv6;
+ }
found |= FOUND_IPV6;
} else if (strcasecmp(tok, "inet") == 0 ||
- strcasecmp(tok, "inet4") == 0) {
- if ((found & FOUND_IPV4) == 0)
+ strcasecmp(tok, "inet4") == 0) {
+ if ((found & FOUND_IPV4) == 0) {
*net_order++ = add_ipv4;
+ }
found |= FOUND_IPV4;
}
}
*/
@ISC_PLATFORM_QUADFORMAT@
-/***
- *** String functions.
- ***/
-/*
- * If the system needs strsep(), ISC_PLATFORM_NEEDSTRSEP will be defined.
- */
-@ISC_PLATFORM_NEEDSTRSEP@
-
/*
* If the system needs strlcpy(), ISC_PLATFORM_NEEDSTRLCPY will be defined.
*/
ISC_LANG_BEGINDECLS
-char *
-isc_string_separate(char **stringp, const char *delim);
-
-#ifdef ISC_PLATFORM_NEEDSTRSEP
-#define strsep isc_string_separate
-#endif
-
#ifdef ISC_PLATFORM_NEEDMEMMOVE
#define memmove(a,b,c) bcopy(b,a,c)
#endif
#include <isc/string.h>
#include <isc/util.h>
-char *
-isc_string_separate(char **stringp, const char *delim) {
- char *string = *stringp;
- char *s;
- const char *d;
- char sc, dc;
-
- if (string == NULL)
- return (NULL);
-
- for (s = string; (sc = *s) != '\0'; s++)
- for (d = delim; (dc = *d) != '\0'; d++)
- if (sc == dc) {
- *s++ = '\0';
- *stringp = s;
- return (string);
- }
- *stringp = NULL;
- return (string);
-}
-
size_t
isc_string_strlcpy(char *dst, const char *src, size_t size)
{
isc_stdio_tell
isc_stdio_write
isc_stdtime_get
-isc_string_separate
isc_string_strcasestr
isc_string_strlcat
isc_string_strlcpy