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.

strings.h 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #ifndef _STRINGS_H
  2. #define _STRINGS_H
  3. #include <limits.h>
  4. #include <string.h>
  5. static inline __attribute__ (( always_inline )) int
  6. __constant_flsl ( unsigned long x ) {
  7. int r = 0;
  8. #if ULONG_MAX > 0xffffffff
  9. if ( x & 0xffffffff00000000UL ) {
  10. x >>= 32;
  11. r += 32;
  12. }
  13. #endif
  14. if ( x & 0xffff0000UL ) {
  15. x >>= 16;
  16. r += 16;
  17. }
  18. if ( x & 0xff00 ) {
  19. x >>= 8;
  20. r += 8;
  21. }
  22. if ( x & 0xf0 ) {
  23. x >>= 4;
  24. r += 4;
  25. }
  26. if ( x & 0xc ) {
  27. x >>= 2;
  28. r += 2;
  29. }
  30. if ( x & 0x2 ) {
  31. x >>= 1;
  32. r += 1;
  33. }
  34. if ( x & 0x1 ) {
  35. r += 1;
  36. }
  37. return r;
  38. }
  39. /* We don't actually have these functions yet */
  40. extern int __flsl ( long x );
  41. #define flsl( x ) \
  42. ( __builtin_constant_p ( x ) ? __constant_flsl ( x ) : __flsl ( x ) )
  43. #define fls( x ) flsl ( x )
  44. extern int strcasecmp ( const char *s1, const char *s2 );
  45. static inline __attribute__ (( always_inline )) void
  46. bcopy ( const void *src, void *dest, size_t n ) {
  47. memmove ( dest, src, n );
  48. }
  49. static inline __attribute__ (( always_inline )) void
  50. bzero ( void *s, size_t n ) {
  51. memset ( s, 0, n );
  52. }
  53. #endif /* _STRINGS_H */