- Define snprintf() when needed.
[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 */
b348deae 78char *alloca ();
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
88#elif defined(__GNUC__) && defined(__STRICT_ANSI__)
89#define alloca __builtin_alloca
90#endif
91
cc248aae 92/*@-redecl -redef@*/
bc93ee84
WD
93/*@mayexit@*/ /*@only@*/ /*@unused@*/
94char * xstrdup (const char *str)
cc248aae
WD
95 /*@*/;
96/*@=redecl =redef@*/
b348deae
MP
97
98#if HAVE_MCHECK_H && defined(__GNUC__)
99#define vmefail() (fprintf(stderr, "virtual memory exhausted.\n"), exit(EXIT_FAILURE), NULL)
100#define xstrdup(_str) (strcpy((malloc(strlen(_str)+1) ? : vmefail()), (_str)))
101#else
102#define xstrdup(_str) strdup(_str)
103#endif /* HAVE_MCHECK_H && defined(__GNUC__) */
104
bc93ee84
WD
105#if HAVE___SECURE_GETENV && !defined(__LCLINT__)
106#define getenv(_s) __secure_getenv(_s)
107#endif
108
109#ifndef HAVE_STRLCPY
110size_t strlcpy(char *d, const char *s, size_t bufsize);
111#endif
112
113#ifndef HAVE_STRLCAT
114size_t strlcat(char *d, const char *s, size_t bufsize);
115#endif
116
9775d6ab
WD
117#if !defined HAVE_SNPRINTF || !defined HAVE_C99_VSNPRINTF
118#define snprintf rsync_snprintf
119int snprintf(char *str,size_t count,const char *fmt,...);
120#endif
121
73042aae
WD
122#define UNUSED(x) x __attribute__((__unused__))
123
bc93ee84
WD
124#define PACKAGE "rsync"
125
126#ifndef DBL_EPSILON
127#define DBL_EPSILON 2.2204460492503131e-16
128#endif
129
130#ifdef _ABS
131#undef _ABS
132#endif
133
b348deae 134#include "popt.h"