Allow any gcc to make use of __builtin_alloca for alloca.
[rsync/rsync.git] / popt / system.h
CommitLineData
b348deae
MP
1#ifdef HAVE_CONFIG_H
2#include "config.h"
3#endif
4
bc93ee84
WD
5#if defined (__GLIBC__) && defined(__LCLINT__)
6/*@-declundef@*/
7/*@unchecked@*/
8extern __const __int32_t *__ctype_tolower;
9/*@unchecked@*/
10extern __const __int32_t *__ctype_toupper;
11/*@=declundef@*/
12#endif
13
b348deae 14#include <ctype.h>
bc93ee84 15
b348deae
MP
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>
9775d6ab
WD
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>
b348deae
MP
47#endif
48
bc93ee84 49#ifndef __GNUC__
73042aae 50#define __attribute__(x)
73042aae
WD
51#endif
52
b348deae
MP
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
cc248aae 59#if defined(__LCLINT__)
bc93ee84
WD
60/*@-declundef -incondefs @*/ /* LCL: missing annotation */
61/*@only@*/ /*@out@*/
62void * alloca (size_t __size)
cc248aae
WD
63 /*@ensures MaxSet(result) == (__size - 1) @*/
64 /*@*/;
bc93ee84 65/*@=declundef =incondefs @*/
cc248aae
WD
66#endif
67
b348deae
MP
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
bc93ee84 76# ifdef HAVE_ALLOCA
74474192 77# ifndef alloca /* predefined by HP cc +Olibcalls */
574a24a2 78char *alloca(size_t size);
74474192
WD
79# endif
80# else
81# ifdef alloca
82# undef alloca
83# endif
84# define alloca(sz) malloc(sz) /* Kludge this for now */
b348deae
MP
85# endif
86# endif
87# endif
12e59929 88#elif !defined(alloca)
b348deae
MP
89#define alloca __builtin_alloca
90#endif
91
89a0e3a9
WD
92#ifndef HAVE_STRLCPY
93size_t strlcpy(char *d, const char *s, size_t bufsize);
94#endif
95
96#ifndef HAVE_STRLCAT
97size_t strlcat(char *d, const char *s, size_t bufsize);
98#endif
99
b348deae 100#if HAVE_MCHECK_H && defined(__GNUC__)
89a0e3a9
WD
101static inline char *
102xstrdup(const char *s)
103{
104 size_t memsize = strlen(s) + 1;
105 char *ptr = malloc(memsize);
e0930845
WD
106 if (!ptr) {
107 fprintf(stderr, "virtual memory exhausted.\n");
108 exit(EXIT_FAILURE);
109 }
89a0e3a9
WD
110 strlcpy(ptr, s, memsize);
111 return ptr;
112}
b348deae
MP
113#else
114#define xstrdup(_str) strdup(_str)
115#endif /* HAVE_MCHECK_H && defined(__GNUC__) */
116
bc93ee84
WD
117#if HAVE___SECURE_GETENV && !defined(__LCLINT__)
118#define getenv(_s) __secure_getenv(_s)
119#endif
120
9775d6ab
WD
121#if !defined HAVE_SNPRINTF || !defined HAVE_C99_VSNPRINTF
122#define snprintf rsync_snprintf
123int snprintf(char *str,size_t count,const char *fmt,...);
124#endif
125
73042aae
WD
126#define UNUSED(x) x __attribute__((__unused__))
127
bc93ee84
WD
128#define PACKAGE "rsync"
129
b348deae 130#include "popt.h"