xref: /freebsd/contrib/unifdef/win32/unifdef.h (revision 22cf89c938886d14f5796fc49f9f020c23ea8eaf)
1 /*
2  * Copyright (c) 2012 - 2015 Tony Finch <dot@dotat.at>
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23  * SUCH DAMAGE.
24  */
25 
26 /* Stop being stupid about POSIX functions */
27 #define _CRT_SECURE_NO_WARNINGS
28 #define _SCL_SECURE_NO_WARNINGS
29 #define _CRT_NONSTDC_NO_WARNINGS
30 
31 #include <ctype.h>
32 #include <errno.h>
33 #include <stdarg.h>
34 #include <stdio.h>
35 #include <stdint.h>
36 #include <stdlib.h>
37 #include <string.h>
38 
39 /* Windows POSIX-flavoured headers */
40 
41 #include <sys/stat.h>
42 #include <fcntl.h>
43 #include <io.h>
44 
45 #define stat     _stat
46 
47 /* fake stdbool.h */
48 #define true 1
49 #define false 0
50 #define bool int
51 
52 /* used by err.c and getopt.c */
53 #define _getprogname() "unifdef"
54 
55 /*
56  * The snprintf() workaround is unnecessary in Visual Studio 2015 or later
57  * but dogma dictates that #if directives are not allowed inside unifdef.
58  */
59 #define snprintf c99_snprintf
60 
61 /* win32.c */
62 int replace(const char *oldname, const char *newname);
63 FILE *mktempmode(char *tmp, int mode);
64 FILE *fbinmode(FILE *fp);
65 int c99_snprintf(char *buf, size_t buflen, const char *format, ...);
66 
67 /* err.c */
68 void err(int, const char *, ...);
69 void verr(int, const char *, va_list);
70 void errc(int, int, const char *, ...);
71 void verrc(int, int, const char *, va_list);
72 void errx(int, const char *, ...);
73 void verrx(int, const char *, va_list);
74 void warn(const char *, ...);
75 void vwarn(const char *, va_list);
76 void warnc(int, const char *, ...);
77 void vwarnc(int, const char *, va_list);
78 void warnx(const char *, ...);
79 void vwarnx(const char *, va_list);
80 
81 /* getopt.c */
82 int getopt(int nargc, char *nargv[], const char *ostr);
83 extern int opterr, optind, optopt, optreset;
84 extern char *optarg;
85