ifuncs.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* Inline functions for rsync.
  2. *
  3. * Copyright (C) 2007-2008 Wayne Davison
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, visit the http://fsf.org website.
  17. */
  18. static inline void
  19. alloc_xbuf(xbuf *xb, size_t sz)
  20. {
  21. if (!(xb->buf = new_array(char, sz)))
  22. out_of_memory("alloc_xbuf");
  23. xb->size = sz;
  24. xb->len = xb->pos = 0;
  25. }
  26. static inline void
  27. realloc_xbuf(xbuf *xb, size_t sz)
  28. {
  29. char *bf = realloc_array(xb->buf, char, sz);
  30. if (!bf)
  31. out_of_memory("realloc_xbuf");
  32. xb->buf = bf;
  33. xb->size = sz;
  34. }
  35. static inline int
  36. to_wire_mode(mode_t mode)
  37. {
  38. #ifdef SUPPORT_LINKS
  39. #if _S_IFLNK != 0120000
  40. if (S_ISLNK(mode))
  41. return (mode & ~(_S_IFMT)) | 0120000;
  42. #endif
  43. #endif
  44. return mode;
  45. }
  46. static inline mode_t
  47. from_wire_mode(int mode)
  48. {
  49. #if _S_IFLNK != 0120000
  50. if ((mode & (_S_IFMT)) == 0120000)
  51. return (mode & ~(_S_IFMT)) | _S_IFLNK;
  52. #endif
  53. return mode;
  54. }
  55. static inline char *
  56. d_name(struct dirent *di)
  57. {
  58. #ifdef HAVE_BROKEN_READDIR
  59. return (di->d_name - 2);
  60. #else
  61. return di->d_name;
  62. #endif
  63. }
  64. static inline int
  65. isDigit(const char *ptr)
  66. {
  67. return isdigit(*(unsigned char *)ptr);
  68. }
  69. static inline int
  70. isPrint(const char *ptr)
  71. {
  72. return isprint(*(unsigned char *)ptr);
  73. }
  74. static inline int
  75. isSpace(const char *ptr)
  76. {
  77. return isspace(*(unsigned char *)ptr);
  78. }
  79. static inline int
  80. isLower(const char *ptr)
  81. {
  82. return islower(*(unsigned char *)ptr);
  83. }
  84. static inline int
  85. isUpper(const char *ptr)
  86. {
  87. return isupper(*(unsigned char *)ptr);
  88. }
  89. static inline int
  90. toLower(const char *ptr)
  91. {
  92. return tolower(*(unsigned char *)ptr);
  93. }
  94. static inline int
  95. toUpper(const char *ptr)
  96. {
  97. return toupper(*(unsigned char *)ptr);
  98. }