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
|
|
|
|
|
2022-06-15 21:16:37 +08:00
|
|
|
#if defined(HAVE_SECURE_GETENV)
|
2013-01-29 00:49:01 +08:00
|
|
|
#define getenv(_s) secure_getenv(_s)
|
2022-06-15 21:16:37 +08:00
|
|
|
#elif defined(HAVE___SECURE_GETENV)
|
2003-05-01 04:04:58 +08:00
|
|
|
#define getenv(_s) __secure_getenv(_s)
|
|
|
|
#endif
|
|
|
|
|
2022-06-15 21:16:37 +08:00
|
|
|
#ifdef HAVE_LIMITS_H
|
1998-07-26 05:00:26 +08:00
|
|
|
#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
|
|
|
|
|
2022-03-09 19:37:10 +08:00
|
|
|
#include <rpm/rpmutil.h>
|
2009-09-16 22:28:22 +08:00
|
|
|
/* compatibility macros to avoid a mass-renaming all over the codebase */
|
|
|
|
#define xmalloc(_size) rmalloc((_size))
|
2022-02-08 15:23:58 +08:00
|
|
|
#define xmallocn(_nmemb, _size) rreallocn(NULL, (_nmemb), (_size))
|
2009-09-16 22:28:22 +08:00
|
|
|
#define xcalloc(_nmemb, _size) rcalloc((_nmemb), (_size))
|
|
|
|
#define xrealloc(_ptr, _size) rrealloc((_ptr), (_size))
|
2022-02-11 21:04:35 +08:00
|
|
|
#define xreallocn(_ptr, _nmemb, _size) rreallocn((_ptr), (_nmemb), (_size))
|
2009-09-16 22:28:22 +08:00
|
|
|
#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. */
|
2017-03-24 20:20:48 +08:00
|
|
|
#if defined(HAVE_SETPROGNAME) /* BSD'ish systems */
|
2013-08-18 03:50:41 +08:00
|
|
|
# include <stdlib.h> /* Make sure this header is included */
|
|
|
|
# define xsetprogname(pn) setprogname(pn)
|
|
|
|
# define xgetprogname(pn) getprogname(pn)
|
2017-03-24 20:20:48 +08:00
|
|
|
#elif defined(HAVE___PROGNAME) /* glibc and others */
|
|
|
|
# define xsetprogname(pn)
|
2013-08-18 03:50:41 +08:00
|
|
|
extern const char *__progname;
|
|
|
|
# define xgetprogname(pn) __progname
|
2017-03-24 02:22:07 +08:00
|
|
|
#else
|
|
|
|
# error "Did not find any sutable implementation of xsetprogname/xgetprogname"
|
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. */
|
2022-06-15 21:16:37 +08:00
|
|
|
#if defined(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
|
|
|
#endif /* H_SYSTEM */
|