]> err.no Git - backuppcd/blob - compat.h
Import gnulib stuff
[backuppcd] / compat.h
1 /*
2  * Copyright (C) 2005  Roy Keene
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17  *
18  * Author Information
19  *      Roy Keene
20  *      Planning Systems Inc
21  *      Slidell, LA
22  *      backuppcd-bugs@psislidell.com
23  */
24
25 #ifndef HAVE_HTONLL
26 #include <endian.h>
27 #ifdef _BIG_ENDIAN
28 htonll(x)   (x)
29 #else
30 #define htonll(x)   ((((uint64_t)htonl(x)) << 32) + htonl(x >> 32))
31 #endif
32 #endif
33
34 #ifndef HAVE_NTOHLL
35 #include <endian.h>
36 #ifdef _BIG_ENDIAN
37 #define ntohll(x)   (x)
38 #else
39 #define ntohll(x)   ((((uint64_t)ntohl(x)) << 32) + ntohl(x >> 32))
40 #endif
41 #endif
42
43 #ifndef RSK_COMPAT_H
44 #define RSK_COMPAT_H
45
46 #ifdef HAVE_CONFIG_H
47 #include <config.h>
48 #endif
49 #ifdef __WIN32__
50 #include "win32.h"
51 #endif
52
53 #ifdef HAVE_INTTYPES_H
54 #include <inttypes.h>
55 #endif
56 #ifdef HAVE_MEMORY_H
57 #include <memory.h>
58 #endif
59 #ifdef HAVE_STDINT_H
60 #include <stdint.h>
61 #endif
62 #ifdef HAVE_STDLIB_H
63 #include <stdlib.h>
64 #endif
65 #ifdef HAVE_STRINGS_H
66 #include <strings.h>
67 #endif
68 #ifdef HAVE_STRING_H
69 #include <string.h>
70 #endif
71 #ifdef HAVE_SYS_STAT_H
72 #include <sys/stat.h>
73 #endif
74 #ifdef HAVE_SYS_TYPES_H
75 #include <sys/types.h>
76 #endif
77 #ifdef HAVE_UNISTD_H
78 #include <unistd.h>
79 #endif
80 #ifdef HAVE_ERRNO_H
81 #include <errno.h>
82 #endif
83 #ifdef HAVE_FCNTL_H
84 #include <fcntl.h>
85 #endif
86 #ifdef HAVE_NETDB_H
87 #include <netdb.h>
88 #endif
89 #ifdef HAVE_NETINET_IN_H
90 #include <netinet/in.h>
91 #endif
92 #ifdef HAVE_STDARG_H
93 #include <stdarg.h>
94 #endif
95 #ifdef HAVE_SYS_SOCKET_H
96 #include <sys/socket.h>
97 #endif
98 #ifdef HAVE_SYS_STATFS_H
99 #include <sys/statfs.h>
100 #else
101 #ifdef HAVE_SYS_VFS_H
102 #include <sys/vfs.h>
103 #endif
104 #endif
105 #ifdef HAVE_SYS_RESOURCE_H
106 #include <sys/resource.h>
107 #endif
108 #ifdef TIME_WITH_SYS_TIME
109 #include <sys/time.h>
110 #include <time.h>
111 #else
112 #ifdef HAVE_SYS_TIME_H
113 #include <sys/time.h>
114 #else
115 #include <time.h>
116 #endif
117 #endif
118
119 #ifndef HAVE_SOCKLEN_T
120 #ifdef NEED_SOCKLEN_T
121 typedef int socklen_t;
122 #endif
123 #endif
124
125
126 #ifndef HAVE_STRSEP
127 #include "strsep.h"
128 #endif
129
130 #ifndef HAVE_GETHOSTNAME
131 #include "gethostname.h"
132 #endif
133
134 #ifdef HAVE_STATFS
135 /*
136  * These constants are used to determine the filesystem type from statfs().
137  * Only used under Linux as other statfs() implementations return ftype == 0.
138  */
139 #ifndef NFS_SUPER_MAGIC
140 #define NFS_SUPER_MAGIC   0x6969
141 #endif
142 #ifndef PROC_SUPER_MAGIC
143 #define PROC_SUPER_MAGIC  0x9fa0
144 #endif
145 #ifndef DEVFS_SUPER_MAGIC
146 #define DEVFS_SUPER_MAGIC 0x1373
147 #endif
148 #ifndef ISOFS_SUPER_MAGIC
149 #define ISOFS_SUPER_MAGIC 0x9660
150 #endif
151 #ifndef NCP_SUPER_MAGIC
152 #define NCP_SUPER_MAGIC   0x564c
153 #endif
154 #ifndef SMB_SUPER_MAGIC
155 #define SMB_SUPER_MAGIC   0x517B
156 #endif
157 #ifndef TMPFS_MAGIC
158 #define TMPFS_MAGIC       0x01021994
159 #endif
160 #endif
161
162
163
164 #ifdef DEBUG
165 #define PRINT_LINE fprintf(stderr, "%lu:%s:%i:%s(): ", (unsigned long) time(NULL), __FILE__, __LINE__, __func__); 
166 #define PRINTERR_D(x...) { PRINT_LINE; fprintf(stderr, x); fprintf(stderr, "\n"); }
167 #define PERROR(x) { PRINT_LINE; perror(x); }
168 #define DPERROR(x) PERROR(x)
169 #define DPRINTF(x...) { PRINT_LINE; fprintf(stderr, x); fprintf(stderr, "\n"); }
170 #else
171 #define PRINT_LINE /**/
172 #define PRINTERR_D(x...) /**/
173 #define PERROR(x) perror(x);
174 #define DPERROR(x) /**/
175 #endif
176 #define CHECKPOINT PRINTERR_D("*** CHECKPOINT REACHED ***")
177 #define SPOTVAR_LLX(x) PRINTERR_D(#x " = %llx", (unsigned long long) x)
178 #define SPOTVAR_LLU(x) PRINTERR_D(#x " = %llu", (unsigned long long) x)
179 #define SPOTVAR_LU(x) PRINTERR_D(#x " = %lu", (unsigned long) x)
180 #define SPOTVAR_D(x) PRINTERR_D(#x " = %lf", x)
181 #define SPOTVAR_X(x) PRINTERR_D(#x " = 0x%x", (unsigned int) x)
182 #define SPOTVAR_I(x) PRINTERR_D(#x " = %i", (int) x)
183 #define SPOTVAR_P(x) PRINTERR_D(#x " = %p", x)
184 #define SPOTVAR_S(x) PRINTERR_D(#x " = \"%s\"", x)
185 #define PRINTERR(x...) { PRINT_LINE; fprintf(stderr, x); fprintf(stderr, "\n"); fflush(stderr); }
186 #define LOG(x...) { PRINT_LINE; fprintf(stderr, "LOG: " x); fprintf(stderr, "\n"); }
187
188 #endif