arch/m68k-amiga: Define the gcc symbol 'start' instead of using .bss
[AROS.git] / compiler / clib / strsep.c
blob5f244d60cb21cc70d662b397b2b0cc615b6fe5b9
1 /*
2 Copyright © 2004, The AROS Development Team. All rights reserved.
3 $Id$
5 BSD function strsep().
6 */
8 #include <stdio.h>
10 /*****************************************************************************
12 NAME */
13 #include <string.h>
15 char * strsep (
17 /* SYNOPSIS */
18 char ** strptr,
19 const char * sep)
21 /* FUNCTION
22 Separates a string by the characters in sep.
24 INPUTS
25 str - The string to check or NULL if the next word in
26 the last string is to be searched.
27 sep - Characters which separate "words" in str.
29 RESULT
30 The first word in str or the next one if str is NULL.
32 NOTES
33 The function changes str !
35 EXAMPLE
36 char buffer[64];
37 char **bufptr
39 strcpy (buffer, "Hello, this is a test.");
40 *bufptr = buffer
42 // First word. Returns "Hello"
43 strtok (bufptr, " \t,.");
45 // Next word. Returns "this"
46 strtok (bufptr, " \t,.");
48 // Next word. Returns "is"
49 strtok (bufptr, " \t");
51 // Next word. Returns "a"
52 strtok (bufptr, " \t");
54 // Next word. Returns "test."
55 strtok (bufptr, " \t");
57 // Next word. Returns NULL.
58 strtok (bufptr, " \t");
60 BUGS
62 SEE ALSO
64 INTERNALS
66 ******************************************************************************/
68 char * retval;
70 if (*strptr == NULL)
71 return NULL;
73 *strptr += strspn (*strptr, sep);
75 if (**strptr == '\0')
77 *strptr = NULL;
78 return NULL;
80 else
81 retval = *strptr;
83 *strptr += strcspn (*strptr, sep);
85 if (**strptr != '\0')
86 *(*strptr) ++ = '\0';
87 else
88 *strptr = NULL;
90 return retval;
91 } /* strsep */