x11gfx.hidd: support 32 bit modes
[AROS.git] / compiler / stdc / strsep.c
blobc67bbfe983b23075349db81222345493f6436fc1
1 /*
2 Copyright © 2004-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 BSD function strsep().
6 */
8 /*****************************************************************************
10 NAME */
11 #include <string.h>
13 char * strsep (
15 /* SYNOPSIS */
16 char ** strptr,
17 const char * sep)
19 /* FUNCTION
20 Separates a string by the characters in sep.
22 INPUTS
23 str - The string to check or NULL if the next word in
24 the last string is to be searched.
25 sep - Characters which separate "words" in str.
27 RESULT
28 The first word in str or the next one if str is NULL.
30 NOTES
31 The function changes str !
33 EXAMPLE
34 char buffer[64];
35 char **bufptr
37 strcpy (buffer, "Hello, this is a test.");
38 *bufptr = buffer
40 // First word. Returns "Hello"
41 strtok (bufptr, " \t,.");
43 // Next word. Returns "this"
44 strtok (bufptr, " \t,.");
46 // Next word. Returns "is"
47 strtok (bufptr, " \t");
49 // Next word. Returns "a"
50 strtok (bufptr, " \t");
52 // Next word. Returns "test."
53 strtok (bufptr, " \t");
55 // Next word. Returns NULL.
56 strtok (bufptr, " \t");
58 BUGS
60 SEE ALSO
62 INTERNALS
64 ******************************************************************************/
66 char * retval;
68 if (*strptr == NULL)
69 return NULL;
71 *strptr += strspn (*strptr, sep);
73 if (**strptr == '\0')
75 *strptr = NULL;
76 return NULL;
78 else
79 retval = *strptr;
81 *strptr += strcspn (*strptr, sep);
83 if (**strptr != '\0')
84 *(*strptr) ++ = '\0';
85 else
86 *strptr = NULL;
88 return retval;
89 } /* strsep */