Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/pkg
Path: blob/main/compat/bsd_compat.h
2065 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
#ifndef HAVE_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
#ifdef HAVE_BSD_STDLIB_H
56
#include <bsd/stdlib.h>
57
#endif
58
59
#ifdef HAVE_BSD_UNISTD_H
60
#include <bsd/unistd.h>
61
#endif
62
63
#ifdef HAVE_BSD_STRING_H
64
#include <bsd/string.h>
65
#endif
66
67
#ifdef HAVE_BSD_STDIO_H
68
#include <bsd/stdio.h>
69
#endif
70
71
#ifdef HAVE_BSD_STLIB_H
72
#include <bsd/stdlib.h>
73
#endif
74
75
#ifdef HAVE_BSD_ERR_H
76
#include <bsd/err.h>
77
#endif
78
79
#ifdef HAVE_BSD_LIBUTIL_H
80
#include <bsd/libutil.h>
81
#endif
82
83
#ifdef HAVE_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_EACCESS
92
#define eaccess(_p, _m) access(_p, _m)
93
#endif
94
95
#if !HAVE_HUMANIZE_NUMBER
96
#include "humanize_number.h"
97
#endif
98
99
#if !HAVE_CLOSEFROM
100
void closefrom(int lowfd);
101
#endif
102
103
#ifndef AT_FDCWD
104
#define AT_FDCWD -100
105
#endif
106
107
#ifndef AT_EACCESS
108
#define AT_EACCESS 0x100
109
#endif
110
111
#ifndef AT_SYMLINK_NOFOLLOW
112
#define AT_SYMLINK_NOFOLLOW 0x200
113
#endif
114
115
#if !HAVE_FACCESSAT
116
int faccessat(int fd, const char *path, int mode, int flag);
117
#endif
118
119
#if !HAVE_FSTATAT
120
int fstatat(int fd, const char *path, struct stat *buf, int flag);
121
#endif
122
123
#if !HAVE_OPENAT
124
int openat(int fd, const char *path, int flags, ...);
125
#endif
126
127
#if !HAVE_READLINKAT
128
ssize_t readlinkat(int fd, const char *restrict path, char *restrict buf, size_t bufsize);
129
#endif
130
131
#if !HAVE_UNLINKAT
132
# ifndef AT_REMOVEDIR
133
# define AT_REMOVEDIR 0x800
134
# endif
135
int unlinkat(int fd, const char *path, int flag);
136
#endif
137
138
#if !HAVE_STRTONUM
139
long long strtonum(const char *, long long, long long, const char **);
140
#endif
141
142
#if !HAVE_STRNSTR
143
char * strnstr(const char *s, const char *find, size_t slen);
144
#endif
145
146
#ifndef _PATH_GROUP
147
#define _PATH_GROUP "/etc/group"
148
#endif
149
150
#ifndef __FBSDID
151
#define __FBSDID(x)
152
#endif
153
154
#ifndef EAUTH
155
#define EAUTH 80
156
#endif
157
158
#ifndef ENEEDAUTH
159
#define ENEEDAUTH 81
160
#endif
161
162
#ifndef MAXLOGNAME
163
#define MAXLOGNAME 33
164
#endif
165
166
#ifndef __DECONST
167
#define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var))
168
#endif
169
170
#ifndef __unused
171
#if defined(__GNUC__) || defined(__clang__)
172
# define __unused __attribute__((__unused__))
173
#else
174
# define __unused
175
#endif
176
#endif
177
178
#ifndef __unreachable
179
# if defined (__GNUC__) || defined (__clang__)
180
# define __unreachable() __builtin_unreachable()
181
# else
182
# define __unreachable() ((void)0)
183
# endif
184
#endif
185
186
#if !HAVE_FUNOPEN
187
#if !HAVE_FOPENCOOKIE
188
# error "Your system has neither funopen nor fopencookie, cannot continue"
189
#endif
190
FILE * funopen(const void *cookie, int (*readfn)(void *, char *, int),
191
int (*writefn)(void *, const char *, int),
192
off_t (*seekfn)(void *, off_t, int), int (*closefn)(void *));
193
#endif
194
195
#if !HAVE_GETPROGNAME
196
# if defined (__linux__) && defined (__GLIBC__)
197
extern char *program_invocation_short_name;
198
# define getprogname() program_invocation_short_name
199
# elif defined (__linux__) && !defined (__GLIBC__)
200
extern char *__progname;
201
# define getprogname() __progname
202
# else
203
# error "Don't know how to replace getprogname()"
204
# endif
205
#endif
206
207
#endif
208
209