1 /* Inline functions for rsync.
3 * Copyright (C) 2007-2008 Wayne Davison
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.
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.
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.
20 alloc_xbuf(xbuf *xb, size_t sz)
22 if (!(xb->buf = new_array(char, sz)))
23 out_of_memory("alloc_xbuf");
25 xb->len = xb->pos = 0;
29 realloc_xbuf(xbuf *xb, size_t sz)
31 char *bf = realloc_array(xb->buf, char, sz);
33 out_of_memory("realloc_xbuf");
39 to_wire_mode(mode_t mode)
42 #if _S_IFLNK != 0120000
44 return (mode & ~(_S_IFMT)) | 0120000;
51 from_wire_mode(int mode)
53 #if _S_IFLNK != 0120000
54 if ((mode & (_S_IFMT)) == 0120000)
55 return (mode & ~(_S_IFMT)) | _S_IFLNK;
61 d_name(struct dirent *di)
63 #ifdef HAVE_BROKEN_READDIR
64 return (di->d_name - 2);
73 return do_big_num(num, 0, NULL);
79 extern int human_readable;
80 return do_big_num(num, human_readable != 0, NULL);
86 extern int human_readable;
87 return do_big_num(num, human_readable, NULL);
91 big_dnum(double dnum, int decimal_digits)
93 return do_big_dnum(dnum, 0, decimal_digits);
97 comma_dnum(double dnum, int decimal_digits)
99 extern int human_readable;
100 return do_big_dnum(dnum, human_readable != 0, decimal_digits);
104 human_dnum(double dnum, int decimal_digits)
106 extern int human_readable;
107 return do_big_dnum(dnum, human_readable, decimal_digits);
111 isDigit(const char *ptr)
113 return isdigit(*(unsigned char *)ptr);
117 isPrint(const char *ptr)
119 return isprint(*(unsigned char *)ptr);
123 isSpace(const char *ptr)
125 return isspace(*(unsigned char *)ptr);
129 isLower(const char *ptr)
131 return islower(*(unsigned char *)ptr);
135 isUpper(const char *ptr)
137 return isupper(*(unsigned char *)ptr);
141 toLower(const char *ptr)
143 return tolower(*(unsigned char *)ptr);
147 toUpper(const char *ptr)
149 return toupper(*(unsigned char *)ptr);