1: /* Inline functions for rsync.
2: *
3: * Copyright (C) 2007-2020 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:
19: static inline void
20: alloc_xbuf(xbuf *xb, size_t sz)
21: {
22: xb->buf = new_array(char, sz);
23: xb->size = sz;
24: xb->len = xb->pos = 0;
25: }
26:
27: static inline void
28: realloc_xbuf(xbuf *xb, size_t sz)
29: {
30: char *bf = realloc_array(xb->buf, char, sz);
31: xb->buf = bf;
32: xb->size = sz;
33: }
34:
35: static inline void
36: free_xbuf(xbuf *xb)
37: {
38: if (xb->buf)
39: free(xb->buf);
40: memset(xb, 0, sizeof (xbuf));
41: }
42:
43: static inline int
44: to_wire_mode(mode_t mode)
45: {
46: #ifdef SUPPORT_LINKS
47: #if _S_IFLNK != 0120000
48: if (S_ISLNK(mode))
49: return (mode & ~(_S_IFMT)) | 0120000;
50: #endif
51: #endif
52: return mode;
53: }
54:
55: static inline mode_t
56: from_wire_mode(int mode)
57: {
58: #if _S_IFLNK != 0120000
59: if ((mode & (_S_IFMT)) == 0120000)
60: return (mode & ~(_S_IFMT)) | _S_IFLNK;
61: #endif
62: return mode;
63: }
64:
65: static inline char *
66: d_name(struct dirent *di)
67: {
68: #ifdef HAVE_BROKEN_READDIR
69: return (di->d_name - 2);
70: #else
71: return di->d_name;
72: #endif
73: }
74:
75: static inline void
76: init_stat_x(stat_x *sx_p)
77: {
78: #ifdef SUPPORT_ACLS
79: sx_p->acc_acl = sx_p->def_acl = NULL;
80: #endif
81: #ifdef SUPPORT_XATTRS
82: sx_p->xattr = NULL;
83: #endif
84: }
85:
86: static inline void
87: free_stat_x(stat_x *sx_p)
88: {
89: #ifdef SUPPORT_ACLS
90: {
91: extern int preserve_acls;
92: if (preserve_acls)
93: free_acl(sx_p);
94: }
95: #endif
96: #ifdef SUPPORT_XATTRS
97: {
98: extern int preserve_xattrs;
99: if (preserve_xattrs)
100: free_xattr(sx_p);
101: }
102: #endif
103: }
104:
105: static inline char *my_strdup(const char *str, const char *file, int line)
106: {
107: int len = strlen(str)+1;
108: char *buf = my_alloc(NULL, len, 1, file, line);
109: memcpy(buf, str, len);
110: return buf;
111: }
112:
113: static inline int
114: strEQ(const char *s1, const char *s2)
115: {
116: return strcmp(s1, s2) == 0;
117: }
118:
119: static inline int
120: strnEQ(const char *s1, const char *s2, size_t n)
121: {
122: return strncmp(s1, s2, n) == 0;
123: }
124:
125: static inline int
126: ic_strEQ(const char *s1, const char *s2)
127: {
128: extern int ignore_case;
129: if (ignore_case)
130: return strcasecmp(s1, s2) == 0;
131: return strcmp(s1, s2) == 0;
132: }
133:
134: static inline int
135: ic_strnEQ(const char *s1, const char *s2, size_t n)
136: {
137: extern int ignore_case;
138: if (ignore_case)
139: return strncasecmp(s1, s2, n) == 0;
140: return strncmp(s1, s2, n) == 0;
141: }
142:
143: #define strNE(s1,s2) (!strEQ(s1,s2))
144: #define strnNE(s1,s2,n) (!strnEQ(s1,s2,n))
145: #define ic_strNE(s1,s2) (!ic_strEQ(s1,s2))
146: #define ic_strnNE(s1,s2) (!ic_strnEQ(s1,s2,n))
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>