Allow any gcc to make use of __builtin_alloca for alloca.
[rsync/rsync.git] / popt / system.h
index db63dd4..50cecaf 100644 (file)
@@ -22,11 +22,28 @@ extern __const __int32_t *__ctype_toupper;
 #endif
 
 #include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#if HAVE_UNISTD_H
-#include <unistd.h>
+#ifdef HAVE_SYS_TYPES_H
+# include <sys/types.h>
+#endif
+#ifdef STDC_HEADERS
+# include <stdlib.h>
+# include <stddef.h>
+#else
+# ifdef HAVE_STDLIB_H
+#  include <stdlib.h>
+# endif
+#endif
+#ifdef HAVE_STRING_H
+# if !defined STDC_HEADERS && defined HAVE_MEMORY_H
+#  include <memory.h>
+# endif
+# include <string.h>
+#endif
+#ifdef HAVE_STRINGS_H
+# include <strings.h>
+#endif
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
 #endif
 
 #ifndef __GNUC__
@@ -58,7 +75,7 @@ void * alloca (size_t __size)
 #  else
 #   ifdef HAVE_ALLOCA
 #    ifndef alloca /* predefined by HP cc +Olibcalls */
-char *alloca ();
+char *alloca(size_t size);
 #    endif
 #   else
 #    ifdef alloca
@@ -68,19 +85,31 @@ char *alloca ();
 #   endif
 #  endif
 # endif
-#elif defined(__GNUC__) && defined(__STRICT_ANSI__)
+#elif !defined(alloca)
 #define alloca __builtin_alloca
 #endif
 
-/*@-redecl -redef@*/
-/*@mayexit@*/ /*@only@*/ /*@unused@*/
-char * xstrdup (const char *str)
-       /*@*/;
-/*@=redecl =redef@*/
+#ifndef HAVE_STRLCPY
+size_t strlcpy(char *d, const char *s, size_t bufsize);
+#endif
+
+#ifndef HAVE_STRLCAT
+size_t strlcat(char *d, const char *s, size_t bufsize);
+#endif
 
 #if HAVE_MCHECK_H && defined(__GNUC__)
-#define        vmefail()       (fprintf(stderr, "virtual memory exhausted.\n"), exit(EXIT_FAILURE), NULL)
-#define xstrdup(_str)   (strcpy((malloc(strlen(_str)+1) ? : vmefail()), (_str)))
+static inline char *
+xstrdup(const char *s)
+{
+    size_t memsize = strlen(s) + 1;
+    char *ptr = malloc(memsize);
+    if (!ptr) {
+       fprintf(stderr, "virtual memory exhausted.\n");
+       exit(EXIT_FAILURE);
+    }
+    strlcpy(ptr, s, memsize);
+    return ptr;
+}
 #else
 #define        xstrdup(_str)   strdup(_str)
 #endif  /* HAVE_MCHECK_H && defined(__GNUC__) */
@@ -89,24 +118,13 @@ char * xstrdup (const char *str)
 #define        getenv(_s)      __secure_getenv(_s)
 #endif
 
-#ifndef HAVE_STRLCPY
-size_t strlcpy(char *d, const char *s, size_t bufsize);
-#endif
-
-#ifndef HAVE_STRLCAT
-size_t strlcat(char *d, const char *s, size_t bufsize);
+#if !defined HAVE_SNPRINTF || !defined HAVE_C99_VSNPRINTF
+#define snprintf rsync_snprintf
+int snprintf(char *str,size_t count,const char *fmt,...);
 #endif
 
 #define UNUSED(x) x __attribute__((__unused__))
 
 #define PACKAGE "rsync"
 
-#ifndef DBL_EPSILON
-#define DBL_EPSILON 2.2204460492503131e-16
-#endif
-
-#ifdef _ABS
-#undef _ABS
-#endif
-
 #include "popt.h"