alsa.audio: drop remaining buffer when closing
[AROS.git] / compiler / stdc / strtok.c
blob8ebe4ca8e2446efe622096ea78d31d085e5ed87c
1 /*
2 Copyright © 1995-2012, The AROS Development Team. All rights reserved.
3 $Id$
5 C99 function strtok().
6 */
8 #include "__stdc_intbase.h"
9 #include <aros/symbolsets.h>
11 /*****************************************************************************
13 NAME */
14 #include <string.h>
16 char * strtok (
18 /* SYNOPSIS */
19 char * str,
20 const char * sep)
22 /* FUNCTION
23 Separates a string by the characters in sep.
25 INPUTS
26 str - The string to check or NULL if the next word in
27 the last string is to be searched.
28 sep - Characters which separate "words" in str.
30 RESULT
31 The first word in str or the next one if str is NULL.
33 NOTES
34 The function changes str !
36 EXAMPLE
37 char buffer[64];
39 strcpy (buffer, "Hello, this is a test.");
41 // Init. Returns "Hello"
42 strtok (str, " \t,.");
44 // Next word. Returns "this"
45 strtok (NULL, " \t,.");
47 // Next word. Returns "is"
48 strtok (NULL, " \t");
50 // Next word. Returns "a"
51 strtok (NULL, " \t");
53 // Next word. Returns "test."
54 strtok (NULL, " \t");
56 // Next word. Returns NULL.
57 strtok (NULL, " \t");
59 BUGS
61 SEE ALSO
63 INTERNALS
65 ******************************************************************************/
67 struct StdCIntBase *StdCBase = (struct StdCIntBase *)__aros_getbase_StdCBase();
69 if (str != NULL)
70 StdCBase->last = str;
71 else
72 str = StdCBase->last;
74 str += strspn (str, sep);
76 if (*str == '\0')
77 return NULL;
79 StdCBase->last = str;
81 StdCBase->last += strcspn (str, sep);
83 if (*StdCBase->last != '\0')
84 *StdCBase->last ++ = '\0';
86 return str;
87 } /* strtok */
90 static int __strtok_init(struct StdCIntBase *StdCBase)
92 StdCBase->last = NULL;
94 return 1;
97 ADD2OPENLIB(__strtok_init, 0);