xref: /aosp_15_r20/bionic/libc/upstream-openbsd/android/include/openbsd-compat.h (revision 8d67ca893c1523eb926b9080dbe4e2ffd2a27ba1)
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 #pragma once
18 
19 #define _BSD_SOURCE
20 #include <sys/cdefs.h>
21 
22 #include <unistd.h> // For environ.
23 
24 #include <stddef.h> // For size_t.
25 
26 #include <sys/random.h> // For getentropy.
27 
28 #define __BEGIN_HIDDEN_DECLS _Pragma("GCC visibility push(hidden)")
29 #define __END_HIDDEN_DECLS _Pragma("GCC visibility pop")
30 
31 extern const char* __progname;
32 
33 /* Ignore all DEF_STRONG/DEF_WEAK in OpenBSD. */
34 #define DEF_STRONG(sym)
35 #define DEF_WEAK(sym)
36 #define __weak_alias __strong_alias
37 
38 /* Ignore all __warn_references in OpenBSD. */
39 #define __warn_references(sym,msg)
40 
41 #define PROTO_NORMAL(x)
42 
43 #if !defined(ANDROID_HOST_MUSL)
44 #define explicit_bzero(p, s) memset_explicit(p, 0, s)
45 #endif
46 
47 #if defined(ANDROID_HOST_MUSL)
48 #define __LIBC_HIDDEN__ __attribute__((visibility("hidden")))
49 #endif
50 
51 /* OpenBSD has this in paths.h. But this directory doesn't normally exist.
52  * Even when it does exist, only the 'shell' user has permissions.
53  */
54 #define _PATH_TMP "/data/local/tmp/"
55 
56 /* Use appropriate shell depending on process's executable. */
57 __LIBC_HIDDEN__ extern const char* __bionic_get_shell_path();
58 #define _PATH_BSHELL __bionic_get_shell_path()
59 
60 __LIBC_HIDDEN__ extern char* __findenv(const char*, int, int*);
61 __LIBC_HIDDEN__ extern char* _mktemp(char*);
62 
63 // Only OpenBSD has this at the moment, and we're more likely to just say
64 // "malloc is always calloc", so we don't expose this as libc API.
65 __LIBC_HIDDEN__ void* recallocarray(void*, size_t, size_t, size_t);
66