aboutsummaryrefslogtreecommitdiff
path: root/lib/libopenbsd/openbsd.h
blob: edbd729216b9f3d5cdd1b6d603942652c42502a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#ifndef _OPENBSD_H
#define _OPENBSD_H
/* #define _GNU_SOURCE */
/* #include <stdarg.h> */
/* #include <stdint.h> */
/* #include <limits.h> */
/* #include <sys/types.h> */
/* #undef _GNU_SOURCE */
/* #undef _FEATURES_H */

#define FAIL_INSTEAD_OF_TRYING_FALLBACK

/* XXX: x86_64 only, see sys/arch/$arch/include/_types.h */
#define ALIGNBYTES		(sizeof(long) - 1)
#define ALIGN(p) (((u_int)(p) + ALIGNBYTES) &~ ALIGNBYTES)

#define __UNUSED		__attribute__ ((unused))

#define __dead		__attribute__((__noreturn__))

#define __BEGIN_DECLS
#define __END_DECLS

#undef __weak_alias
#define __weak_alias(new, old) \
	extern __typeof(old) new __attribute__((weak, alias(#old)))

#define MAKE_CLONE(new, old) \
	extern __typeof(old) new __attribute__((weak, alias(#old)))

#ifndef SA_LEN
#define SA_LEN(X) \
	(((struct sockaddr*)(X))->sa_family == AF_INET ? sizeof(struct sockaddr_in) : \
	 ((struct sockaddr*)(X))->sa_family == AF_INET6 ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr))
#endif

#define	_PW_BUF_LEN	1024
#define	_GR_BUF_LEN	1024

#define NOFILE_MAX	NOFILE

#if !defined(HAVE_ATTRIBUTE__BOUNDED__)
#define __bounded__(x, y, z)
#endif

#if !defined(DEF_WEAK)
#define DEF_WEAK(x)
#endif

#if !defined(DEF_STRONG)
#define DEF_STRONG(x)
#endif

#if !defined(PROTO_NORMAL)
#define PROTO_NORMAL(x)
#endif

/* sys/sys/param.h */
/*
 * File system parameters and macros.
 *
 * The file system is made out of blocks of at most MAXBSIZE units, with
 * smaller units (fragments) only in the last direct block.  MAXBSIZE
 * primarily determines the size of buffers in the buffer pool.  It may be
 * made larger without any effect on existing file systems; however making
 * it smaller makes some file systems unmountable.
 */
#define	MAXBSIZE	(64 * 1024)

#ifndef NL_TEXTMAX
#define	NL_TEXTMAX	2048
#endif

#ifndef howmany
#define howmany(n,d) (((n)+((d)-1))/(d))
#endif

/* API definitions lifted from OpenBSD src/include */

/* pwd.h */
#define _PW_NAME_LEN 63

/* stdlib.h */

/* unistd.h */
#ifndef HAVE_EXECVPE
int execvpe(const char *, char *const *, char *const *);
#endif /* !HAVE_EXECVPE */
#ifndef HAVE_SETRESUID
/* int setresuid(uid_t, uid_t, uid_t); */
#endif /* !HAVE_SETRESUID */

#ifndef HAVE_PLEDGE
int pledge(const char *, const char *[]);
#endif /* !HAVE_PLEDGE */

#ifndef HAVE_SETPROGNAME
const char * getprogname(void);
void setprogname(const char *progname);
#endif /* !HAVE_SETPROGNAME */

/* pwcache.c */
/* char *user_from_uid(uid_t, int); */
/* char *group_from_gid(gid_t gid, int); */

/* getbsize.c */
char *getbsize(int *, long *);

/* base64.c */
/*
int b64_ntop(unsigned char const *, size_t, char *, size_t);
int b64_pton(char const *, unsigned char *, size_t);
*/

#define strtoq strtoll

/* inttypes.h */
/*
intmax_t	strtoimax(const char *, char **, int);
uintmax_t	strtoumax(const char *, char **, int);
*/

/* #define d_namlen d_reclen */
#if !defined(_DIRENT_HAVE_NAMLEN)
#define D_NAMLEN(x) \
	strnlen((x)->d_name, (x)->d_reclen)
#else
#define D_NAMLEN(x) \
	(x)->d_namlen
#endif

/* XXX: read dynamically? */
#define UID_MAX 60000
#define GID_MAX 60000

/* sys/sys/stat.h */
#define	ACCESSPERMS	(S_IRWXU|S_IRWXG|S_IRWXO)	/* 00777 */
#define	ALLPERMS	 (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO) /* 00666 */
#define	DEFFILEMODE	(S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)

#define S_ISTXT S_ISVTX

/* lib/libc/include/thread_private.h */
#define _MUTEX_LOCK(mutex)				do {} while (0)
#define _MUTEX_UNLOCK(mutex)				do {} while (0)

#define SHA512_Update SHA512Update
#define SHA512_CTX SHA2_CTX
#define SHA512_Init SHA512Init
#define SHA512_Final SHA512Final

/* setproctitle.c */
void setproctitle(const char *, ...);

/* pw_dup.c */
struct passwd *pw_dup(const struct passwd *);

int issetugid(void);
#endif