Moving inline functions into its own .h file.
[rsync/rsync.git] / ifuncs.h
1 /* Inline functions. */
2
3 static inline void
4 alloc_xbuf(xbuf *xb, size_t sz)
5 {
6         if (!(xb->buf = new_array(char, sz)))
7                 out_of_memory("alloc_xbuf");
8         xb->size = sz;
9         xb->len = xb->pos = 0;
10 }
11
12 static inline void
13 realloc_xbuf(xbuf *xb, size_t sz)
14 {
15         char *bf = realloc_array(xb->buf, char, sz);
16         if (!bf)
17                 out_of_memory("realloc_xbuf");
18         xb->buf = bf;
19         xb->size = sz;
20 }
21
22 static inline int
23 to_wire_mode(mode_t mode)
24 {
25 #ifdef SUPPORT_LINKS
26 #if _S_IFLNK != 0120000
27         if (S_ISLNK(mode))
28                 return (mode & ~(_S_IFMT)) | 0120000;
29 #endif
30 #endif
31         return mode;
32 }
33
34 static inline mode_t
35 from_wire_mode(int mode)
36 {
37 #if _S_IFLNK != 0120000
38         if ((mode & (_S_IFMT)) == 0120000)
39                 return (mode & ~(_S_IFMT)) | _S_IFLNK;
40 #endif
41         return mode;
42 }
43
44 static inline int
45 isDigit(const char *ptr)
46 {
47         return isdigit(*(unsigned char *)ptr);
48 }
49
50 static inline int
51 isPrint(const char *ptr)
52 {
53         return isprint(*(unsigned char *)ptr);
54 }
55
56 static inline int
57 isSpace(const char *ptr)
58 {
59         return isspace(*(unsigned char *)ptr);
60 }
61
62 static inline int
63 isLower(const char *ptr)
64 {
65         return islower(*(unsigned char *)ptr);
66 }
67
68 static inline int
69 isUpper(const char *ptr)
70 {
71         return isupper(*(unsigned char *)ptr);
72 }
73
74 static inline int
75 toLower(const char *ptr)
76 {
77         return tolower(*(unsigned char *)ptr);
78 }
79
80 static inline int
81 toUpper(const char *ptr)
82 {
83         return toupper(*(unsigned char *)ptr);
84 }