1/*
2 * Copyright (C) 2014 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _BIONIC_OPENBSD_COMPAT_H_included
18#define _BIONIC_OPENBSD_COMPAT_H_included
19
20#define _BSD_SOURCE
21#include <sys/cdefs.h>
22
23#include <stddef.h> // For size_t.
24
25// TODO: libandroid_support uses this file, so we need to wait for
26// <sys/random.h> to be in the NDK headers before we can lose this declaration.
27//#include <sys/random.h> // For getentropy.
28int getentropy(void*, size_t);
29
30#define __BEGIN_HIDDEN_DECLS _Pragma("GCC visibility push(hidden)")
31#define __END_HIDDEN_DECLS _Pragma("GCC visibility pop")
32
33extern const char* __progname;
34
35/* Redirect internal C library calls to the public function. */
36#define _err err
37#define _errx errx
38#define _verr verr
39#define _verrx verrx
40#define _vwarn vwarn
41#define _vwarnx vwarnx
42#define _warn warn
43#define _warnx warnx
44
45/* Ignore all DEF_STRONG/DEF_WEAK in OpenBSD. */
46#define DEF_STRONG(sym)
47#define DEF_WEAK(sym)
48#define __weak_alias __strong_alias
49
50/* Ignore all __warn_references in OpenBSD. */
51#define __warn_references(sym,msg)
52
53/* OpenBSD's <ctype.h> uses these names, which conflicted with stlport.
54 * Additionally, we changed the numeric/digit type from N to D for libcxx.
55 */
56#define _U _CTYPE_U
57#define _L _CTYPE_L
58#define _N _CTYPE_D
59#define _S _CTYPE_S
60#define _P _CTYPE_P
61#define _C _CTYPE_C
62#define _X _CTYPE_X
63#define _B _CTYPE_B
64
65/* OpenBSD has this, but we can't really implement it correctly on Linux. */
66#define issetugid() 0
67
68#define explicit_bzero(p, s) memset(p, 0, s)
69
70/* OpenBSD has these in <sys/param.h>, but "ALIGN" isn't something we want to reserve. */
71#define ALIGNBYTES (sizeof(uintptr_t) - 1)
72#define ALIGN(p) (((uintptr_t)(p) + ALIGNBYTES) &~ ALIGNBYTES)
73
74/* OpenBSD has this in paths.h. But this directory doesn't normally exist.
75 * Even when it does exist, only the 'shell' user has permissions.
76 */
77#define _PATH_TMP "/data/local/tmp/"
78
79/* Use appropriate shell depending on process's executable. */
80__LIBC_HIDDEN__ extern const char* __bionic_get_shell_path();
81#define _PATH_BSHELL __bionic_get_shell_path()
82
83/* OpenBSD has this as API, but we just use it internally. */
84__LIBC_HIDDEN__ void* reallocarray(void*, size_t, size_t);
85
86/* LP32 NDK ctype.h contained references to these. */
87__LIBC32_LEGACY_PUBLIC__ extern const short* _tolower_tab_;
88__LIBC32_LEGACY_PUBLIC__ extern const short* _toupper_tab_;
89
90__LIBC_HIDDEN__ extern const char _C_ctype_[];
91__LIBC_HIDDEN__ extern const short _C_toupper_[];
92__LIBC_HIDDEN__ extern const short _C_tolower_[];
93__LIBC_HIDDEN__ extern char* __findenv(const char*, int, int*);
94__LIBC_HIDDEN__ extern char* _mktemp(char*);
95
96#endif
97