aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPaul Eggert2023-08-12 12:50:15 -0700
committerPaul Eggert2023-08-12 12:57:35 -0700
commit5315e6e8d7e7233d54cce2b4c1bc8cf3b7acf4dc (patch)
tree5dc35aa709e829e1a67dcb868e643eee85c3449a /lib
parentf3868cb9d1806b35186eabc0262393316ebe689a (diff)
downloademacs-5315e6e8d7e7233d54cce2b4c1bc8cf3b7acf4dc.tar.gz
emacs-5315e6e8d7e7233d54cce2b4c1bc8cf3b7acf4dc.zip
Avoid stpncpy
It’s not worth the porting hassle, and as the glibc manual says, “this function is generally a poor choice for processing strings”. * admin/merge-gnulib (GNULIB_MODULES): Remove stpncpy. * exec/configure.ac: Do not check for stpncpy. * exec/exec.c (rpl_stpncpy, stpncpy): Remove this replacement. (exec_0): Properly clear buffer1. Use memcpy instead of stpncpy to add the trailing name. This code is clearly still suboptimal but efficiency is not that important here and I tried to minimize the change. * lib/gnulib.mk.in, m4/gnulib-comp.m4: Regenerate.
Diffstat (limited to 'lib')
-rw-r--r--lib/gnulib.mk.in12
-rw-r--r--lib/stpncpy.c92
2 files changed, 0 insertions, 104 deletions
diff --git a/lib/gnulib.mk.in b/lib/gnulib.mk.in
index 78ecb544c6e..785bdc70c5c 100644
--- a/lib/gnulib.mk.in
+++ b/lib/gnulib.mk.in
@@ -157,7 +157,6 @@
157# stddef \ 157# stddef \
158# stdio \ 158# stdio \
159# stpcpy \ 159# stpcpy \
160# stpncpy \
161# strnlen \ 160# strnlen \
162# strtoimax \ 161# strtoimax \
163# symlink \ 162# symlink \
@@ -336,7 +335,6 @@ GL_COND_OBJ_SIGDESCR_NP_CONDITION = @GL_COND_OBJ_SIGDESCR_NP_CONDITION@
336GL_COND_OBJ_STDIO_READ_CONDITION = @GL_COND_OBJ_STDIO_READ_CONDITION@ 335GL_COND_OBJ_STDIO_READ_CONDITION = @GL_COND_OBJ_STDIO_READ_CONDITION@
337GL_COND_OBJ_STDIO_WRITE_CONDITION = @GL_COND_OBJ_STDIO_WRITE_CONDITION@ 336GL_COND_OBJ_STDIO_WRITE_CONDITION = @GL_COND_OBJ_STDIO_WRITE_CONDITION@
338GL_COND_OBJ_STPCPY_CONDITION = @GL_COND_OBJ_STPCPY_CONDITION@ 337GL_COND_OBJ_STPCPY_CONDITION = @GL_COND_OBJ_STPCPY_CONDITION@
339GL_COND_OBJ_STPNCPY_CONDITION = @GL_COND_OBJ_STPNCPY_CONDITION@
340GL_COND_OBJ_STRNLEN_CONDITION = @GL_COND_OBJ_STRNLEN_CONDITION@ 338GL_COND_OBJ_STRNLEN_CONDITION = @GL_COND_OBJ_STRNLEN_CONDITION@
341GL_COND_OBJ_STRTOIMAX_CONDITION = @GL_COND_OBJ_STRTOIMAX_CONDITION@ 339GL_COND_OBJ_STRTOIMAX_CONDITION = @GL_COND_OBJ_STRTOIMAX_CONDITION@
342GL_COND_OBJ_STRTOLL_CONDITION = @GL_COND_OBJ_STRTOLL_CONDITION@ 340GL_COND_OBJ_STRTOLL_CONDITION = @GL_COND_OBJ_STRTOLL_CONDITION@
@@ -3454,16 +3452,6 @@ endif
3454endif 3452endif
3455## end gnulib module stpcpy 3453## end gnulib module stpcpy
3456 3454
3457## begin gnulib module stpncpy
3458ifeq (,$(OMIT_GNULIB_MODULE_stpncpy))
3459
3460ifneq (,$(GL_COND_OBJ_STPNCPY_CONDITION))
3461libgnu_a_SOURCES += stpncpy.c
3462endif
3463
3464endif
3465## end gnulib module stpncpy
3466
3467## begin gnulib module string 3455## begin gnulib module string
3468ifeq (,$(OMIT_GNULIB_MODULE_string)) 3456ifeq (,$(OMIT_GNULIB_MODULE_string))
3469 3457
diff --git a/lib/stpncpy.c b/lib/stpncpy.c
deleted file mode 100644
index d1422a927df..00000000000
--- a/lib/stpncpy.c
+++ /dev/null
@@ -1,92 +0,0 @@
1/* Copyright (C) 1993, 1995-1997, 2002-2003, 2005-2007, 2009-2023 Free Software
2 * Foundation, Inc.
3
4 NOTE: The canonical source of this file is maintained with the GNU C Library.
5 Bugs can be reported to bug-glibc@gnu.org.
6
7 This file is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as
9 published by the Free Software Foundation; either version 2.1 of the
10 License, or (at your option) any later version.
11
12 This file is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with this program. If not, see <https://www.gnu.org/licenses/>. */
19
20/* This is almost copied from strncpy.c, written by Torbjorn Granlund. */
21
22#include <config.h>
23
24/* Specification. */
25#include <string.h>
26
27#ifndef weak_alias
28# define __stpncpy stpncpy
29#endif
30
31/* Copy no more than N bytes of SRC to DST, returning a pointer past the
32 last non-NUL byte written into DST. */
33char *
34(__stpncpy) (char *dest, const char *src, size_t n)
35{
36 char c;
37 char *s = dest;
38
39 if (n >= 4)
40 {
41 size_t n4 = n >> 2;
42
43 for (;;)
44 {
45 c = *src++;
46 *dest++ = c;
47 if (c == '\0')
48 break;
49 c = *src++;
50 *dest++ = c;
51 if (c == '\0')
52 break;
53 c = *src++;
54 *dest++ = c;
55 if (c == '\0')
56 break;
57 c = *src++;
58 *dest++ = c;
59 if (c == '\0')
60 break;
61 if (--n4 == 0)
62 goto last_chars;
63 }
64 n -= dest - s;
65 goto zero_fill;
66 }
67
68 last_chars:
69 n &= 3;
70 if (n == 0)
71 return dest;
72
73 for (;;)
74 {
75 c = *src++;
76 --n;
77 *dest++ = c;
78 if (c == '\0')
79 break;
80 if (n == 0)
81 return dest;
82 }
83
84 zero_fill:
85 while (n-- > 0)
86 dest[n] = '\0';
87
88 return dest - 1;
89}
90#ifdef weak_alias
91weak_alias (__stpncpy, stpncpy)
92#endif