aboutsummaryrefslogtreecommitdiffstats
path: root/exec/exec.c
diff options
context:
space:
mode:
authorPo Lu2023-05-01 21:42:42 +0800
committerPo Lu2023-05-01 21:42:42 +0800
commitf92bdbc67754c77afcae95cb1ab237e2c5053ab2 (patch)
treef3898c28ff76b3f1be56978e30d866318a615039 /exec/exec.c
parent8a909927995738cf1103198f8086a42bf28a1d50 (diff)
downloademacs-f92bdbc67754c77afcae95cb1ab237e2c5053ab2.tar.gz
emacs-f92bdbc67754c77afcae95cb1ab237e2c5053ab2.zip
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.
Diffstat (limited to 'exec/exec.c')
-rw-r--r--exec/exec.c103
1 files changed, 99 insertions, 4 deletions
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 <https://www.gnu.org/licenses/>. */
21 21
22#include <errno.h> 22#include <errno.h>
23#include <unistd.h> 23#include <unistd.h>
24#include <string.h>
25#include <fcntl.h> 24#include <fcntl.h>
26#include <assert.h> 25#include <assert.h>
27#include <string.h> 26#include <string.h>
@@ -48,6 +47,103 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
48 47
49 48
50 49
50
51/* Define replacements for required string functions. */
52
53#ifndef HAVE_STPCPY
54
55/* Copy SRC to DEST, returning the address of the terminating '\0' in
56 DEST. */
57
58static char *
59rpl_stpcpy (char *dest, const char *src)
60{
61 register char *d;
62 register const char *s;
63
64 d = dest;
65 s = src;
66
67 do
68 *d++ = *s;
69 while (*s++ != '\0');
70
71 return d - 1;
72}
73
74#define stpcpy rpl_stpcpy
75#endif /* !HAVE_STPCPY */
76
77#ifndef HAVE_STPNCPY
78
79/* Copy no more than N bytes of SRC to DST, returning a pointer past
80 the last non-NUL byte written into DST. */
81
82char *
83rpl_stpncpy (char *dest, const char *src, size_t n)
84{
85 char c, *s;
86 size_t n4;
87
88 s = dest;
89
90 if (n >= 4)
91 {
92 n4 = n >> 2;
93
94 for (;;)
95 {
96 c = *src++;
97 *dest++ = c;
98 if (c == '\0')
99 break;
100 c = *src++;
101 *dest++ = c;
102 if (c == '\0')
103 break;
104 c = *src++;
105 *dest++ = c;
106 if (c == '\0')
107 break;
108 c = *src++;
109 *dest++ = c;
110 if (c == '\0')
111 break;
112 if (--n4 == 0)
113 goto last_chars;
114 }
115 n -= dest - s;
116 goto zero_fill;
117 }
118
119 last_chars:
120 n &= 3;
121 if (n == 0)
122 return dest;
123
124 for (;;)
125 {
126 c = *src++;
127 --n;
128 *dest++ = c;
129 if (c == '\0')
130 break;
131 if (n == 0)
132 return dest;
133 }
134
135 zero_fill:
136 while (n-- > 0)
137 dest[n] = '\0';
138
139 return dest - 1;
140}
141
142#define stpncpy rpl_stpncpy
143#endif /* !HAVE_STPNCPY */
144
145
146
51/* Executable reading functions. 147/* Executable reading functions.
52 These functions extract information from an executable that is 148 These functions extract information from an executable that is
53 about to be loaded. 149 about to be loaded.
@@ -624,9 +720,8 @@ process_program_header (const char *name, int fd,
624 break; 720 break;
625 721
626 case 3: /* PT_INTERP */ 722 case 3: /* PT_INTERP */
627 /* This describes another executable that must be loaded. 723 /* This describes another executable that must be loaded. Open
628 Open the interpreter and process each of its headers 724 the interpreter and process each of its headers as well. */
629 as well. */
630 rc = process_interpreter (fd, header, entry); 725 rc = process_interpreter (fd, header, entry);
631 break; 726 break;
632 727