sigh, vasnprintf changed in gnulib
[gnulib.git] / lib / strsep.c
1 /* Copyright (C) 2004 Free Software Foundation, Inc.
2  * Written by Yoann Vandoorselaere <yoann@prelude-ids.org>
3  *
4  * The file is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This file is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this file; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17  * USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #include <config.h>
22 #endif
23
24 /* Specification.  */
25 #include "strsep.h"
26
27 #include <string.h>
28
29 #include "strpbrk.h"
30
31 char *
32 strsep (char **stringp, const char *delim)
33 {
34   char *start = *stringp;
35   char *ptr;
36
37   if (!start)
38     return NULL;
39
40   if (!*delim)
41     ptr = start + strlen (start);
42   else
43     {
44       ptr = strpbrk (start, delim);
45       if (!ptr)
46         {
47           *stringp = NULL;
48           return start;
49         }
50     }
51
52   *ptr = '\0';
53   *stringp = ptr + 1;
54
55   return start;
56 }