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