iPXE
stringextra.c
Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 1991, 1992  Linus Torvalds
00003  *  Copyright (C) 2004 Tobias Lorenz
00004  *
00005  *  string handling functions
00006  *  based on linux/lib/string.c
00007  *
00008  * This program is free software; you can redistribute it and/or modify
00009  * it under the terms of the GNU General Public License version 2 as
00010  * published by the Free Software Foundation.
00011  */
00012 
00013 FILE_LICENCE ( GPL2_ONLY );
00014 
00015 /*
00016  * stupid library routines.. The optimized versions should generally be found
00017  * as inline code in <asm-xx/string.h>
00018  *
00019  * These are buggy as well..
00020  *
00021  * * Fri Jun 25 1999, Ingo Oeser <ioe@informatik.tu-chemnitz.de>
00022  * -  Added strsep() which will replace strtok() soon (because strsep() is
00023  *    reentrant and should be faster). Use only strsep() in new code, please.
00024  */
00025 
00026 /*
00027  * these are the standard string functions that are currently not used by
00028  * any code in etherboot. put into a separate file to avoid linking them in
00029  * with the rest of string.o
00030  * if anything ever does want to use a function of these, consider moving
00031  * the function in question back into string.c
00032  */
00033  
00034 #include <stdint.h>
00035 #include <stdlib.h>
00036 #include <string.h>
00037 #include <ctype.h>
00038 
00039 /* *** FROM string.c *** */
00040 
00041 #ifndef __HAVE_ARCH_STRPBRK
00042 /**
00043  * strpbrk - Find the first occurrence of a set of characters
00044  * @cs: The string to be searched
00045  * @ct: The characters to search for
00046  */
00047 char * strpbrk(const char * cs,const char * ct)
00048 {
00049         const char *sc1,*sc2;
00050 
00051         for( sc1 = cs; *sc1 != '\0'; ++sc1) {
00052                 for( sc2 = ct; *sc2 != '\0'; ++sc2) {
00053                         if (*sc1 == *sc2)
00054                                 return (char *) sc1;
00055                 }
00056         }
00057         return NULL;
00058 }
00059 #endif
00060 
00061 #ifndef __HAVE_ARCH_STRSEP
00062 /**
00063  * strsep - Split a string into tokens
00064  * @s: The string to be searched
00065  * @ct: The characters to search for
00066  *
00067  * strsep() updates @s to point after the token, ready for the next call.
00068  *
00069  * It returns empty tokens, too, behaving exactly like the libc function
00070  * of that name. In fact, it was stolen from glibc2 and de-fancy-fied.
00071  * Same semantics, slimmer shape. ;)
00072  */
00073 char * strsep(char **s, const char *ct)
00074 {
00075         char *sbegin = *s, *end;
00076 
00077         if (sbegin == NULL)
00078                 return NULL;
00079 
00080         end = strpbrk(sbegin, ct);
00081         if (end)
00082                 *end++ = '\0';
00083         *s = end;
00084 
00085         return sbegin;
00086 }
00087 #endif