Add plugin calling support
[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 #ifdef HAVE_SYS_PARAM_H
13 #include <sys/param.h>
14 #endif
15
16 /* <unistd.h> should be included before any preprocessor test
17    of _POSIX_VERSION.  */
18 #ifdef HAVE_UNISTD_H
19 #include <unistd.h>
20 #if !defined(__GLIBC__)
21 #ifdef __APPLE__
22 #include <crt_externs.h>
23 #define environ (*_NSGetEnviron())
24 #else
25 extern char ** environ;
26 #endif /* __APPLE__ */
27 #endif
28 #endif
29
30 #if !defined(HAVE_STPCPY)
31 char * stpcpy(char * dest, const char * src);
32 #endif
33
34 #if !defined(HAVE_STPNCPY)
35 char * stpncpy(char * dest, const char * src, size_t n);
36 #endif
37
38 #if HAVE___SECURE_GETENV
39 #define getenv(_s)      __secure_getenv(_s)
40 #endif
41
42 #ifdef HAVE_FCNTL_H
43 #include <fcntl.h>
44 #else
45 #include <sys/file.h>
46 #endif
47
48 #ifdef HAVE_DIRENT_H
49 # include <dirent.h>
50 # define NLENGTH(direct) (strlen((direct)->d_name))
51 #else /* not HAVE_DIRENT_H */
52 # define dirent direct
53 # define NLENGTH(direct) ((direct)->d_namlen)
54 # ifdef HAVE_SYS_NDIR_H
55 #  include <sys/ndir.h>
56 # endif /* HAVE_SYS_NDIR_H */
57 # ifdef HAVE_SYS_DIR_H
58 #  include <sys/dir.h>
59 # endif /* HAVE_SYS_DIR_H */
60 # ifdef HAVE_NDIR_H
61 #  include <ndir.h>
62 # endif /* HAVE_NDIR_H */
63 #endif /* HAVE_DIRENT_H */
64
65 #if HAVE_LIMITS_H
66 #include <limits.h>
67 #endif
68
69 #ifndef PATH_MAX
70 #ifdef _POSIX_PATH_MAX
71 #define PATH_MAX _POSIX_PATH_MAX
72 #elif defined MAXPATHLEN
73 #define PATH_MAX MAXPATHLEN
74 #else
75 #define PATH_MAX 256
76 #endif
77 #endif
78
79 #if WITH_SELINUX
80 #include <selinux/selinux.h>
81 #else
82 typedef char * security_context_t;
83
84 #define freecon(_c)
85
86 #define setfilecon(_fn, _c)     (-1)
87 #define lsetfilecon(_fn, _c)    (-1)
88
89 #define is_selinux_enabled()    (0)
90
91 #define matchpathcon_init(_fn)                  (-1)
92 #define matchpathcon_fini()                     (0)
93 #define matchpathcon(_fn, _fm, _c)              (-1)
94
95 #define rpm_execcon(_v, _fn, _av, _envp)        (0)
96 #endif
97
98 #include "rpmio/rpmutil.h"
99 /* compatibility macros to avoid a mass-renaming all over the codebase */
100 #define xmalloc(_size) rmalloc((_size))
101 #define xcalloc(_nmemb, _size) rcalloc((_nmemb), (_size))
102 #define xrealloc(_ptr, _size) rrealloc((_ptr), (_size))
103 #define xstrdup(_str) rstrdup((_str))
104 #define _free(_ptr) rfree((_ptr))
105
106 /* Retrofit glibc __progname */
107 #if defined __GLIBC__ && __GLIBC__ >= 2
108 #if __GLIBC_MINOR__ >= 1
109 #define __progname      __assert_program_name
110 #endif
111 #define setprogname(pn)
112 #else
113 #define __progname      program_name
114 #define setprogname(pn) \
115   { if ((__progname = strrchr(pn, '/')) != NULL) __progname++; \
116     else __progname = pn;               \
117   }
118 #endif
119 extern const char *__progname;
120
121 /* Take care of NLS matters.  */
122 #if ENABLE_NLS
123 # include <locale.h>
124 # include <libintl.h>
125 # define _(Text) dgettext (PACKAGE, Text)
126 #else
127 # define _(Text) Text
128 #endif
129
130 #define N_(Text) Text
131
132 /* ============== from misc/miscfn.h */
133
134 #if !defined(USE_GNU_GLOB) 
135 #if HAVE_FNMATCH_H
136 #include <fnmatch.h>
137 #endif
138
139 #if HAVE_GLOB_H 
140 #include <glob.h>
141 #endif
142 #else
143 #include "misc/glob.h"
144 #include "misc/fnmatch.h"
145 #endif
146
147 #include <dlfcn.h>
148
149 #endif  /* H_SYSTEM */