2000-12-13 04:03:45 +08:00
|
|
|
/**
|
|
|
|
* \file system.h
|
|
|
|
*/
|
1998-07-26 05:00:26 +08:00
|
|
|
|
|
|
|
#ifndef H_SYSTEM
|
|
|
|
#define H_SYSTEM
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
2002-06-21 01:17:23 +08:00
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
#include <sys/stat.h>
|
1999-11-27 08:15:07 +08:00
|
|
|
#include <stdio.h>
|
1998-07-26 05:00:26 +08:00
|
|
|
|
1998-07-31 06:09:42 +08:00
|
|
|
#ifdef HAVE_SYS_PARAM_H
|
|
|
|
#include <sys/param.h>
|
|
|
|
#endif
|
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
/* <unistd.h> should be included before any preprocessor test
|
|
|
|
of _POSIX_VERSION. */
|
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
2007-09-03 20:35:17 +08:00
|
|
|
#if !defined(__GLIBC__)
|
2005-01-05 03:31:31 +08:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <crt_externs.h>
|
|
|
|
#define environ (*_NSGetEnviron())
|
|
|
|
#else
|
2002-04-09 06:52:45 +08:00
|
|
|
extern char ** environ;
|
2005-01-05 03:31:31 +08:00
|
|
|
#endif /* __APPLE__ */
|
2002-04-09 06:52:45 +08:00
|
|
|
#endif
|
1998-07-26 05:00:26 +08:00
|
|
|
#endif
|
|
|
|
|
1998-07-31 06:09:42 +08:00
|
|
|
#if TIME_WITH_SYS_TIME
|
|
|
|
# include <sys/time.h>
|
|
|
|
# include <time.h>
|
|
|
|
#else
|
|
|
|
# if HAVE_SYS_TIME_H
|
|
|
|
# include <sys/time.h>
|
|
|
|
# else
|
|
|
|
# include <time.h>
|
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
#ifdef HAVE_STRING_H
|
|
|
|
# if !STDC_HEADERS && HAVE_MEMORY_H
|
|
|
|
# include <memory.h>
|
|
|
|
# endif
|
|
|
|
# include <string.h>
|
|
|
|
#else
|
|
|
|
# include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
2001-10-14 03:35:58 +08:00
|
|
|
#if !defined(HAVE_STPCPY)
|
2007-09-12 01:04:11 +08:00
|
|
|
char * stpcpy(char * dest, const char * src);
|
1999-12-02 04:00:39 +08:00
|
|
|
#endif
|
|
|
|
|
2001-10-14 03:35:58 +08:00
|
|
|
#if !defined(HAVE_STPNCPY)
|
2007-09-12 01:04:11 +08:00
|
|
|
char * stpncpy(char * dest, const char * src, size_t n);
|
2000-02-28 04:50:52 +08:00
|
|
|
#endif
|
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
#include <errno.h>
|
|
|
|
#ifndef errno
|
|
|
|
extern int errno;
|
|
|
|
#endif
|
|
|
|
|
2007-09-03 20:35:17 +08:00
|
|
|
#if HAVE___SECURE_GETENV
|
2003-05-01 04:04:58 +08:00
|
|
|
#define getenv(_s) __secure_getenv(_s)
|
|
|
|
#endif
|
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
#ifdef STDC_HEADERS
|
2007-09-12 01:04:11 +08:00
|
|
|
/* FIX: shrug */
|
1998-07-26 05:00:26 +08:00
|
|
|
#define getopt system_getopt
|
|
|
|
#include <stdlib.h>
|
|
|
|
#undef getopt
|
|
|
|
#else /* not STDC_HEADERS */
|
1999-04-14 19:28:31 +08:00
|
|
|
char *getenv (const char *name);
|
1998-07-26 05:00:26 +08:00
|
|
|
#endif /* STDC_HEADERS */
|
|
|
|
|
2000-06-13 06:13:10 +08:00
|
|
|
/* XXX solaris2.5.1 has not */
|
|
|
|
#if !defined(EXIT_FAILURE)
|
|
|
|
#define EXIT_FAILURE 1
|
|
|
|
#endif
|
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
#ifdef HAVE_FCNTL_H
|
|
|
|
#include <fcntl.h>
|
|
|
|
#else
|
|
|
|
#include <sys/file.h>
|
|
|
|
#endif
|
|
|
|
|
2007-09-03 20:35:17 +08:00
|
|
|
#if !defined(SEEK_SET)
|
1998-07-26 05:00:26 +08:00
|
|
|
#define SEEK_SET 0
|
|
|
|
#define SEEK_CUR 1
|
|
|
|
#define SEEK_END 2
|
|
|
|
#endif
|
2007-09-03 20:35:17 +08:00
|
|
|
#if !defined(F_OK)
|
1998-07-26 05:00:26 +08:00
|
|
|
#define F_OK 0
|
|
|
|
#define X_OK 1
|
|
|
|
#define W_OK 2
|
|
|
|
#define R_OK 4
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_DIRENT_H
|
|
|
|
# include <dirent.h>
|
|
|
|
# define NLENGTH(direct) (strlen((direct)->d_name))
|
|
|
|
#else /* not HAVE_DIRENT_H */
|
|
|
|
# define dirent direct
|
|
|
|
# define NLENGTH(direct) ((direct)->d_namlen)
|
|
|
|
# ifdef HAVE_SYS_NDIR_H
|
|
|
|
# include <sys/ndir.h>
|
|
|
|
# endif /* HAVE_SYS_NDIR_H */
|
|
|
|
# ifdef HAVE_SYS_DIR_H
|
|
|
|
# include <sys/dir.h>
|
|
|
|
# endif /* HAVE_SYS_DIR_H */
|
|
|
|
# ifdef HAVE_NDIR_H
|
|
|
|
# include <ndir.h>
|
|
|
|
# endif /* HAVE_NDIR_H */
|
|
|
|
#endif /* HAVE_DIRENT_H */
|
|
|
|
|
2002-06-20 03:27:20 +08:00
|
|
|
#include <ctype.h>
|
|
|
|
|
2007-09-03 20:35:17 +08:00
|
|
|
#if HAVE_SYS_MMAN_H
|
1998-07-31 06:09:42 +08:00
|
|
|
#include <sys/mman.h>
|
|
|
|
#endif
|
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
#if HAVE_SYS_WAIT_H
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAVE_LIMITS_H
|
|
|
|
#include <limits.h>
|
|
|
|
#endif
|
|
|
|
|
2008-11-03 20:13:45 +08:00
|
|
|
#ifndef PATH_MAX
|
|
|
|
#ifdef _POSIX_PATH_MAX
|
|
|
|
#define PATH_MAX _POSIX_PATH_MAX
|
|
|
|
#elif defined MAXPATHLEN
|
|
|
|
#define PATH_MAX MAXPATHLEN
|
|
|
|
#else
|
|
|
|
#define PATH_MAX 256
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2004-01-05 22:09:47 +08:00
|
|
|
#if WITH_SELINUX
|
|
|
|
#include <selinux/selinux.h>
|
|
|
|
#else
|
|
|
|
typedef char * security_context_t;
|
|
|
|
|
|
|
|
#define freecon(_c)
|
|
|
|
|
|
|
|
#define getfilecon(_fn, _c) (-1)
|
|
|
|
#define lgetfilecon(_fn, _c) (-1)
|
|
|
|
#define fgetfilecon(_fd, _c) (-1)
|
|
|
|
|
|
|
|
#define setfilecon(_fn, _c) (-1)
|
|
|
|
#define lsetfilecon(_fn, _c) (-1)
|
|
|
|
#define fsetfilecon(_fd, _c) (-1)
|
|
|
|
|
|
|
|
#define security_check_context(_c) (0)
|
|
|
|
|
2008-05-08 17:40:37 +08:00
|
|
|
#define is_selinux_enabled() (0)
|
2004-11-11 14:11:37 +08:00
|
|
|
|
2007-09-03 18:59:42 +08:00
|
|
|
#define matchpathcon_init(_fn) (-1)
|
|
|
|
#define matchpathcon_fini() (0)
|
|
|
|
#define matchpathcon(_fn, _fm, _c) (-1)
|
|
|
|
|
2004-11-11 14:11:37 +08:00
|
|
|
#define rpm_execcon(_v, _fn, _av, _envp) (0)
|
2004-01-05 22:09:47 +08:00
|
|
|
#endif
|
|
|
|
|
2008-10-26 20:17:16 +08:00
|
|
|
#if WITH_CAP
|
|
|
|
#include <sys/capability.h>
|
2008-10-29 17:49:38 +08:00
|
|
|
#else
|
|
|
|
typedef void * cap_t;
|
2008-10-26 20:17:16 +08:00
|
|
|
#endif
|
|
|
|
|
2008-10-26 20:18:17 +08:00
|
|
|
#if WITH_ACL
|
|
|
|
#include <acl/libacl.h>
|
|
|
|
#endif
|
|
|
|
|
1999-09-12 08:41:51 +08:00
|
|
|
#if HAVE_MCHECK_H
|
|
|
|
#include <mcheck.h>
|
2001-09-25 05:53:14 +08:00
|
|
|
#endif /* HAVE_MCHECK_H */
|
1999-09-21 11:22:53 +08:00
|
|
|
|
2009-09-16 22:28:22 +08:00
|
|
|
#include "rpmio/rpmutil.h"
|
|
|
|
/* compatibility macros to avoid a mass-renaming all over the codebase */
|
|
|
|
#define xmalloc(_size) rmalloc((_size))
|
|
|
|
#define xcalloc(_nmemb, _size) rcalloc((_nmemb), (_size))
|
|
|
|
#define xrealloc(_ptr, _size) rrealloc((_ptr), (_size))
|
|
|
|
#define xstrdup(_str) rstrdup((_str))
|
|
|
|
#define _free(_ptr) rfree((_ptr))
|
|
|
|
|
1999-09-26 23:04:03 +08:00
|
|
|
/* Retrofit glibc __progname */
|
|
|
|
#if defined __GLIBC__ && __GLIBC__ >= 2
|
2000-05-25 01:53:35 +08:00
|
|
|
#if __GLIBC_MINOR__ >= 1
|
|
|
|
#define __progname __assert_program_name
|
|
|
|
#endif
|
1999-09-26 23:04:03 +08:00
|
|
|
#define setprogname(pn)
|
|
|
|
#else
|
1999-09-27 01:28:00 +08:00
|
|
|
#define __progname program_name
|
1999-09-26 23:04:03 +08:00
|
|
|
#define setprogname(pn) \
|
1999-09-27 01:28:00 +08:00
|
|
|
{ if ((__progname = strrchr(pn, '/')) != NULL) __progname++; \
|
1999-09-26 23:04:03 +08:00
|
|
|
else __progname = pn; \
|
|
|
|
}
|
|
|
|
#endif
|
2005-01-18 07:58:09 +08:00
|
|
|
extern const char *__progname;
|
1999-09-26 23:04:03 +08:00
|
|
|
|
1998-07-31 06:09:42 +08:00
|
|
|
#if HAVE_NETDB_H
|
|
|
|
#include <netdb.h>
|
|
|
|
#endif
|
|
|
|
|
1998-10-08 22:59:17 +08:00
|
|
|
/* Take care of NLS matters. */
|
|
|
|
|
|
|
|
#if HAVE_LOCALE_H
|
|
|
|
# include <locale.h>
|
|
|
|
#endif
|
|
|
|
#if !HAVE_SETLOCALE
|
|
|
|
# define setlocale(Category, Locale) /* empty */
|
|
|
|
#endif
|
|
|
|
|
2007-09-03 20:35:17 +08:00
|
|
|
#if ENABLE_NLS
|
1998-10-08 22:59:17 +08:00
|
|
|
# include <libintl.h>
|
2007-11-13 18:57:49 +08:00
|
|
|
# define _(Text) dgettext (PACKAGE, Text)
|
1998-10-08 22:59:17 +08:00
|
|
|
#else
|
|
|
|
# undef bindtextdomain
|
|
|
|
# define bindtextdomain(Domain, Directory) /* empty */
|
|
|
|
# undef textdomain
|
|
|
|
# define textdomain(Domain) /* empty */
|
|
|
|
# define _(Text) Text
|
1999-10-01 00:56:05 +08:00
|
|
|
# undef dgettext
|
|
|
|
# define dgettext(DomainName, Text) Text
|
1998-10-08 22:59:17 +08:00
|
|
|
#endif
|
|
|
|
|
1998-12-02 01:18:38 +08:00
|
|
|
#define N_(Text) Text
|
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
/* ============== from misc/miscfn.h */
|
|
|
|
|
2007-09-03 20:35:17 +08:00
|
|
|
#if !defined(USE_GNU_GLOB)
|
1998-07-26 05:00:26 +08:00
|
|
|
#if HAVE_FNMATCH_H
|
|
|
|
#include <fnmatch.h>
|
|
|
|
#endif
|
|
|
|
|
2007-09-03 20:35:17 +08:00
|
|
|
#if HAVE_GLOB_H
|
1998-07-26 05:00:26 +08:00
|
|
|
#include <glob.h>
|
2000-03-12 04:14:07 +08:00
|
|
|
#endif
|
1998-07-26 05:00:26 +08:00
|
|
|
#else
|
|
|
|
#include "misc/glob.h"
|
2000-03-12 04:14:07 +08:00
|
|
|
#include "misc/fnmatch.h"
|
2001-10-14 03:35:58 +08:00
|
|
|
#endif
|
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
#if NEED_STRINGS_H
|
|
|
|
#include <strings.h>
|
|
|
|
#endif
|
|
|
|
|
2005-02-04 07:05:59 +08:00
|
|
|
#if HAVE_GETMNTINFO || HAVE_GETMNTINFO_R || HAVE_MNTCTL
|
1998-07-26 05:00:26 +08:00
|
|
|
# define GETMNTENT_ONE 0
|
|
|
|
# define GETMNTENT_TWO 0
|
|
|
|
# if HAVE_SYS_MNTCTL_H
|
|
|
|
# include <sys/mntctl.h>
|
|
|
|
# endif
|
|
|
|
# if HAVE_SYS_VMOUNT_H
|
|
|
|
# include <sys/vmount.h>
|
|
|
|
# endif
|
|
|
|
# if HAVE_SYS_MOUNT_H
|
|
|
|
# include <sys/mount.h>
|
|
|
|
# endif
|
|
|
|
#elif HAVE_MNTENT_H || !(HAVE_GETMNTENT) || HAVE_STRUCT_MNTTAB
|
|
|
|
# if HAVE_MNTENT_H
|
|
|
|
# include <stdio.h>
|
|
|
|
# include <mntent.h>
|
|
|
|
# define our_mntent struct mntent
|
|
|
|
# define our_mntdir mnt_dir
|
|
|
|
# elif HAVE_STRUCT_MNTTAB
|
|
|
|
# include <stdio.h>
|
|
|
|
# include <mnttab.h>
|
|
|
|
struct our_mntent {
|
|
|
|
char * our_mntdir;
|
|
|
|
};
|
|
|
|
struct our_mntent *getmntent(FILE *filep);
|
|
|
|
# define our_mntent struct our_mntent
|
|
|
|
# else
|
|
|
|
# include <stdio.h>
|
|
|
|
struct our_mntent {
|
|
|
|
char * our_mntdir;
|
|
|
|
};
|
|
|
|
struct our_mntent *getmntent(FILE *filep);
|
|
|
|
# define our_mntent struct our_mntent
|
|
|
|
# endif
|
|
|
|
# define GETMNTENT_ONE 1
|
|
|
|
# define GETMNTENT_TWO 0
|
|
|
|
#elif HAVE_SYS_MNTTAB_H
|
|
|
|
# include <stdio.h>
|
|
|
|
# include <sys/mnttab.h>
|
|
|
|
# define GETMNTENT_ONE 0
|
|
|
|
# define GETMNTENT_TWO 1
|
|
|
|
# define our_mntent struct mnttab
|
|
|
|
# define our_mntdir mnt_mountp
|
|
|
|
#else /* if !HAVE_MNTCTL */
|
|
|
|
# error Neither mntent.h, mnttab.h, or mntctl() exists. I cannot build on this system.
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef MOUNTED
|
|
|
|
#define MOUNTED "/etc/mnttab"
|
|
|
|
#endif
|
2003-02-15 07:03:35 +08:00
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
#endif /* H_SYSTEM */
|