diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2023-08-12 12:50:15 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2023-08-12 12:57:35 -0700 |
commit | 5315e6e8d7e7233d54cce2b4c1bc8cf3b7acf4dc (patch) | |
tree | 5dc35aa709e829e1a67dcb868e643eee85c3449a /lib | |
parent | f3868cb9d1806b35186eabc0262393316ebe689a (diff) | |
download | emacs-5315e6e8d7e7233d54cce2b4c1bc8cf3b7acf4dc.tar.gz |
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.in | 12 | ||||
-rw-r--r-- | lib/stpncpy.c | 92 |
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 @@ # stddef \ # stdio \ # stpcpy \ -# stpncpy \ # strnlen \ # strtoimax \ # symlink \ @@ -336,7 +335,6 @@ GL_COND_OBJ_SIGDESCR_NP_CONDITION = @GL_COND_OBJ_SIGDESCR_NP_CONDITION@ GL_COND_OBJ_STDIO_READ_CONDITION = @GL_COND_OBJ_STDIO_READ_CONDITION@ GL_COND_OBJ_STDIO_WRITE_CONDITION = @GL_COND_OBJ_STDIO_WRITE_CONDITION@ GL_COND_OBJ_STPCPY_CONDITION = @GL_COND_OBJ_STPCPY_CONDITION@ -GL_COND_OBJ_STPNCPY_CONDITION = @GL_COND_OBJ_STPNCPY_CONDITION@ GL_COND_OBJ_STRNLEN_CONDITION = @GL_COND_OBJ_STRNLEN_CONDITION@ GL_COND_OBJ_STRTOIMAX_CONDITION = @GL_COND_OBJ_STRTOIMAX_CONDITION@ GL_COND_OBJ_STRTOLL_CONDITION = @GL_COND_OBJ_STRTOLL_CONDITION@ @@ -3454,16 +3452,6 @@ endif endif ## end gnulib module stpcpy -## begin gnulib module stpncpy -ifeq (,$(OMIT_GNULIB_MODULE_stpncpy)) - -ifneq (,$(GL_COND_OBJ_STPNCPY_CONDITION)) -libgnu_a_SOURCES += stpncpy.c -endif - -endif -## end gnulib module stpncpy - ## begin gnulib module string ifeq (,$(OMIT_GNULIB_MODULE_string)) 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 @@ -/* Copyright (C) 1993, 1995-1997, 2002-2003, 2005-2007, 2009-2023 Free Software - * Foundation, Inc. - - NOTE: The canonical source of this file is maintained with the GNU C Library. - Bugs can be reported to bug-glibc@gnu.org. - - This file is free software: you can redistribute it and/or modify - it under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 2.1 of the - License, or (at your option) any later version. - - This file is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see <https://www.gnu.org/licenses/>. */ - -/* This is almost copied from strncpy.c, written by Torbjorn Granlund. */ - -#include <config.h> - -/* Specification. */ -#include <string.h> - -#ifndef weak_alias -# define __stpncpy stpncpy -#endif - -/* Copy no more than N bytes of SRC to DST, returning a pointer past the - last non-NUL byte written into DST. */ -char * -(__stpncpy) (char *dest, const char *src, size_t n) -{ - char c; - char *s = dest; - - if (n >= 4) - { - size_t 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; -} -#ifdef weak_alias -weak_alias (__stpncpy, stpncpy) -#endif |