comparison port/C/strsep.c @ 548:f48bb09bccc7

Misc: huge cleanup, switch to spaces
author David Demelier <markand@malikania.fr>
date Wed, 15 Jun 2016 13:13:26 +0200
parents dc1b5143c5e3
children 266f32919d0a
comparison
equal deleted inserted replaced
547:ecf5fb9319da 548:f48bb09bccc7
1 /* 1 /*
2 * strsep.c -- separate a string by delimiters 2 * strsep.c -- separate a string by delimiters
3 * 3 *
4 * Copyright (c) 2011, 2012, David Demelier <markand@malikania.fr> 4 * Copyright (c) 2011-2016 David Demelier <markand@malikania.fr>
5 * 5 *
6 * Permission to use, copy, modify, and/or distribute this software for any 6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above 7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies. 8 * copyright notice and this permission notice appear in all copies.
9 * 9 *
20 #include <string.h> 20 #include <string.h>
21 21
22 char * 22 char *
23 strsep(char **stringp, const char *delim) 23 strsep(char **stringp, const char *delim)
24 { 24 {
25 char *item, *ptr; 25 char *item, *ptr;
26 26
27 if (*stringp == NULL || delim[0] == '\0') 27 if (*stringp == NULL || delim[0] == '\0')
28 return NULL; 28 return NULL;
29 29
30 item = *stringp; 30 item = *stringp;
31 if ((ptr = strpbrk(*stringp, delim)) == NULL) { 31 if ((ptr = strpbrk(*stringp, delim)) == NULL) {
32 *stringp = NULL; 32 *stringp = NULL;
33 return item; 33 return item;
34 } 34 }
35 35
36 *ptr = '\0'; 36 *ptr = '\0';
37 *stringp = ptr + 1; 37 *stringp = ptr + 1;
38 38
39 return item; 39 return item;
40 } 40 }