2000-12-13 04:03:45 +08:00
|
|
|
/**
|
|
|
|
* \file system.h
|
2014-05-11 08:27:26 +08:00
|
|
|
*
|
|
|
|
* Some misc low-level API
|
2000-12-13 04:03:45 +08:00
|
|
|
*/
|
1998-07-26 05:00:26 +08:00
|
|
|
|
|
|
|
#ifndef H_SYSTEM
|
|
|
|
#define H_SYSTEM
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
2013-01-29 00:49:01 +08:00
|
|
|
#if HAVE_SECURE_GETENV
|
|
|
|
#define getenv(_s) secure_getenv(_s)
|
|
|
|
#elif 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 HAVE_FCNTL_H
|
|
|
|
#include <fcntl.h>
|
|
|
|
#else
|
|
|
|
#include <sys/file.h>
|
|
|
|
#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 */
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
2015-09-29 11:49:24 +08:00
|
|
|
#if defined(HAVE_FDATASYNC) && !HAVE_DECL_FDATASYNC
|
|
|
|
extern int fdatasync(int fildes);
|
|
|
|
#endif
|
|
|
|
|
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))
|
|
|
|
|
2013-08-18 03:50:41 +08:00
|
|
|
/* To extract program's name: use calls (reimplemented or shipped with system):
|
|
|
|
- void setprogname(const char *pn)
|
|
|
|
- const char *getprogname(void)
|
|
|
|
|
|
|
|
setprogname(*pn) must be the first call in main() in order to set the name
|
|
|
|
as soon as possible. */
|
2016-02-15 23:08:25 +08:00
|
|
|
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__) || defined(__APPLE__)
|
2013-08-18 03:50:41 +08:00
|
|
|
/* `man setprogname' v. May 21, 2011 (NetBSD 6.1) says:
|
|
|
|
Portable programs that wish to use getprogname() should call setprogname()
|
|
|
|
in main(). In some systems (like NetBSD) it can be set only once and it is
|
|
|
|
done before an execution of main() -- therefore calling it again has no
|
|
|
|
effect.
|
2016-02-11 21:08:58 +08:00
|
|
|
|
2013-08-18 03:50:41 +08:00
|
|
|
Getprogname and setprogname function calls appeared in NetBSD 1.6
|
|
|
|
(released in 2002). So nothing to (re)implement for this platform. */
|
|
|
|
# include <stdlib.h> /* Make sure this header is included */
|
|
|
|
# define xsetprogname(pn) setprogname(pn)
|
|
|
|
# define xgetprogname(pn) getprogname(pn)
|
|
|
|
#elif defined(__GLIBC__) /* GNU LIBC ships with (const *char *) __progname */
|
|
|
|
# define xsetprogname(pn) /* No need to implement it in GNU LIBC. */
|
|
|
|
extern const char *__progname;
|
|
|
|
# define xgetprogname(pn) __progname
|
|
|
|
#else /* Reimplement setprogname and getprogname */
|
|
|
|
# include "misc/rpmxprogname.h"
|
|
|
|
# define xsetprogname(pn) _rpmxsetprogname(pn)
|
|
|
|
# define xgetprogname() _rpmxgetprogname()
|
2000-05-25 01:53:35 +08:00
|
|
|
#endif
|
1999-09-26 23:04:03 +08:00
|
|
|
|
1998-10-08 22:59:17 +08:00
|
|
|
/* Take care of NLS matters. */
|
2007-09-03 20:35:17 +08:00
|
|
|
#if ENABLE_NLS
|
2010-01-05 20:28:47 +08:00
|
|
|
# include <locale.h>
|
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
|
|
|
|
# define _(Text) Text
|
|
|
|
#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 */
|
|
|
|
|
2000-03-12 04:14:07 +08:00
|
|
|
#include "misc/fnmatch.h"
|
2001-10-14 03:35:58 +08:00
|
|
|
|
2010-06-22 05:04:39 +08:00
|
|
|
#include <dlfcn.h>
|
|
|
|
|
1998-07-26 05:00:26 +08:00
|
|
|
#endif /* H_SYSTEM */
|