These changes are the raw update to qemu-2.6.
[kvmfornfv.git] / qemu / roms / ipxe / src / core / stringextra.c
1 /*
2  *  Copyright (C) 1991, 1992  Linus Torvalds
3  *  Copyright (C) 2004 Tobias Lorenz
4  *
5  *  string handling functions
6  *  based on linux/lib/string.c
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation.
11  */
12
13 FILE_LICENCE ( GPL2_ONLY );
14
15 /*
16  * stupid library routines.. The optimized versions should generally be found
17  * as inline code in <asm-xx/string.h>
18  *
19  * These are buggy as well..
20  *
21  * * Fri Jun 25 1999, Ingo Oeser <ioe@informatik.tu-chemnitz.de>
22  * -  Added strsep() which will replace strtok() soon (because strsep() is
23  *    reentrant and should be faster). Use only strsep() in new code, please.
24  */
25
26 /*
27  * these are the standard string functions that are currently not used by
28  * any code in etherboot. put into a separate file to avoid linking them in
29  * with the rest of string.o
30  * if anything ever does want to use a function of these, consider moving
31  * the function in question back into string.c
32  */
33  
34 #include <stdint.h>
35 #include <stdlib.h>
36 #include <string.h>
37 #include <ctype.h>
38
39 /* *** FROM string.c *** */
40
41 #ifndef __HAVE_ARCH_STRPBRK
42 /**
43  * strpbrk - Find the first occurrence of a set of characters
44  * @cs: The string to be searched
45  * @ct: The characters to search for
46  */
47 char * strpbrk(const char * cs,const char * ct)
48 {
49         const char *sc1,*sc2;
50
51         for( sc1 = cs; *sc1 != '\0'; ++sc1) {
52                 for( sc2 = ct; *sc2 != '\0'; ++sc2) {
53                         if (*sc1 == *sc2)
54                                 return (char *) sc1;
55                 }
56         }
57         return NULL;
58 }
59 #endif
60
61 #ifndef __HAVE_ARCH_STRSEP
62 /**
63  * strsep - Split a string into tokens
64  * @s: The string to be searched
65  * @ct: The characters to search for
66  *
67  * strsep() updates @s to point after the token, ready for the next call.
68  *
69  * It returns empty tokens, too, behaving exactly like the libc function
70  * of that name. In fact, it was stolen from glibc2 and de-fancy-fied.
71  * Same semantics, slimmer shape. ;)
72  */
73 char * strsep(char **s, const char *ct)
74 {
75         char *sbegin = *s, *end;
76
77         if (sbegin == NULL)
78                 return NULL;
79
80         end = strpbrk(sbegin, ct);
81         if (end)
82                 *end++ = '\0';
83         *s = end;
84
85         return sbegin;
86 }
87 #endif