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