File: strsep.c

package info (click to toggle)
nut 2.8.4%2Breally-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 25,720 kB
  • sloc: ansic: 132,030; sh: 17,256; cpp: 12,566; makefile: 5,646; python: 1,114; perl: 856; xml: 47
file content (19 lines) | stat: -rw-r--r-- 487 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <string.h>

/* Simple implem courtesy of https://stackoverflow.com/a/58244503
 * Note: like the (BSD) standard implem, this changes the original stringp!
 * Result is undefined (segfault here) if stringp==NULL
 * (it is supposed to be address of string after all)
 */
char *strsep(char **stringp, const char *delim) {
	char *rv = *stringp;
	if (rv) {
		*stringp += strcspn(*stringp, delim);
		if (**stringp)
			*(*stringp)++ = '\0';
		else
			*stringp = NULL;
	}
	return rv;
}