Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/compat/bsd_compat.h
2649 views
1
/*-
2
* Copyright (c) 2014 Landon Fuller <[email protected]>
3
* All rights reserved.
4
*
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
7
* are met:
8
* 1. Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer
10
* in this position and unchanged.
11
* 2. Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
*
15
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25
*/
26
27
#ifndef _BSD_COMPAT_H
28
#define _BSD_COMPAT_H
29
30
#include "pkg_config.h"
31
32
#ifdef __OpenBSD__
33
#include "../external/libelf/_elftc.h"
34
35
#ifndef EPROTO
36
#define EPROTO EINTR
37
#endif
38
#endif
39
40
#if !__has_include(<bsd/sys/cdefs.h>)
41
42
#include <sys/cdefs.h>
43
44
#else
45
46
/* Deal with broken __DECONST */
47
#ifndef __uintptr_t
48
# include <stdint.h>
49
# define __uintptr_t uintptr_t
50
#endif
51
52
#include <bsd/sys/cdefs.h>
53
#endif
54
55
#if __has_include(<bsd/stdlib.h>)
56
#include <bsd/stdlib.h>
57
#endif
58
59
#if __has_include(<bsd/unistd.h>)
60
#include <bsd/unistd.h>
61
#endif
62
63
#if __has_include(<bsd/string.h>)
64
#include <bsd/string.h>
65
#endif
66
67
#if __has_include(<bsd/stdio.h>)
68
#include <bsd/stdio.h>
69
#endif
70
71
#if __has_include(<bsd/stdlib.h>)
72
#include <bsd/stdlib.h>
73
#endif
74
75
#if __has_include(<bsd/err.h>)
76
#include <bsd/err.h>
77
#endif
78
79
#if __has_include(<bsd/libutil.h>)
80
#include <bsd/libutil.h>
81
#endif
82
83
#if __has_include(<bsd/sys/time.h>)
84
#include <bsd/sys/time.h>
85
#endif
86
87
#include <sys/fcntl.h>
88
#include <sys/stat.h>
89
#include "endian_util.h"
90
91
#if !HAVE_HUMANIZE_NUMBER
92
#include "humanize_number.h"
93
#endif
94
95
#if !HAVE_CLOSEFROM
96
void closefrom(int lowfd);
97
#endif
98
99
#ifndef AT_FDCWD
100
#define AT_FDCWD -100
101
#endif
102
103
#ifndef AT_SYMLINK_NOFOLLOW
104
#define AT_SYMLINK_NOFOLLOW 0x200
105
#endif
106
107
#if !HAVE_STRTONUM
108
long long strtonum(const char *, long long, long long, const char **);
109
#endif
110
111
#ifndef _PATH_GROUP
112
#define _PATH_GROUP "/etc/group"
113
#endif
114
115
#ifndef __FBSDID
116
#define __FBSDID(x)
117
#endif
118
119
#ifndef EAUTH
120
#define EAUTH 80
121
#endif
122
123
#ifndef ENEEDAUTH
124
#define ENEEDAUTH 81
125
#endif
126
127
#ifndef MAXLOGNAME
128
#define MAXLOGNAME 33
129
#endif
130
131
#ifndef __DECONST
132
#define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var))
133
#endif
134
135
#ifndef __unused
136
#if defined(__GNUC__) || defined(__clang__)
137
# define __unused __attribute__((__unused__))
138
#else
139
# define __unused
140
#endif
141
#endif
142
143
#ifndef __unreachable
144
# if defined (__GNUC__) || defined (__clang__)
145
# define __unreachable() __builtin_unreachable()
146
# else
147
# define __unreachable() ((void)0)
148
# endif
149
#endif
150
151
#if !HAVE_FUNOPEN
152
#if !HAVE_FOPENCOOKIE
153
# error "Your system has neither funopen nor fopencookie, cannot continue"
154
#endif
155
FILE * funopen(const void *cookie, int (*readfn)(void *, char *, int),
156
int (*writefn)(void *, const char *, int),
157
off_t (*seekfn)(void *, off_t, int), int (*closefn)(void *));
158
#endif
159
160
#if !HAVE_GETPROGNAME
161
# if defined (__linux__) && defined (__GLIBC__)
162
extern char *program_invocation_short_name;
163
# define getprogname() program_invocation_short_name
164
# elif defined (__linux__) && !defined (__GLIBC__)
165
extern char *__progname;
166
# define getprogname() __progname
167
# else
168
# error "Don't know how to replace getprogname()"
169
# endif
170
#endif
171
172
#endif
173
174