| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 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 |
sx_p->crtime = 0; |
| 79 |
#ifdef SUPPORT_ACLS |
| 80 |
sx_p->acc_acl = sx_p->def_acl = NULL; |
| 81 |
#endif |
| 82 |
#ifdef SUPPORT_XATTRS |
| 83 |
sx_p->xattr = NULL; |
| 84 |
#endif |
| 85 |
} |
| 86 |
|
| 87 |
static inline void |
| 88 |
free_stat_x(stat_x *sx_p) |
| 89 |
{ |
| 90 |
#ifdef SUPPORT_ACLS |
| 91 |
{ |
| 92 |
extern int preserve_acls; |
| 93 |
if (preserve_acls) |
| 94 |
free_acl(sx_p); |
| 95 |
} |
| 96 |
#endif |
| 97 |
#ifdef SUPPORT_XATTRS |
| 98 |
{ |
| 99 |
extern int preserve_xattrs; |
| 100 |
if (preserve_xattrs) |
| 101 |
free_xattr(sx_p); |
| 102 |
} |
| 103 |
#endif |
| 104 |
} |
| 105 |
|
| 106 |
static inline char *my_strdup(const char *str, const char *file, int line) |
| 107 |
{ |
| 108 |
int len = strlen(str)+1; |
| 109 |
char *buf = my_alloc(NULL, len, 1, file, line); |
| 110 |
memcpy(buf, str, len); |
| 111 |
return buf; |
| 112 |
} |