From f92bdbc67754c77afcae95cb1ab237e2c5053ab2 Mon Sep 17 00:00:00 2001 From: Po Lu Date: Mon, 1 May 2023 21:42:42 +0800 Subject: [PATCH] Update Android port * exec/config.h.in: Update config.h.in. * exec/configure.ac: Check for stpcpy and stpncpy. * exec/exec.c (rpl_stpcpy, rpl_stpncpy): Define replacements when they are not present on the system. (process_program_header): Fill comment. --- exec/config.h.in | 9 ++++ exec/configure.ac | 2 +- exec/exec.c | 103 ++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 109 insertions(+), 5 deletions(-) diff --git a/exec/config.h.in b/exec/config.h.in index d602d89a38e..c276ff3f1f7 100644 --- a/exec/config.h.in +++ b/exec/config.h.in @@ -38,6 +38,9 @@ along with GNU Emacs. If not, see . */ /* Define to number of the `exec' system call. */ #undef EXEC_SYSCALL +/* Define to 1 if you have the `getpagesize' function. */ +#undef HAVE_GETPAGESIZE + /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H @@ -53,6 +56,12 @@ along with GNU Emacs. If not, see . */ /* Define to 1 if you have the header file. */ #undef HAVE_STDLIB_H +/* Define to 1 if you have the `stpcpy' function. */ +#undef HAVE_STPCPY + +/* Define to 1 if you have the `stpncpy' function. */ +#undef HAVE_STPNCPY + /* Define to 1 if you have the header file. */ #undef HAVE_STRINGS_H diff --git a/exec/configure.ac b/exec/configure.ac index 9763edc99f3..9b4bcebe34e 100644 --- a/exec/configure.ac +++ b/exec/configure.ac @@ -54,7 +54,7 @@ AC_TYPE_UINTPTR_T AC_TYPE_PID_T AC_HEADER_STDBOOL -AC_CHECK_FUNC([getpagesize]) +AC_CHECK_FUNCS([getpagesize stpcpy stpncpy]) AH_BOTTOM([ #ifdef HAVE_STDBOOL_H diff --git a/exec/exec.c b/exec/exec.c index c7a73f221f5..df8c9430236 100644 --- a/exec/exec.c +++ b/exec/exec.c @@ -21,7 +21,6 @@ along with GNU Emacs. If not, see . */ #include #include -#include #include #include #include @@ -48,6 +47,103 @@ along with GNU Emacs. If not, see . */ + +/* Define replacements for required string functions. */ + +#ifndef HAVE_STPCPY + +/* Copy SRC to DEST, returning the address of the terminating '\0' in + DEST. */ + +static char * +rpl_stpcpy (char *dest, const char *src) +{ + register char *d; + register const char *s; + + d = dest; + s = src; + + do + *d++ = *s; + while (*s++ != '\0'); + + return d - 1; +} + +#define stpcpy rpl_stpcpy +#endif /* !HAVE_STPCPY */ + +#ifndef HAVE_STPNCPY + +/* Copy no more than N bytes of SRC to DST, returning a pointer past + the last non-NUL byte written into DST. */ + +char * +rpl_stpncpy (char *dest, const char *src, size_t n) +{ + char c, *s; + size_t n4; + + s = dest; + + if (n >= 4) + { + n4 = n >> 2; + + for (;;) + { + c = *src++; + *dest++ = c; + if (c == '\0') + break; + c = *src++; + *dest++ = c; + if (c == '\0') + break; + c = *src++; + *dest++ = c; + if (c == '\0') + break; + c = *src++; + *dest++ = c; + if (c == '\0') + break; + if (--n4 == 0) + goto last_chars; + } + n -= dest - s; + goto zero_fill; + } + + last_chars: + n &= 3; + if (n == 0) + return dest; + + for (;;) + { + c = *src++; + --n; + *dest++ = c; + if (c == '\0') + break; + if (n == 0) + return dest; + } + + zero_fill: + while (n-- > 0) + dest[n] = '\0'; + + return dest - 1; +} + +#define stpncpy rpl_stpncpy +#endif /* !HAVE_STPNCPY */ + + + /* Executable reading functions. These functions extract information from an executable that is about to be loaded. @@ -624,9 +720,8 @@ process_program_header (const char *name, int fd, break; case 3: /* PT_INTERP */ - /* This describes another executable that must be loaded. - Open the interpreter and process each of its headers - as well. */ + /* This describes another executable that must be loaded. Open + the interpreter and process each of its headers as well. */ rc = process_interpreter (fd, header, entry); break; -- 2.39.2