In a couple of more places, it makes sense to treat Android like Linux.
2019-01-26 Bruno Haible <br...@clisp.org> vma-iter: Add support for Android. * lib/vma-iter.h (VMA_ITERATE_SUPPORTED): Define on Android as well. * lib/vma-iter.c: Treat Android like Linux. * lib/get-rusage-data.c (get_rusage_data): Likewise. 2019-01-26 Bruno Haible <br...@clisp.org> getloadavg: Add support for Android. * lib/getloadavg.c: Treat Android like Linux. 2019-01-27 Bruno Haible <br...@clisp.org> relocatable-prog: Use Linux code on Android. * lib/progreloc.c: Treat Android like Linux. 2019-01-27 Bruno Haible <br...@clisp.org> tests: Enable Linux specific tests on Android. * tests/test-flock.c (main): Treat Android like Linux. * tests/test-openat-safer.c (main): Likewise.
>From 79b92f92dbba81d48f62e85b5b2dd8bdc4798c41 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Sun, 27 Jan 2019 04:57:29 +0100 Subject: [PATCH 1/4] vma-iter: Add support for Android. * lib/vma-iter.h (VMA_ITERATE_SUPPORTED): Define on Android as well. * lib/vma-iter.c: Treat Android like Linux. * lib/get-rusage-data.c (get_rusage_data): Likewise. --- ChangeLog | 7 +++++++ lib/get-rusage-data.c | 2 +- lib/vma-iter.c | 14 +++++++------- lib/vma-iter.h | 2 +- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index eec6a50..6fb03bc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2019-01-26 Bruno Haible <br...@clisp.org> + vma-iter: Add support for Android. + * lib/vma-iter.h (VMA_ITERATE_SUPPORTED): Define on Android as well. + * lib/vma-iter.c: Treat Android like Linux. + * lib/get-rusage-data.c (get_rusage_data): Likewise. + +2019-01-26 Bruno Haible <br...@clisp.org> + fts: Optimize on Android. * lib/fts.c: Treat Android like Linux. diff --git a/lib/get-rusage-data.c b/lib/get-rusage-data.c index cdd5d99..131cca7 100644 --- a/lib/get-rusage-data.c +++ b/lib/get-rusage-data.c @@ -413,7 +413,7 @@ get_rusage_data (void) Prefer get_rusage_data_via_iterator(). */ return get_rusage_data_via_iterator (); #elif HAVE_SETRLIMIT && defined RLIMIT_DATA && !defined __HAIKU__ -# if defined __linux__ || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ || defined _AIX || defined __hpux || defined __sgi || defined __osf__ || defined __sun /* Linux, FreeBSD, NetBSD, OpenBSD, AIX, HP-UX, IRIX, OSF/1, Solaris */ +# if defined __linux__ || defined __ANDROID__ || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ || defined _AIX || defined __hpux || defined __sgi || defined __osf__ || defined __sun /* Linux, FreeBSD, NetBSD, OpenBSD, AIX, HP-UX, IRIX, OSF/1, Solaris */ /* get_rusage_data_via_setrlimit() works. */ return get_rusage_data_via_setrlimit (); # else diff --git a/lib/vma-iter.c b/lib/vma-iter.c index d641570..5bf3906 100644 --- a/lib/vma-iter.c +++ b/lib/vma-iter.c @@ -40,11 +40,11 @@ #include <fcntl.h> /* open, O_RDONLY */ #include <unistd.h> /* getpagesize, lseek, read, close, getpid */ -#if defined __linux__ +#if defined __linux__ || defined __ANDROID__ # include <limits.h> /* PATH_MAX */ #endif -#if defined __linux__ || defined __FreeBSD_kernel__ || defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__ || defined __minix /* || defined __CYGWIN__ */ +#if defined __linux__ || defined __ANDROID__ || defined __FreeBSD_kernel__ || defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__ || defined __minix /* || defined __CYGWIN__ */ # include <sys/types.h> # include <sys/mman.h> /* mmap, munmap */ #endif @@ -112,7 +112,7 @@ /* Support for reading text files in the /proc file system. */ -#if defined __linux__ || defined __FreeBSD_kernel__ || defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__ || defined __minix /* || defined __CYGWIN__ */ +#if defined __linux__ || defined __ANDROID__ || defined __FreeBSD_kernel__ || defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__ || defined __minix /* || defined __CYGWIN__ */ /* Buffered read-only streams. We cannot use <stdio.h> here, because fopen() calls malloc(), and a malloc() @@ -129,7 +129,7 @@ VMAs with nonsensical addresses. So use mmap(), and ignore the resulting VMA. */ -# ifdef __linux__ +# if defined __linux__ || defined __ANDROID__ /* On Linux, if the file does not entirely fit into the buffer, the read() function stops before the line that would come out truncated. The maximum size of such a line is 73 + PATH_MAX bytes. To be sure that we @@ -205,7 +205,7 @@ rof_open (struct rofile *rof, const char *filename) { /* The buffer was sufficiently large. */ rof->filled = n; -# ifdef __linux__ +# if defined __linux__ || defined __ANDROID__ /* On Linux, the read() call may stop even if the buffer was large enough. We need the equivalent of full_read(). */ for (;;) @@ -342,7 +342,7 @@ rof_close (struct rofile *rof) /* Support for reading the info from a text file in the /proc file system. */ -#if defined __linux__ || (defined __FreeBSD_kernel__ && !defined __FreeBSD__) /* || defined __CYGWIN__ */ +#if defined __linux__ || defined __ANDROID__ || (defined __FreeBSD_kernel__ && !defined __FreeBSD__) /* || defined __CYGWIN__ */ /* GNU/kFreeBSD mounts /proc as linprocfs, which looks like a Linux /proc file system. */ @@ -866,7 +866,7 @@ vma_iterate_bsd (vma_iterate_callback_fn callback, void *data) int vma_iterate (vma_iterate_callback_fn callback, void *data) { -#if defined __linux__ || defined __FreeBSD_kernel__ || defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__ || defined __minix /* || defined __CYGWIN__ */ +#if defined __linux__ || defined __ANDROID__ || defined __FreeBSD_kernel__ || defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__ || defined __minix /* || defined __CYGWIN__ */ # if defined __FreeBSD__ /* On FreeBSD with procfs (but not GNU/kFreeBSD, which uses linprocfs), the diff --git a/lib/vma-iter.h b/lib/vma-iter.h index c1e1e5a..e319d5d 100644 --- a/lib/vma-iter.h +++ b/lib/vma-iter.h @@ -52,7 +52,7 @@ extern int vma_iterate (vma_iterate_callback_fn callback, void *data); this platform. Note that even when this macro is defined, vma_iterate() may still fail to find any virtual memory area, for example if /proc is not mounted. */ -#if defined __linux__ || defined __GNU__ || defined __FreeBSD_kernel__ || defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__ || defined __sgi || defined __osf__ || defined __sun || HAVE_PSTAT_GETPROCVM || (defined __APPLE__ && defined __MACH__) || defined _WIN32 || defined __CYGWIN__ || defined __BEOS__ || defined __HAIKU__ || defined __minix || HAVE_MQUERY +#if defined __linux__ || defined __ANDROID__ || defined __GNU__ || defined __FreeBSD_kernel__ || defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__ || defined __sgi || defined __osf__ || defined __sun || HAVE_PSTAT_GETPROCVM || (defined __APPLE__ && defined __MACH__) || defined _WIN32 || defined __CYGWIN__ || defined __BEOS__ || defined __HAIKU__ || defined __minix || HAVE_MQUERY # define VMA_ITERATE_SUPPORTED 1 #endif -- 2.7.4
>From 70152b70539454073fbcd503daeed368b1059f43 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Sun, 27 Jan 2019 04:57:32 +0100 Subject: [PATCH 2/4] getloadavg: Add support for Android. * lib/getloadavg.c: Treat Android like Linux. --- ChangeLog | 5 +++++ lib/getloadavg.c | 21 +++++++++++---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6fb03bc..80aeb34 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2019-01-26 Bruno Haible <br...@clisp.org> + getloadavg: Add support for Android. + * lib/getloadavg.c: Treat Android like Linux. + +2019-01-26 Bruno Haible <br...@clisp.org> + vma-iter: Add support for Android. * lib/vma-iter.h (VMA_ITERATE_SUPPORTED): Define on Android as well. * lib/vma-iter.c: Treat Android like Linux. diff --git a/lib/getloadavg.c b/lib/getloadavg.c index 0ed697f..3536647 100644 --- a/lib/getloadavg.c +++ b/lib/getloadavg.c @@ -47,8 +47,8 @@ N_NAME_POINTER The nlist n_name element is a pointer, not an array. HAVE_STRUCT_NLIST_N_UN_N_NAME 'n_un.n_name' is member of 'struct nlist'. - LINUX_LDAV_FILE [__linux__, __CYGWIN__]: File containing - load averages. + LINUX_LDAV_FILE [__linux__, __ANDROID__, __CYGWIN__]: File + containing load averages. Specific system predefines this file uses, aside from setting default values if not emacs: @@ -65,7 +65,7 @@ UMAX4_3 VMS _WIN32 Native Windows (possibly also defined on Cygwin) - __linux__ Linux: assumes /proc file system mounted. + __linux__, __ANDROID__ Linux: assumes /proc file system mounted. Support from Michael K. Johnson. __CYGWIN__ Cygwin emulates linux /proc/loadavg. __NetBSD__ NetBSD: assumes /kern file system mounted. @@ -263,7 +263,7 @@ # ifdef LOAD_AVE_TYPE # ifndef __VMS -# ifndef __linux__ +# if !(defined __linux__ || defined __ANDROID__) # ifndef NLIST_STRUCT # include <a.out.h> # else /* NLIST_STRUCT */ @@ -286,7 +286,7 @@ # ifndef LDAV_SYMBOL # define LDAV_SYMBOL "_avenrun" # endif /* LDAV_SYMBOL */ -# endif /* __linux__ */ +# endif /* __linux__ || __ANDROID__ */ # else /* __VMS */ @@ -359,7 +359,8 @@ # include <sys/dg_sys_info.h> # endif -# if (defined __linux__ || defined __CYGWIN__ || defined SUNOS_5 \ +# if (defined __linux__ || defined __ANDROID__ \ + || defined __CYGWIN__ || defined SUNOS_5 \ || (defined LOAD_AVE_TYPE && ! defined __VMS)) # include <fcntl.h> # endif @@ -388,7 +389,7 @@ static bool getloadavg_initialized; /* Offset in kmem to seek to read load average, or 0 means invalid. */ static long offset; -# if ! defined __VMS && ! defined sgi && ! defined __linux__ +# if ! defined __VMS && ! defined sgi && ! (defined __linux__ || defined __ANDROID__) static struct nlist name_list[2]; # endif @@ -498,8 +499,8 @@ getloadavg (double loadavg[], int nelem) } # endif -# if !defined (LDAV_DONE) && (defined (__linux__) || defined (__CYGWIN__)) - /* Linux without glibc, Cygwin */ +# if !defined (LDAV_DONE) && (defined __linux__ || defined __ANDROID__ || defined __CYGWIN__) + /* Linux without glibc, Android, Cygwin */ # define LDAV_DONE # undef LOAD_AVE_TYPE @@ -554,7 +555,7 @@ getloadavg (double loadavg[], int nelem) return elem; -# endif /* __linux__ || __CYGWIN__ */ +# endif /* __linux__ || __ANDROID__ || __CYGWIN__ */ # if !defined (LDAV_DONE) && defined (__NetBSD__) /* NetBSD < 0.9 */ # define LDAV_DONE -- 2.7.4
>From fa3e028aab95578dacf9bf42733c123865b82654 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Sun, 27 Jan 2019 11:37:46 +0100 Subject: [PATCH 3/4] relocatable-prog: Use Linux code on Android. * lib/progreloc.c: Treat Android like Linux. --- ChangeLog | 5 +++++ lib/progreloc.c | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 80aeb34..82fc48f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2019-01-27 Bruno Haible <br...@clisp.org> + + relocatable-prog: Use Linux code on Android. + * lib/progreloc.c: Treat Android like Linux. + 2019-01-26 Bruno Haible <br...@clisp.org> getloadavg: Add support for Android. diff --git a/lib/progreloc.c b/lib/progreloc.c index 5cec310..1c4db0c 100644 --- a/lib/progreloc.c +++ b/lib/progreloc.c @@ -102,7 +102,7 @@ extern char * canonicalize_file_name (const char *name); #if ENABLE_RELOCATABLE -#if defined __linux__ || defined __CYGWIN__ +#if defined __linux__ || defined __ANDROID__ || defined __CYGWIN__ /* File descriptor of the executable. (Only used to verify that we find the correct executable.) */ static int executable_fd = -1; @@ -118,7 +118,7 @@ maybe_executable (const char *filename) return false; #endif -#if defined __linux__ || defined __CYGWIN__ +#if defined __linux__ || defined __ANDROID__ || defined __CYGWIN__ if (executable_fd >= 0) { /* If we already have an executable_fd, check that filename points to @@ -180,7 +180,7 @@ find_executable (const char *argv0) return xstrdup (location); #else /* Unix */ -# ifdef __linux__ +# if defined __linux__ || defined __ANDROID__ /* The executable is accessible as /proc/<pid>/exe. In newer Linux versions, also as /proc/self/exe. Linux >= 2.1 provides a symlink to the true pathname; older Linux versions give only device and ino, -- 2.7.4
>From 675d6027ed01a4dc971d8fe8cdd8fee9eae209b7 Mon Sep 17 00:00:00 2001 From: Bruno Haible <br...@clisp.org> Date: Sun, 27 Jan 2019 11:39:56 +0100 Subject: [PATCH 4/4] tests: Enable Linux specific tests on Android. * tests/test-flock.c (main): Treat Android like Linux. * tests/test-openat-safer.c (main): Likewise. --- ChangeLog | 6 ++++++ tests/test-flock.c | 2 +- tests/test-openat-safer.c | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 82fc48f..5c77d69 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2019-01-27 Bruno Haible <br...@clisp.org> + tests: Enable Linux specific tests on Android. + * tests/test-flock.c (main): Treat Android like Linux. + * tests/test-openat-safer.c (main): Likewise. + +2019-01-27 Bruno Haible <br...@clisp.org> + relocatable-prog: Use Linux code on Android. * lib/progreloc.c: Treat Android like Linux. diff --git a/tests/test-flock.c b/tests/test-flock.c index ff688bc..aa428ff 100644 --- a/tests/test-flock.c +++ b/tests/test-flock.c @@ -98,7 +98,7 @@ main (int argc, char *argv[]) ASSERT (fd >= 0); ASSERT (write (fd, "hello", 5) == 5); -#if defined __linux__ +#if defined __linux__ || defined __ANDROID__ /* Invalid operation codes are rejected by the Linux implementation and by the gnulib replacement, but not by the Mac OS X implementation. */ ASSERT (flock (fd, LOCK_SH | LOCK_EX) == -1); diff --git a/tests/test-openat-safer.c b/tests/test-openat-safer.c index 042e488..7971168 100644 --- a/tests/test-openat-safer.c +++ b/tests/test-openat-safer.c @@ -96,7 +96,7 @@ main (void) errno = 0; ASSERT (openat (dfd, witness "/", O_RDONLY) == -1); ASSERT (errno == ENOTDIR || errno == EISDIR || errno == EINVAL); -#ifdef __linux__ +#if defined __linux__ || defined __ANDROID__ /* Using a bad directory is okay for absolute paths. */ fd = openat (-1, "/dev/null", O_WRONLY); ASSERT (STDERR_FILENO < fd); -- 2.7.4