third_party: Update popt to 1.16 release
[samba.git] / third_party / popt / system.h
index bbb4f6cc264b3e7bd9ebb09ff1b6862af4c31b86..452bf40dc1aac90c9837f7e00e5d91b7cf68da6f 100644 (file)
@@ -1,3 +1,7 @@
+/**
+ * \file popt/system.h
+ */
+
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -13,11 +17,14 @@ extern __const __int32_t *__ctype_toupper;
 
 #include <ctype.h>
 
+/* XXX isspace(3) has i18n encoding signednesss issues on Solaris. */
+#define        _isspaceptr(_chp)       isspace((int)(*(unsigned char *)(_chp)))
+
 #include <errno.h>
 #include <fcntl.h>
 #include <limits.h>
 
-#if HAVE_MCHECK_H 
+#ifdef HAVE_MCHECK_H
 #include <mcheck.h>
 #endif
 
@@ -25,7 +32,7 @@ extern __const __int32_t *__ctype_toupper;
 #include <stdlib.h>
 #include <string.h>
 
-#if HAVE_UNISTD_H
+#if defined(HAVE_UNISTD_H) && !defined(__LCLINT__)
 #include <unistd.h>
 #endif
 
@@ -35,44 +42,62 @@ extern __const __int32_t *__ctype_toupper;
 #include <libc.h>
 #endif
 
-#if defined(__LCLINT__)
-/*@-declundef -incondefs -redecl@*/ /* LCL: missing annotation */
-/*@only@*/ void * alloca (size_t __size)
-       /*@ensures MaxSet(result) == (__size - 1) @*/
+/*@-incondefs@*/
+/*@mayexit@*/ /*@only@*/ /*@out@*/ /*@unused@*/
+void * xmalloc (size_t size)
+       /*@globals errno @*/
+       /*@ensures maxSet(result) == (size - 1) @*/
+       /*@modifies errno @*/;
+
+/*@mayexit@*/ /*@only@*/ /*@unused@*/
+void * xcalloc (size_t nmemb, size_t size)
+       /*@ensures maxSet(result) == (nmemb - 1) @*/
        /*@*/;
-/*@=declundef =incondefs =redecl@*/
-#endif
 
-/* AIX requires this to be the first thing in the file.  */ 
-#ifndef __GNUC__
-# if HAVE_ALLOCA_H
-#  include <alloca.h>
-# else
-#  ifdef _AIX
-#pragma alloca
-#  else
-#   ifndef alloca /* predefined by HP cc +Olibcalls */
-char *alloca ();
-#   endif
-#  endif
-# endif
-#elif defined(__GNUC__) && defined(__STRICT_ANSI__)
-#define alloca __builtin_alloca
-#elif defined(__GNUC__) && defined(HAVE_ALLOCA_H)
-# include <alloca.h>
-#endif
+/*@mayexit@*/ /*@only@*/ /*@unused@*/
+void * xrealloc (/*@null@*/ /*@only@*/ void * ptr, size_t size)
+       /*@ensures maxSet(result) == (size - 1) @*/
+       /*@modifies *ptr @*/;
 
-/*@-redecl -redef@*/
-/*@mayexit@*/ /*@only@*/ char * xstrdup (const char *str)
+/*@mayexit@*/ /*@only@*/ /*@unused@*/
+char * xstrdup (const char *str)
        /*@*/;
-/*@=redecl =redef@*/
+/*@=incondefs@*/
+
+#if !defined(HAVE_STPCPY)
+/* Copy SRC to DEST, returning the address of the terminating '\0' in DEST.  */
+static inline char * stpcpy (char *dest, const char * src) {
+    register char *d = dest;
+    register const char *s = src;
 
-#if HAVE_MCHECK_H && defined(__GNUC__)
+    do
+       *d++ = *s;
+    while (*s++ != '\0');
+    return d - 1;
+}
+#endif
+
+/* Memory allocation via macro defs to get meaningful locations from mtrace() */
+#if defined(HAVE_MCHECK_H) && defined(__GNUC__)
 #define        vmefail()       (fprintf(stderr, "virtual memory exhausted.\n"), exit(EXIT_FAILURE), NULL)
+#define        xmalloc(_size)          (malloc(_size) ? : vmefail())
+#define        xcalloc(_nmemb, _size)  (calloc((_nmemb), (_size)) ? : vmefail())
+#define        xrealloc(_ptr, _size)   (realloc((_ptr), (_size)) ? : vmefail())
 #define xstrdup(_str)   (strcpy((malloc(strlen(_str)+1) ? : vmefail()), (_str)))
 #else
+#define        xmalloc(_size)          malloc(_size)
+#define        xcalloc(_nmemb, _size)  calloc((_nmemb), (_size))
+#define        xrealloc(_ptr, _size)   realloc((_ptr), (_size))
 #define        xstrdup(_str)   strdup(_str)
-#endif  /* HAVE_MCHECK_H && defined(__GNUC__) */
+#endif  /* defined(HAVE_MCHECK_H) && defined(__GNUC__) */
 
+#if defined(HAVE___SECURE_GETENV) && !defined(__LCLINT__)
+#define        getenv(_s)      __secure_getenv(_s)
+#endif
+
+#if !defined(__GNUC__) && !defined(__attribute__)
+#define __attribute__(x)
+#endif
+#define UNUSED(x) x __attribute__((__unused__))
 
 #include "popt.h"