vitunes
 All Data Structures
compat.h
1 /*
2  * Copyright (c) 2010, 2011, 2012 Ryan Flannery <ryan.flannery@gmail.com>
3  *
4  * Permission to use, copy, modify, and distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16 
17 /*
18  * Compatibility goo for other OS's. These files are intended to add
19  * support for various FEATURES that other OS's do not support. Kinda'
20  * like what autoconf is supposed to do, but doesn't.
21  *
22  * These files consist of the following:
23  *
24  * compat.h This file, which contains the main feature-goo, along
25  * with any OS specific goo. See below for details.
26  *
27  * compat.c The counterpart to this file, which includes all the
28  * necessary #includes of compat/ stuff to add various
29  * features.
30  *
31  * compat/ The directory containing all OpenBSD-specific
32  * features of vitunes that may be needed on other OS's.
33  *
34  */
35 
36 #ifndef COMPAT_H
37 #define COMPAT_H
38 
39 /* OpenBSD has fparseln(3), but it must be included thusly */
40 #if defined(__OpenBSD__)
41 # include <stdio.h>
42 # include <util.h>
43 # include <libgen.h>
44 #endif
45 
46 /* FreeBSD has fparseln(3), but it must be included thusly */
47 #if defined(__FreeBSD__)
48 # include <stdio.h>
49 # include <sys/types.h>
50 # include <libutil.h>
51 # include <libgen.h>
52 #endif
53 
54 /* Mac OS X has fparseln(3), but it must be included thusly */
55 #if defined(__MACH__)
56 # include <stdio.h>
57 # include <util.h>
58 #endif
59 
60 /* Mac OS X needs strtonum(3) */
61 #if defined(__APPLE__) && defined(__MACH__)
62 # include <inttypes.h>
63 # include <stdlib.h>
64 # define COMPAT_NEED_STRTONUM
65 # define COMPAT_NEED_STRTOLL
66 #endif
67 
68 /* Linux needs the following.. */
69 #if defined(__linux)
70 # define _GNU_SOURCE
71 # define COMPAT_NEED_FPARSELN
72 # define COMPAT_NEED_OPTRESET
73 # define COMPAT_NEED_STRLCAT
74 # define COMPAT_NEED_STRTONUM
75 
76 /* still unsure/curious about these last two */
77 # ifndef u_short
78  typedef unsigned short u_short;
79 # endif
80 # ifndef PATH_MAX
81 # include <linux/limits.h>
82 # else
83 # define PATH_MAX 4096
84 # endif
85 #endif
86 
87 
88 /* Now add necessary prototypes... */
89 
90 #ifdef COMPAT_NEED_FPARSELN
91 # include <stdio.h>
92  char *fparseln(FILE *fp, size_t *size, size_t *lineno,
93  const char str[3], int flags);
94 #endif
95 
96 #ifdef COMPAT_NEED_OPTRESET
97  extern int optreset;
98 #endif
99 
100 #ifdef COMPAT_NEED_STRLCAT
101  size_t strlcat(char *dst, const char *src, size_t siz);
102  size_t strlcpy(char *dst, const char *src, size_t siz);
103 #endif
104 
105 #ifdef COMPAT_NEED_STRTOLL
106  long long strtoll(const char *str, char **endptr, int base);
107 #endif
108 
109 #ifdef COMPAT_NEED_STRTONUM
110  long long strtonum(const char *, long long, long long, const char **);
111 #endif
112 
113 #endif