You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

stringextra.c 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. FILE_LICENCE ( GPL2_ONLY );
  13. /*
  14. * stupid library routines.. The optimized versions should generally be found
  15. * as inline code in <asm-xx/string.h>
  16. *
  17. * These are buggy as well..
  18. *
  19. * * Fri Jun 25 1999, Ingo Oeser <ioe@informatik.tu-chemnitz.de>
  20. * - Added strsep() which will replace strtok() soon (because strsep() is
  21. * reentrant and should be faster). Use only strsep() in new code, please.
  22. */
  23. /*
  24. * these are the standard string functions that are currently not used by
  25. * any code in etherboot. put into a separate file to avoid linking them in
  26. * with the rest of string.o
  27. * if anything ever does want to use a function of these, consider moving
  28. * the function in question back into string.c
  29. */
  30. #include <stdint.h>
  31. #include <stdlib.h>
  32. #include <string.h>
  33. #include <ctype.h>
  34. /* *** FROM string.c *** */
  35. #ifndef __HAVE_ARCH_STRPBRK
  36. /**
  37. * strpbrk - Find the first occurrence of a set of characters
  38. * @cs: The string to be searched
  39. * @ct: The characters to search for
  40. */
  41. char * strpbrk(const char * cs,const char * ct)
  42. {
  43. const char *sc1,*sc2;
  44. for( sc1 = cs; *sc1 != '\0'; ++sc1) {
  45. for( sc2 = ct; *sc2 != '\0'; ++sc2) {
  46. if (*sc1 == *sc2)
  47. return (char *) sc1;
  48. }
  49. }
  50. return NULL;
  51. }
  52. #endif
  53. #ifndef __HAVE_ARCH_STRSEP
  54. /**
  55. * strsep - Split a string into tokens
  56. * @s: The string to be searched
  57. * @ct: The characters to search for
  58. *
  59. * strsep() updates @s to point after the token, ready for the next call.
  60. *
  61. * It returns empty tokens, too, behaving exactly like the libc function
  62. * of that name. In fact, it was stolen from glibc2 and de-fancy-fied.
  63. * Same semantics, slimmer shape. ;)
  64. */
  65. char * strsep(char **s, const char *ct)
  66. {
  67. char *sbegin = *s, *end;
  68. if (sbegin == NULL)
  69. return NULL;
  70. end = strpbrk(sbegin, ct);
  71. if (end)
  72. *end++ = '\0';
  73. *s = end;
  74. return sbegin;
  75. }
  76. #endif