19f07849eSopenharmony_ci/**
29f07849eSopenharmony_ci * @file
39f07849eSopenharmony_ci */
49f07849eSopenharmony_ci
59f07849eSopenharmony_ci#ifdef HAVE_CONFIG_H
69f07849eSopenharmony_ci#include "config.h"
79f07849eSopenharmony_ci#endif
89f07849eSopenharmony_ci
99f07849eSopenharmony_ci#include <ctype.h>
109f07849eSopenharmony_ci
119f07849eSopenharmony_ci/* XXX isspace(3) has i18n encoding signednesss issues on Solaris. */
129f07849eSopenharmony_ci#define	_isspaceptr(_chp)	isspace((int)(*(unsigned const char *)(_chp)))
139f07849eSopenharmony_ci
149f07849eSopenharmony_ci#ifdef HAVE_MCHECK_H
159f07849eSopenharmony_ci#include <mcheck.h>
169f07849eSopenharmony_ci#endif
179f07849eSopenharmony_ci
189f07849eSopenharmony_ci#include <stdlib.h>
199f07849eSopenharmony_ci#include <string.h>
209f07849eSopenharmony_ci
219f07849eSopenharmony_civoid * xmalloc (size_t size);
229f07849eSopenharmony_ci
239f07849eSopenharmony_civoid * xcalloc (size_t nmemb, size_t size);
249f07849eSopenharmony_ci
259f07849eSopenharmony_civoid * xrealloc (void * ptr, size_t size);
269f07849eSopenharmony_ci
279f07849eSopenharmony_cichar * xstrdup (const char *str);
289f07849eSopenharmony_ci
299f07849eSopenharmony_ci#if !defined(HAVE_STPCPY)
309f07849eSopenharmony_ci/* Copy SRC to DEST, returning the address of the terminating '\0' in DEST.  */
319f07849eSopenharmony_cistatic inline char * stpcpy (char *dest, const char * src) {
329f07849eSopenharmony_ci    register char *d = dest;
339f07849eSopenharmony_ci    register const char *s = src;
349f07849eSopenharmony_ci
359f07849eSopenharmony_ci    do
369f07849eSopenharmony_ci	*d++ = *s;
379f07849eSopenharmony_ci    while (*s++ != '\0');
389f07849eSopenharmony_ci    return d - 1;
399f07849eSopenharmony_ci}
409f07849eSopenharmony_ci#endif
419f07849eSopenharmony_ci
429f07849eSopenharmony_ci/* Memory allocation via macro defs to get meaningful locations from mtrace() */
439f07849eSopenharmony_ci#if defined(HAVE_MCHECK_H) && defined(__GNUC__)
449f07849eSopenharmony_ci#define	vmefail()	(fprintf(stderr, "virtual memory exhausted.\n"), exit(EXIT_FAILURE), NULL)
459f07849eSopenharmony_ci#define	xmalloc(_size) 		(malloc(_size) ? : vmefail())
469f07849eSopenharmony_ci#define	xcalloc(_nmemb, _size)	(calloc((_nmemb), (_size)) ? : vmefail())
479f07849eSopenharmony_ci#define	xrealloc(_ptr, _size)	(realloc((_ptr), (_size)) ? : vmefail())
489f07849eSopenharmony_ci#define xstrdup(_str)   (strcpy((malloc(strlen(_str)+1) ? : vmefail()), (_str)))
499f07849eSopenharmony_ci#else
509f07849eSopenharmony_ci#define	xmalloc(_size) 		malloc(_size)
519f07849eSopenharmony_ci#define	xcalloc(_nmemb, _size)	calloc((_nmemb), (_size))
529f07849eSopenharmony_ci#define	xrealloc(_ptr, _size)	realloc((_ptr), (_size))
539f07849eSopenharmony_ci#define	xstrdup(_str)	strdup(_str)
549f07849eSopenharmony_ci#endif  /* defined(HAVE_MCHECK_H) && defined(__GNUC__) */
559f07849eSopenharmony_ci
569f07849eSopenharmony_ci#if defined(HAVE_SECURE_GETENV)
579f07849eSopenharmony_ci#define getenv(_s)	secure_getenv(_s)
589f07849eSopenharmony_ci#elif defined(HAVE___SECURE_GETENV)
599f07849eSopenharmony_ci#define	getenv(_s)	__secure_getenv(_s)
609f07849eSopenharmony_ci#endif
619f07849eSopenharmony_ci
629f07849eSopenharmony_ci#if !defined(__GNUC__) && !defined(__attribute__)
639f07849eSopenharmony_ci#define __attribute__(x)
649f07849eSopenharmony_ci#endif
659f07849eSopenharmony_ci#define UNUSED(x) x __attribute__((__unused__))
669f07849eSopenharmony_ci#define FORMAT(a, b, c) __attribute__((__format__ (a, b, c)))
679f07849eSopenharmony_ci#define NORETURN __attribute__((__noreturn__))
689f07849eSopenharmony_ci
699f07849eSopenharmony_ci#include "popt.h"
70