Use dgettext() instead of just gettext()
[platform/upstream/rpm.git] / system.h
1 /**
2  * \file system.h
3  */
4
5 #ifndef H_SYSTEM
6 #define H_SYSTEM
7
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif
11
12 #include <sys/types.h>
13
14 #include <sys/stat.h>
15 #include <stdio.h>
16
17 #ifdef HAVE_SYS_PARAM_H
18 #include <sys/param.h>
19 #endif
20
21 /* <unistd.h> should be included before any preprocessor test
22    of _POSIX_VERSION.  */
23 #ifdef HAVE_UNISTD_H
24 #include <unistd.h>
25 #if !defined(__GLIBC__)
26 #ifdef __APPLE__
27 #include <crt_externs.h>
28 #define environ (*_NSGetEnviron())
29 #else
30 extern char ** environ;
31 #endif /* __APPLE__ */
32 #endif
33 #endif
34
35 #if TIME_WITH_SYS_TIME
36 # include <sys/time.h>
37 # include <time.h>
38 #else
39 # if HAVE_SYS_TIME_H
40 #  include <sys/time.h>
41 # else
42 #  include <time.h>
43 # endif
44 #endif
45
46 #if NEED_TIMEZONE
47 extern time_t timezone;
48 #endif
49
50 /* Since major is a function on SVR4, we can't use `ifndef major'.  */
51 #if MAJOR_IN_MKDEV
52 #include <sys/mkdev.h>
53 #define HAVE_MAJOR
54 #endif
55 #if MAJOR_IN_SYSMACROS
56 #include <sys/sysmacros.h>
57 #define HAVE_MAJOR
58 #endif
59 #ifdef major                    /* Might be defined in sys/types.h.  */
60 #define HAVE_MAJOR
61 #endif
62
63 #ifndef HAVE_MAJOR
64 #define major(dev)  (((dev) >> 8) & 0xff)
65 #define minor(dev)  ((dev) & 0xff)
66 #define makedev(maj, min)  (((maj) << 8) | (min))
67 #endif
68 #undef HAVE_MAJOR
69
70 #ifdef HAVE_UTIME_H
71 #include <utime.h>
72 #endif
73
74 #ifdef HAVE_STRING_H
75 # if !STDC_HEADERS && HAVE_MEMORY_H
76 #  include <memory.h>
77 # endif
78 # include <string.h>
79 #else
80 # include <strings.h>
81 char *memchr ();
82 #endif
83
84 #if !defined(HAVE_STPCPY)
85 char * stpcpy(char * dest, const char * src);
86 #endif
87
88 #if !defined(HAVE_STPNCPY)
89 char * stpncpy(char * dest, const char * src, size_t n);
90 #endif
91
92 #include <errno.h>
93 #ifndef errno
94 extern int errno;
95 #endif
96
97 #if HAVE_ERROR && HAVE_ERROR_H
98 #include <error.h>
99 #endif
100
101 #if HAVE___SECURE_GETENV
102 #define getenv(_s)      __secure_getenv(_s)
103 #endif
104
105 #ifdef STDC_HEADERS
106 /* FIX: shrug */
107 #define getopt system_getopt
108 #include <stdlib.h>
109 #undef getopt
110 #else /* not STDC_HEADERS */
111 char *getenv (const char *name);
112 #if ! HAVE_REALPATH
113 char *realpath(const char *path, char resolved_path []);
114 #endif
115 #endif /* STDC_HEADERS */
116
117 /* XXX solaris2.5.1 has not */
118 #if !defined(EXIT_FAILURE)
119 #define EXIT_FAILURE    1
120 #endif
121
122 #ifdef HAVE_FCNTL_H
123 #include <fcntl.h>
124 #else
125 #include <sys/file.h>
126 #endif
127
128 #if !defined(SEEK_SET)
129 #define SEEK_SET 0
130 #define SEEK_CUR 1
131 #define SEEK_END 2
132 #endif
133 #if !defined(F_OK) 
134 #define F_OK 0
135 #define X_OK 1
136 #define W_OK 2
137 #define R_OK 4
138 #endif
139
140 #ifdef HAVE_DIRENT_H
141 # include <dirent.h>
142 # define NLENGTH(direct) (strlen((direct)->d_name))
143 #else /* not HAVE_DIRENT_H */
144 # define dirent direct
145 # define NLENGTH(direct) ((direct)->d_namlen)
146 # ifdef HAVE_SYS_NDIR_H
147 #  include <sys/ndir.h>
148 # endif /* HAVE_SYS_NDIR_H */
149 # ifdef HAVE_SYS_DIR_H
150 #  include <sys/dir.h>
151 # endif /* HAVE_SYS_DIR_H */
152 # ifdef HAVE_NDIR_H
153 #  include <ndir.h>
154 # endif /* HAVE_NDIR_H */
155 #endif /* HAVE_DIRENT_H */
156
157 #ifdef __GNUC__
158 # undef alloca
159 # define alloca __builtin_alloca
160 #else
161 # ifdef HAVE_ALLOCA_H
162 #  include <alloca.h>
163 # else
164 #  ifndef _AIX
165 /* AIX alloca decl has to be the first thing in the file, bletch! */
166 char *alloca ();
167 #  endif
168 # endif
169 #endif
170
171 #include <ctype.h>
172
173 #if HAVE_SYS_MMAN_H
174 #include <sys/mman.h>
175 #endif
176
177 /* XXX FIXME: popt on sunos4.1.3: <sys/resource.h> requires <sys/time.h> */
178 #if HAVE_SYS_RESOURCE_H && HAVE_SYS_TIME_H
179 #include <sys/resource.h>
180 #endif
181
182 #if HAVE_SYS_UTSNAME_H
183 #include <sys/utsname.h>
184 #endif
185
186 #if HAVE_SYS_WAIT_H
187 #include <sys/wait.h>
188 #endif
189
190 #if HAVE_GETOPT_H
191 #include <getopt.h>
192 #endif
193
194 #if HAVE_GRP_H
195 #include <grp.h>
196 #endif
197
198 #if HAVE_LIMITS_H
199 #include <limits.h>
200 #endif
201
202 #if HAVE_ERR_H
203 #include <err.h>
204 #endif
205
206 #if HAVE_MALLOC_H 
207 #include <malloc.h>
208 #endif
209
210 #if WITH_SELINUX
211 #include <selinux/selinux.h>
212 #else
213 typedef char * security_context_t;
214
215 #define freecon(_c)
216
217 #define getfilecon(_fn, _c)     (-1)
218 #define lgetfilecon(_fn, _c)    (-1)
219 #define fgetfilecon(_fd, _c)    (-1)
220
221 #define setfilecon(_fn, _c)     (-1)
222 #define lsetfilecon(_fn, _c)    (-1)
223 #define fsetfilecon(_fd, _c)    (-1)
224
225 #define security_check_context(_c)      (0)
226
227 #define is_selinux_enabled()    (-1)
228
229 #define matchpathcon_init(_fn)                  (-1)
230 #define matchpathcon_fini()                     (0)
231 #define matchpathcon(_fn, _fm, _c)              (-1)
232
233 #define rpm_execcon(_v, _fn, _av, _envp)        (0)
234 #endif
235
236 /**
237  * Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
238  * @param p             memory to free
239  * @return              NULL always
240  */
241 static inline
242 void * _free(const void * p)
243 {
244     if (p != NULL)      free((void *)p);
245     return NULL;
246 }
247
248
249 /* FIX: these are macros */
250 /**
251  */
252 void * xmalloc (size_t size);
253
254 /**
255  */
256 void * xcalloc (size_t nmemb, size_t size);
257
258 /**
259  * @todo Annotate ptr with returned/out.
260  */
261 void * xrealloc (void * ptr,
262                                         size_t size);
263
264 /**
265  */
266 char * xstrdup (const char *str);
267
268 /**
269  */
270 void * vmefail(size_t size);
271
272 #if HAVE_MCHECK_H
273 #include <mcheck.h>
274 /* Memory allocation via macro defs to get meaningful locations from mtrace() */
275 #if defined(__GNUC__)
276 #define xmalloc(_size)          (malloc(_size) ? : vmefail(_size))
277 #define xcalloc(_nmemb, _size)  (calloc((_nmemb), (_size)) ? : vmefail(_size))
278 #define xrealloc(_ptr, _size)   (realloc((_ptr), (_size)) ? : vmefail(_size))
279 #define xstrdup(_str)   (strcpy((malloc(strlen(_str)+1) ? : vmefail(strlen(_str)+1)), (_str)))
280 #endif  /* defined(__GNUC__) */
281 #endif  /* HAVE_MCHECK_H */
282
283 /* Retrofit glibc __progname */
284 #if defined __GLIBC__ && __GLIBC__ >= 2
285 #if __GLIBC_MINOR__ >= 1
286 #define __progname      __assert_program_name
287 #endif
288 #define setprogname(pn)
289 #else
290 #define __progname      program_name
291 #define setprogname(pn) \
292   { if ((__progname = strrchr(pn, '/')) != NULL) __progname++; \
293     else __progname = pn;               \
294   }
295 #endif
296 extern const char *__progname;
297
298 #if HAVE_NETDB_H
299 #include <netdb.h>
300 #endif
301
302 #if HAVE_PWD_H
303 #include <pwd.h>
304 #endif
305
306 /* Take care of NLS matters.  */
307
308 #if HAVE_LOCALE_H
309 # include <locale.h>
310 #endif
311 #if !HAVE_SETLOCALE
312 # define setlocale(Category, Locale) /* empty */
313 #endif
314
315 #if ENABLE_NLS
316 # include <libintl.h>
317 # define _(Text) dgettext (PACKAGE, Text)
318 #else
319 # undef bindtextdomain
320 # define bindtextdomain(Domain, Directory) /* empty */
321 # undef textdomain
322 # define textdomain(Domain) /* empty */
323 # define _(Text) Text
324 # undef dgettext
325 # define dgettext(DomainName, Text) Text
326 #endif
327
328 #define N_(Text) Text
329
330 /* ============== from misc/miscfn.h */
331
332 #if !defined(USE_GNU_GLOB) 
333 #if HAVE_FNMATCH_H
334 #include <fnmatch.h>
335 #endif
336
337 #if HAVE_GLOB_H 
338 #include <glob.h>
339 #endif
340 #else
341 #include "misc/glob.h"
342 #include "misc/fnmatch.h"
343 #endif
344
345 #if ! HAVE_S_IFSOCK
346 #define S_IFSOCK (0xc000)
347 #endif
348
349 #if ! HAVE_S_ISLNK
350 #define S_ISLNK(mode) ((mode & 0xf000) == S_IFLNK)
351 #endif
352
353 #if ! HAVE_S_ISSOCK
354 #define S_ISSOCK(mode) ((mode & 0xf000) == S_IFSOCK)
355 #endif
356
357 #if NEED_STRINGS_H
358 #include <strings.h>
359 #endif
360
361 #if NEED_MYREALLOC
362 #define realloc(ptr,size) myrealloc(ptr,size)
363 extern void *myrealloc(void *, size_t);
364 #endif
365
366 #if ! HAVE_SETENV
367 extern int setenv(const char *name, const char *value, int replace);
368 extern void unsetenv(const char *name);
369 #endif
370
371 #if HAVE_SYS_SOCKET_H
372 #include <sys/types.h>
373 #include <sys/socket.h>
374 #endif
375
376 #if HAVE_POLL_H
377 #include <poll.h>
378 #else
379 #if HAVE_SYS_SELECT_H
380 #include <sys/select.h>
381 #endif
382 #endif
383
384 /* Solaris <= 2.6 limits getpass return to only 8 chars */
385 #if HAVE_GETPASSPHRASE
386 #define getpass getpassphrase
387 #endif
388
389 #if ! HAVE_LCHOWN
390 #define lchown chown
391 #endif
392
393 #if HAVE_GETMNTINFO || HAVE_GETMNTINFO_R || HAVE_MNTCTL
394 # define GETMNTENT_ONE 0
395 # define GETMNTENT_TWO 0
396 # if HAVE_SYS_MNTCTL_H
397 #  include <sys/mntctl.h>
398 # endif
399 # if HAVE_SYS_VMOUNT_H
400 #  include <sys/vmount.h>
401 # endif
402 # if HAVE_SYS_MOUNT_H
403 #  include <sys/mount.h>
404 # endif
405 #elif HAVE_MNTENT_H || !(HAVE_GETMNTENT) || HAVE_STRUCT_MNTTAB
406 # if HAVE_MNTENT_H
407 #  include <stdio.h>
408 #  include <mntent.h>
409 #  define our_mntent struct mntent
410 #  define our_mntdir mnt_dir
411 # elif HAVE_STRUCT_MNTTAB
412 #  include <stdio.h>
413 #  include <mnttab.h>
414    struct our_mntent {
415        char * our_mntdir;
416    };
417    struct our_mntent *getmntent(FILE *filep);
418 #  define our_mntent struct our_mntent
419 # else
420 #  include <stdio.h>
421    struct our_mntent {
422        char * our_mntdir;
423    };
424    struct our_mntent *getmntent(FILE *filep);
425 #  define our_mntent struct our_mntent
426 # endif
427 # define GETMNTENT_ONE 1
428 # define GETMNTENT_TWO 0
429 #elif HAVE_SYS_MNTTAB_H
430 # include <stdio.h>
431 # include <sys/mnttab.h>
432 # define GETMNTENT_ONE 0
433 # define GETMNTENT_TWO 1
434 # define our_mntent struct mnttab
435 # define our_mntdir mnt_mountp
436 #else /* if !HAVE_MNTCTL */
437 # error Neither mntent.h, mnttab.h, or mntctl() exists. I cannot build on this system.
438 #endif
439
440 #ifndef MOUNTED
441 #define MOUNTED "/etc/mnttab"
442 #endif
443
444 #endif  /* H_SYSTEM */