summaryrefslogtreecommitdiff
path: root/ngircd/src/portab/strtok_r.c
blob: 4d00772f202a7d10963f596c2f99ca6aaf224ad1 (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
/*
 * 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