csomh / source-git / rpm

Forked from source-git/rpm 4 years ago
Clone
2ff057
/**
2ff057
 * \file system.h
2ff057
 *
2ff057
 *  Some misc low-level API
2ff057
 */
2ff057
2ff057
#ifndef	H_SYSTEM
2ff057
#define	H_SYSTEM
2ff057
2ff057
#ifdef HAVE_CONFIG_H
2ff057
#include "config.h"
2ff057
#endif
2ff057
2ff057
#ifdef HAVE_SYS_PARAM_H
2ff057
#include <sys/param.h>
2ff057
#endif
2ff057
2ff057
/* <unistd.h> should be included before any preprocessor test
2ff057
   of _POSIX_VERSION.  */
2ff057
#ifdef HAVE_UNISTD_H
2ff057
#include <unistd.h>
2ff057
#if !defined(__GLIBC__)
2ff057
#ifdef __APPLE__
2ff057
#include <crt_externs.h>
2ff057
#define environ (*_NSGetEnviron())
2ff057
#else
2ff057
extern char ** environ;
2ff057
#endif /* __APPLE__ */
2ff057
#endif
2ff057
#endif
2ff057
2ff057
#if !defined(HAVE_STPCPY)
2ff057
char * stpcpy(char * dest, const char * src);
2ff057
#endif
2ff057
2ff057
#if !defined(HAVE_STPNCPY)
2ff057
char * stpncpy(char * dest, const char * src, size_t n);
2ff057
#endif
2ff057
2ff057
#if HAVE_SECURE_GETENV
2ff057
#define	getenv(_s)	secure_getenv(_s)
2ff057
#elif HAVE___SECURE_GETENV
2ff057
#define	getenv(_s)	__secure_getenv(_s)
2ff057
#endif
2ff057
2ff057
#ifdef HAVE_FCNTL_H
2ff057
#include <fcntl.h>
2ff057
#else
2ff057
#include <sys/file.h>
2ff057
#endif
2ff057
2ff057
#ifdef HAVE_DIRENT_H
2ff057
# include <dirent.h>
2ff057
# define NLENGTH(direct) (strlen((direct)->d_name))
2ff057
#else /* not HAVE_DIRENT_H */
2ff057
# define dirent direct
2ff057
# define NLENGTH(direct) ((direct)->d_namlen)
2ff057
# ifdef HAVE_SYS_NDIR_H
2ff057
#  include <sys/ndir.h>
2ff057
# endif /* HAVE_SYS_NDIR_H */
2ff057
# ifdef HAVE_SYS_DIR_H
2ff057
#  include <sys/dir.h>
2ff057
# endif /* HAVE_SYS_DIR_H */
2ff057
# ifdef HAVE_NDIR_H
2ff057
#  include <ndir.h>
2ff057
# endif /* HAVE_NDIR_H */
2ff057
#endif /* HAVE_DIRENT_H */
2ff057
2ff057
#if HAVE_LIMITS_H
2ff057
#include <limits.h>
2ff057
#endif
2ff057
2ff057
#ifndef PATH_MAX
2ff057
#ifdef _POSIX_PATH_MAX
2ff057
#define PATH_MAX _POSIX_PATH_MAX
2ff057
#elif defined MAXPATHLEN
2ff057
#define PATH_MAX MAXPATHLEN
2ff057
#else
2ff057
#define PATH_MAX 256
2ff057
#endif
2ff057
#endif
2ff057
2ff057
#if defined(HAVE_FDATASYNC) && !HAVE_DECL_FDATASYNC
2ff057
extern int fdatasync(int fildes);
2ff057
#endif
2ff057
2ff057
#include "rpmio/rpmutil.h"
2ff057
/* compatibility macros to avoid a mass-renaming all over the codebase */
2ff057
#define xmalloc(_size) rmalloc((_size))
2ff057
#define xcalloc(_nmemb, _size) rcalloc((_nmemb), (_size))
2ff057
#define xrealloc(_ptr, _size) rrealloc((_ptr), (_size))
2ff057
#define xstrdup(_str) rstrdup((_str))
2ff057
#define _free(_ptr) rfree((_ptr))
2ff057
2ff057
/* To extract program's name: use calls (reimplemented or shipped with system):
2ff057
   - void setprogname(const char *pn)
2ff057
   - const char *getprogname(void)
2ff057
2ff057
   setprogname(*pn) must be the first call in main() in order to set the name
2ff057
   as soon as possible. */
2ff057
#if defined(HAVE_SETPROGNAME) /* BSD'ish systems */
2ff057
# include <stdlib.h> /* Make sure this header is included */
2ff057
# define xsetprogname(pn) setprogname(pn)
2ff057
# define xgetprogname(pn) getprogname(pn)
2ff057
#elif defined(HAVE___PROGNAME) /* glibc and others */
2ff057
# define xsetprogname(pn)
2ff057
  extern const char *__progname;
2ff057
# define xgetprogname(pn) __progname
2ff057
#else
2ff057
# error "Did not find any sutable implementation of xsetprogname/xgetprogname"
2ff057
#endif
2ff057
2ff057
/* Take care of NLS matters.  */
2ff057
#if ENABLE_NLS
2ff057
# include <locale.h>
2ff057
# include <libintl.h>
2ff057
# define _(Text) dgettext (PACKAGE, Text)
2ff057
#else
2ff057
# define _(Text) Text
2ff057
#endif
2ff057
2ff057
#define N_(Text) Text
2ff057
2ff057
/* ============== from misc/miscfn.h */
2ff057
2ff057
#include "misc/fnmatch.h"
2ff057
2ff057
#include <dlfcn.h>
2ff057
2ff057
#endif	/* H_SYSTEM */