about summary refs log tree commit diff
path: root/src/portab/strtok_r.c
blob: 043898e9e13f72c6013d6a0f26c7390ed4b4735c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
 * ngIRCd -- The Next Generation IRC Daemon
 */

#include "portab.h"

/**
 * @file
 * Implementation of strtok_r()
 */

#ifndef HAVE_STRTOK_R

#include <string.h>

char *
strtok_r(char *str, const char *delim, char **saveptr)
{
	char *tmp;

	if (!str)
		str = *saveptr;
	str += strspn(str, delim);
	if (*str == 0)
		return NULL;

	tmp = str + strcspn(str, delim); /* get end of token */
	if (*tmp) { /* another delimiter */
		*tmp = 0;
		tmp++;
	}
	*saveptr = tmp;
	return str;
}

#endif