Allow any gcc to make use of __builtin_alloca for alloca.
[rsync/rsync.git] / popt / system.h
1 #ifdef HAVE_CONFIG_H
2 #include "config.h"
3 #endif
4
5 #if defined (__GLIBC__) && defined(__LCLINT__)
6 /*@-declundef@*/
7 /*@unchecked@*/
8 extern __const __int32_t *__ctype_tolower;
9 /*@unchecked@*/
10 extern __const __int32_t *__ctype_toupper;
11 /*@=declundef@*/
12 #endif
13
14 #include <ctype.h>
15
16 #include <errno.h>
17 #include <fcntl.h>
18 #include <limits.h>
19
20 #if HAVE_MCHECK_H 
21 #include <mcheck.h>
22 #endif
23
24 #include <stdio.h>
25 #ifdef HAVE_SYS_TYPES_H
26 # include <sys/types.h>
27 #endif
28 #ifdef STDC_HEADERS
29 # include <stdlib.h>
30 # include <stddef.h>
31 #else
32 # ifdef HAVE_STDLIB_H
33 #  include <stdlib.h>
34 # endif
35 #endif
36 #ifdef HAVE_STRING_H
37 # if !defined STDC_HEADERS && defined HAVE_MEMORY_H
38 #  include <memory.h>
39 # endif
40 # include <string.h>
41 #endif
42 #ifdef HAVE_STRINGS_H
43 # include <strings.h>
44 #endif
45 #ifdef HAVE_UNISTD_H
46 # include <unistd.h>
47 #endif
48
49 #ifndef __GNUC__
50 #define __attribute__(x) 
51 #endif
52
53 #ifdef __NeXT
54 /* access macros are not declared in non posix mode in unistd.h -
55  don't try to use posix on NeXTstep 3.3 ! */
56 #include <libc.h>
57 #endif
58
59 #if defined(__LCLINT__)
60 /*@-declundef -incondefs @*/ /* LCL: missing annotation */
61 /*@only@*/ /*@out@*/
62 void * alloca (size_t __size)
63         /*@ensures MaxSet(result) == (__size - 1) @*/
64         /*@*/;
65 /*@=declundef =incondefs @*/
66 #endif
67
68 /* AIX requires this to be the first thing in the file.  */ 
69 #ifndef __GNUC__
70 # if HAVE_ALLOCA_H
71 #  include <alloca.h>
72 # else
73 #  ifdef _AIX
74 #pragma alloca
75 #  else
76 #   ifdef HAVE_ALLOCA
77 #    ifndef alloca /* predefined by HP cc +Olibcalls */
78 char *alloca(size_t size);
79 #    endif
80 #   else
81 #    ifdef alloca
82 #     undef alloca
83 #    endif
84 #    define alloca(sz) malloc(sz) /* Kludge this for now */
85 #   endif
86 #  endif
87 # endif
88 #elif !defined(alloca)
89 #define alloca __builtin_alloca
90 #endif
91
92 #ifndef HAVE_STRLCPY
93 size_t strlcpy(char *d, const char *s, size_t bufsize);
94 #endif
95
96 #ifndef HAVE_STRLCAT
97 size_t strlcat(char *d, const char *s, size_t bufsize);
98 #endif
99
100 #if HAVE_MCHECK_H && defined(__GNUC__)
101 static inline char *
102 xstrdup(const char *s)
103 {
104     size_t memsize = strlen(s) + 1;
105     char *ptr = malloc(memsize);
106     if (!ptr) {
107         fprintf(stderr, "virtual memory exhausted.\n");
108         exit(EXIT_FAILURE);
109     }
110     strlcpy(ptr, s, memsize);
111     return ptr;
112 }
113 #else
114 #define xstrdup(_str)   strdup(_str)
115 #endif  /* HAVE_MCHECK_H && defined(__GNUC__) */
116
117 #if HAVE___SECURE_GETENV && !defined(__LCLINT__)
118 #define getenv(_s)      __secure_getenv(_s)
119 #endif
120
121 #if !defined HAVE_SNPRINTF || !defined HAVE_C99_VSNPRINTF
122 #define snprintf rsync_snprintf
123 int snprintf(char *str,size_t count,const char *fmt,...);
124 #endif
125
126 #define UNUSED(x) x __attribute__((__unused__))
127
128 #define PACKAGE "rsync"
129
130 #include "popt.h"