util: refactor to use DETECT_OS_ANDROID

except leaving u_endian.h behind to use __ANDROID__ directly to be
consistent with the rest in that file, which deserves a different
refactor

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Reviewed-by: Yonggang Luo <luoyonggang@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27374>
This commit is contained in:
Yiwei Zhang 2024-01-30 14:18:01 -08:00 committed by Marge Bot
parent 569437221d
commit 53d9debcf4
9 changed files with 17 additions and 13 deletions

View file

@ -46,7 +46,7 @@
#include <stdio.h>
#endif
#if !(defined(__FreeBSD__) || defined(HAVE_MEMFD_CREATE) || defined(HAVE_MKOSTEMP) || defined(ANDROID))
#if !(defined(__FreeBSD__) || defined(HAVE_MEMFD_CREATE) || defined(HAVE_MKOSTEMP) || DETECT_OS_ANDROID)
static int
set_cloexec_or_close(int fd)
{
@ -70,7 +70,7 @@ err:
}
#endif
#if !(defined(__FreeBSD__) || defined(HAVE_MEMFD_CREATE) || defined(ANDROID))
#if !(defined(__FreeBSD__) || defined(HAVE_MEMFD_CREATE) || DETECT_OS_ANDROID)
static int
create_tmpfile_cloexec(char *tmpname)
{

View file

@ -38,11 +38,13 @@
#include <unistd.h>
#include <time.h>
#include "util/detect_os.h"
#if defined(__cplusplus)
extern "C" {
#endif
#ifdef ANDROID
#if DETECT_OS_ANDROID
/* On Android, rely on the system's libsync instead of rolling our own
* sync_wait() and sync_merge(). This gives us compatibility with pre-4.7
* Android kernels.
@ -157,7 +159,7 @@ sync_valid_fd(int fd)
return ioctl(fd, SYNC_IOC_FILE_INFO, &info) >= 0;
}
#endif /* !ANDROID */
#endif /* DETECT_OS_ANDROID */
/* accumulate fd2 into fd1. If *fd1 is not a valid fd then dup fd2,
* otherwise sync_merge() and close the old *fd1. This can be used

View file

@ -128,7 +128,7 @@ os_malloc_aligned_fd(size_t size, size_t alignment, int *fd, char const *fd_name
if(mem_fd < 0)
return NULL;
#if defined(HAVE_MEMFD_CREATE) || defined(ANDROID)
#if defined(HAVE_MEMFD_CREATE) || DETECT_OS_ANDROID
// Seal fd, so no one can grow or shrink the memory.
if (fcntl(mem_fd, F_ADD_SEALS, F_SEAL_SHRINK | F_SEAL_GROW | F_SEAL_SEAL) != 0)
goto fail;

View file

@ -9,6 +9,7 @@
#include "u_perfetto.h"
#include "u_gpuvis.h"
#include "util/detect_os.h"
#include "util/macros.h"
#if defined(HAVE_PERFETTO)
@ -33,7 +34,7 @@
*
* https://github.com/android/ndk/issues/1178
*/
#elif defined(ANDROID) && !defined(__cplusplus)
#elif DETECT_OS_ANDROID && !defined(__cplusplus)
#include <cutils/trace.h>

View file

@ -37,6 +37,7 @@
#include <time.h>
#include <unistd.h>
#include "util/detect_os.h"
#include "util/mesa-sha1.h"
#include "util/disk_cache.h"
#include "util/disk_cache_os.h"
@ -190,7 +191,7 @@ test_disk_cache_create(void *mem_ctx, const char *cache_dir_name,
disk_cache_destroy(cache);
#ifdef ANDROID
#if DETECT_OS_ANDROID
/* Android doesn't try writing to disk (just calls the cache callbacks), so
* the directory tests below don't apply.
*/

View file

@ -179,7 +179,7 @@ debug_backtrace_print(FILE *f,
frame_ip(&backtrace[i]));
}
}
#elif defined(ANDROID)
#elif DETECT_OS_ANDROID
/* Not implemented here; see u_debug_stack_android.cpp */
#else /* ! HAVE_LIBUNWIND */

View file

@ -82,7 +82,7 @@
# define UTIL_ARCH_BIG_ENDIAN 1
#endif
#elif defined(_WIN32) || defined(ANDROID)
#elif defined(_WIN32) || defined(__ANDROID__)
#define UTIL_ARCH_LITTLE_ENDIAN 1
#define UTIL_ARCH_BIG_ENDIAN 0

View file

@ -103,7 +103,7 @@ __getProgramName()
{
return strdup(program_invocation_short_name);
}
#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__APPLE__) || defined(ANDROID) || defined(__NetBSD__)
#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__APPLE__) || DETECT_OS_ANDROID || defined(__NetBSD__)
#if defined(__NetBSD__)
# include <sys/param.h>
#endif
@ -170,7 +170,7 @@ __getProgramName()
#endif
#if defined(GET_PROGRAM_NAME_NOT_AVAILABLE)
#if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__UCLIBC__) || defined(ANDROID)
#if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__UCLIBC__) || DETECT_OS_ANDROID
/* This is a hack. It's said to work on OpenBSD, NetBSD and GNU.
* Rogelio M.Serrano Jr. reported it's also working with UCLIBC. It's
* used as a last resort, if there is no documented facility available. */

View file

@ -20,7 +20,7 @@
#include <OS.h>
#endif
#if DETECT_OS_LINUX && !defined(ANDROID)
#if DETECT_OS_LINUX && !DETECT_OS_ANDROID
#include <sched.h>
#elif defined(_WIN32) && !defined(HAVE_PTHREAD)
#include <windows.h>
@ -37,7 +37,7 @@
int
util_get_current_cpu(void)
{
#if DETECT_OS_LINUX && !defined(ANDROID)
#if DETECT_OS_LINUX && !DETECT_OS_ANDROID
return sched_getcpu();
#elif defined(_WIN32) && !defined(HAVE_PTHREAD)