mirror of the now-defunct rocklinux.org
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.

92 lines
2.6 KiB

  1. # --- ROCK-COPYRIGHT-NOTE-BEGIN ---
  2. #
  3. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  4. # Please add additional copyright information _after_ the line containing
  5. # the ROCK-COPYRIGHT-NOTE-END tag. Otherwise it might get removed by
  6. # the ./scripts/Create-CopyPatch script. Do not edit this copyright text!
  7. #
  8. # ROCK Linux: rock-src/package/base/dietlibc/strnlen.patch
  9. # ROCK Linux is Copyright (C) 1998 - 2003 Clifford Wolf
  10. #
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; either version 2 of the License, or
  14. # (at your option) any later version. A copy of the GNU General Public
  15. # License can be found at Documentation/COPYING.
  16. #
  17. # Many people helped and are helping developing ROCK Linux. Please
  18. # have a look at http://www.rocklinux.org/ and the Documentation/TEAM
  19. # file for details.
  20. #
  21. # --- ROCK-COPYRIGHT-NOTE-END ---
  22. --- /dev/null Thu Jan 1 00:00:00 1970
  23. +++ ./lib/strnlen.c Fri Jan 10 23:54:35 2003
  24. @@ -0,0 +1,57 @@
  25. +#include <endian.h>
  26. +#include "dietfeatures.h"
  27. +#include <string.h>
  28. +
  29. +#ifdef WANT_SMALL_STRING_ROUTINES
  30. +size_t strnlen(const char *s, size_t maxlen) {
  31. + register size_t i;
  32. + if (!maxlen) return 0;
  33. + if (!s) return 0;
  34. + for (i=0; *s && i<maxlen; ++s) ++i;
  35. + return i;
  36. +}
  37. +#else
  38. +static const unsigned long magic = 0x01010101;
  39. +
  40. +size_t strnlen(const char *s, size_t maxlen)
  41. +{
  42. + const char *t = s;
  43. + const char *u = s + maxlen;
  44. + unsigned long word;
  45. +
  46. + if (!s) return 0;
  47. +
  48. + /* Byte compare up until word boundary */
  49. + for (; ((unsigned long) t & 3); t++)
  50. + if (!*t) {
  51. + if (t>u) t = u;
  52. + return t - s;
  53. + }
  54. +
  55. + /* Word compare */
  56. + do {
  57. + if (t>u) return maxlen;
  58. + word = *((unsigned long *) t); t += 4;
  59. + word = (word - magic) &~ word;
  60. + word &= (magic << 7);
  61. + } while (word == 0);
  62. +
  63. +#if BYTE_ORDER == LITTLE_ENDIAN
  64. + /* word & 0x80808080 == word */
  65. + word = (word - 1) & (magic << 10);
  66. + word += (word << 8) + (word << 16);
  67. + t += word >> 26;
  68. +#else
  69. + if ((word & 0x80800000) == 0) {
  70. + word <<= 16;
  71. + t += 2;
  72. + }
  73. + if ((word & 0x80000000) == 0) t += 1;
  74. +#endif
  75. + if (t-4 > u) {
  76. + return maxlen;
  77. + } else {
  78. + return ((const char *) t) - 4 - s;
  79. + }
  80. +}
  81. +#endif
  82. --- ./include/string.h~ Mon Jul 8 20:30:53 2002
  83. +++ ./include/string.h Sat Jan 11 00:03:10 2003
  84. @@ -35,6 +35,7 @@
  85. int strncasecmp(const char *s1, const char *s2, size_t n) __THROW __pure__;
  86. size_t strlen(const char *s) __THROW __pure__;
  87. +size_t strnlen(const char *s, size_t maxlen) __THROW __pure__;
  88. char *strstr(const char *haystack, const char *needle) __THROW __pure__;