new GLOBSORT variable

This commit is contained in:
Chet Ramey
2023-04-16 16:13:14 -04:00
parent 15b199c0dd
commit d06fefb2ba
36 changed files with 1811 additions and 943 deletions
+28 -2
View File
@@ -94,7 +94,8 @@ CSOURCES = clktck.c clock.c getcwd.c getenv.c oslib.c setlinebuf.c \
wcsdup.c fpurge.c zgetline.c mbscmp.c mbsncmp.c uconvert.c \
ufuncs.c casemod.c dprintf.c input_avail.c mbscasecmp.c fnxform.c \
strchrnul.c unicode.c wcswidth.c wcsnwidth.c shmbchar.c strdup.c \
strvis.c utf8.c random.c gettimeofday.c timers.c
strvis.c strlcpy.c strscpy.c utf8.c random.c gettimeofday.c \
timers.c anonfile.c
# The header files for this library.
HSOURCES =
@@ -109,6 +110,7 @@ OBJECTS = clktck.o clock.o getenv.o oslib.o setlinebuf.o strnlen.o \
fmtullong.o fmtumax.o zcatfd.o zmapfd.o winsize.o wcsdup.o \
fpurge.o zgetline.o mbscmp.o mbsncmp.o uconvert.o ufuncs.o casemod.o \
input_avail.o mbscasecmp.o fnxform.o unicode.o shmbchar.o strvis.o \
strscpy.o anonfile.o \
utf8.o random.o gettimeofday.o timers.o wcsnwidth.o ${LIBOBJS}
SUPPORT = Makefile
@@ -144,6 +146,7 @@ ${BUILD_DIR}/pathnames.h: ${BUILD_DIR}/config.h ${BUILD_DIR}/Makefile Makefile
-( cd ${BUILD_DIR} && ${MAKE} ${MFLAGS} pathnames.h )
# rules for losing makes, like SunOS
anonfile.o: anonfile.c
casemod.o: casemod.c
clktck.o: clktck.c
clock.o: clock.c
@@ -200,6 +203,8 @@ strtoull.o: strtoull.c
strtoumax.o: strtoumax.c
strtrans.o: strtrans.c
strvis.o: strvis.c
strlcpy.o: strlcpy.c
strscpy.o: strscpy.c
timers.o: timers.c
times.o: times.c
timeval.o: timeval.c
@@ -227,6 +232,7 @@ strtoul.o: strtol.c
strtoull.o: strtol.c
# all files in the library depend on config.h
anonfile.o: ${BUILD_DIR}/config.h
casemod.o: ${BUILD_DIR}/config.h
clktck.o: ${BUILD_DIR}/config.h
clock.o: ${BUILD_DIR}/config.h
@@ -283,6 +289,8 @@ strtoull.o: ${BUILD_DIR}/config.h
strtoumax.o: ${BUILD_DIR}/config.h
strtrans.o: ${BUILD_DIR}/config.h
strvis.o: ${BUILD_DIR}/config.h
strlcpy.o: ${BUILD_DIR}/config.h
strscpy.o: ${BUILD_DIR}/config.h
timers.o: ${BUILD_DIR}/config.h
times.o: ${BUILD_DIR}/config.h
timeval.o: ${BUILD_DIR}/config.h
@@ -521,6 +529,14 @@ strvis.o: ${BASHINCDIR}/ansi_stdlib.h ${BASHINCDIR}/chartypes.h
strvis.o: ${BASHINCDIR}/shmbutil.h ${BASHINCDIR}/shmbchar.h
strvis.o: ${topdir}/bashintl.h ${LIBINTL_H} $(BASHINCDIR)/gettext.h
strlcpy.o: ${topdir}/bashansi.h
strlcpy.o: ${BASHINCDIR}/ansi_stdlib.h ${BASHINCDIR}/chartypes.h
strlcpy.o: ${BASHINCDIR}/typemax.h
strscpy.o: ${topdir}/bashansi.h
strscpy.o: ${BASHINCDIR}/ansi_stdlib.h ${BASHINCDIR}/chartypes.h
strscpy.o: ${BASHINCDIR}/typemax.h
times.o: ${BASHINCDIR}/systimes.h
times.o: ${BASHINCDIR}/posixtime.h
@@ -539,7 +555,6 @@ tmpfile.o: ${topdir}/unwind_prot.h ${topdir}/dispose_cmd.h
tmpfile.o: ${topdir}/make_cmd.h ${topdir}/subst.h ${topdir}/sig.h
tmpfile.o: ${BUILD_DIR}/pathnames.h ${topdir}/externs.h
uconvert.o: ${topdir}/bashtypes.h
uconvert.o: ${BASHINCDIR}/chartypes.h
uconvert.o: ${topdir}/shell.h ${topdir}/syntax.h ${topdir}/bashjmp.h ${BASHINCDIR}/posixjmp.h
uconvert.o: ${topdir}/command.h ${BASHINCDIR}/stdc.h ${topdir}/error.h
@@ -662,3 +677,14 @@ zmapfd.o: ${BASHINCDIR}/stdc.h
zmapfd.o: ${topdir}/command.h
zmapfd.o: ${topdir}/general.h
zmapfd.o: ${topdir}/bashtypes.h ${BASHINCDIR}/chartypes.h ${topdir}/xmalloc.h
anonfile.o: ${topdir}/bashansi.h ${BASHINCDIR}/ansi_stdlib.h
anonfile.o: ${topdir}/bashtypes.h
anonfile.o: ${BASHINCDIR}/filecntl.h
anonfile.o: ${topdir}/shell.h ${topdir}/syntax.h ${topdir}/bashjmp.h ${BASHINCDIR}/posixjmp.h
anonfile.o: ${topdir}/command.h ${BASHINCDIR}/stdc.h ${topdir}/error.h
anonfile.o: ${topdir}/general.h ${topdir}/bashtypes.h ${topdir}/variables.h ${topdir}/conftypes.h
anonfile.o: ${topdir}/array.h ${topdir}/hashlib.h ${topdir}/quit.h
anonfile.o: ${topdir}/unwind_prot.h ${topdir}/dispose_cmd.h
anonfile.o: ${topdir}/make_cmd.h ${topdir}/subst.h ${topdir}/sig.h
anonfile.o: ${BUILD_DIR}/pathnames.h ${topdir}/externs.h
+67
View File
@@ -0,0 +1,67 @@
/* anonfile.c - open and close temporary files (anonymous and memory-backed if possible). */
/* Copyright (C) 2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
Bash is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Bash 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with Bash. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#if defined (HAVE_UNISTD_H)
# include <unistd.h>
#endif
#include <bashtypes.h>
#if defined (HAVE_MEMFD_CREATE) || defined (HAVE_SHM_OPEN) || defined (HAVE_SHM_MKSTEMP)
# include <sys/mman.h>
#endif
#include <filecntl.h>
#include <errno.h>
#include <shell.h>
#include <bashansi.h>
/* Placeholder for future use of memfd_create/shm_open/shm_mkstemp */
static int
anonunlink (const char *fn)
{
int r;
r = unlink (fn);
return r;
}
int
anonopen (const char *name, int flags)
{
int fd, flag;
/* Heuristic */
flag = (name && *name == '/') ? MT_TEMPLATE : MT_USETMPDIR;
fd = sh_mktmpfd (name, flag|MT_USERANDOM|MT_READWRITE|MT_UNLINK, (char **)NULL);
return fd;
}
int
anonclose (int fd, const char *name)
{
int r;
r = close (fd);
return r;
}
+39
View File
@@ -0,0 +1,39 @@
/* strlcpy - null-terminated string copy with length checking. */
/* Copyright (C) 2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
Bash is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Bash 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with Bash. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <bashansi.h>
size_t
strlcpy(const char *dest, const const char *src, size_t size)
{
size_t ret;
ret = strlen(src);
if (size)
{
size_t len;
len = (ret >= size) ? size - 1 : ret;
memcpy (dest, src, len);
dest[len] = '\0';
}
return ret;
}
+38
View File
@@ -0,0 +1,38 @@
/* strscpy - null-terminated string copy with length checking. */
/* Copyright (C) 2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
Bash is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Bash 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with Bash. If not, see <http://www.gnu.org/licenses/>.
*/
#include <config.h>
#include <bashansi.h>
ssize_t
strscpy (char *d, const char *s, size_t len)
{
size_t i;
for (i = 0; i < len; i++)
if ((d[i] = s[i]) == 0)
return ((ssize_t)i);
if (i != 0)
d[--i] = '\0';
return (-1); /* strlen (s) > len */
}
+34 -4
View File
@@ -58,6 +58,8 @@ extern int errno;
extern pid_t dollar_dollar_pid;
static int tmpunlink (const char *);
static char *get_sys_tmpdir (void);
static char *get_tmpdir (int);
@@ -134,6 +136,15 @@ sh_seedrand (void)
#endif
}
static int
tmpunlink (const char *fn)
{
int r;
r = unlink (fn);
return r;
}
char *
sh_mktmpname (const char *nameroot, int flags)
{
@@ -181,7 +192,7 @@ sh_mktmpname (const char *nameroot, int flags)
(unsigned long) dollar_dollar_pid ^
x;
sprintf (filename, "%s/%s-%lu", tdir, lroot, filenum);
if (tmpnamelen > 0 && tmpnamelen < 32)
if (tmpnamelen > 0 && tmpnamelen < 32) /* XXX */
filename[tdlen + 1 + tmpnamelen] = '\0';
# ifdef HAVE_LSTAT
r = lstat (filename, &sb);
@@ -220,6 +231,13 @@ sh_mktmpfd (const char *nameroot, int flags, char **namep)
else
sprintf (filename, "%s/%s.XXXXXX", tdir, lroot);
fd = mkstemp (filename);
if ((flags & MT_UNLINK) && tmpunlink (filename) < 0)
{
int e = errno;
close (fd);
fd = -1;
errno = e;
}
if (fd < 0 || namep == 0)
{
free (filename);
@@ -227,6 +245,7 @@ sh_mktmpfd (const char *nameroot, int flags, char **namep)
}
if (namep)
*namep = filename;
return fd;
#else /* !USE_MKSTEMP */
#ifndef USE_URANDOM32
@@ -245,16 +264,27 @@ sh_mktmpfd (const char *nameroot, int flags, char **namep)
(unsigned long) dollar_dollar_pid ^
x;
sprintf (filename, "%s/%s-%lu", tdir, lroot, filenum);
if (tmpnamelen > 0 && tmpnamelen < 32)
if (tmpnamelen > 0 && tmpnamelen < 32) /* XXX */
filename[tdlen + 1 + tmpnamelen] = '\0';
fd = open (filename, BASEOPENFLAGS | ((flags & MT_READWRITE) ? O_RDWR : O_WRONLY), 0600);
}
while (fd < 0 && errno == EEXIST);
if ((flags & MT_UNLINK) && (tmpunlink (filename) < 0)
{
int e = errno;
close (fd);
fd = -1;
errno = e;
}
if (fd < 0 || namep == 0)
{
free (filename);
filename = NULL;
}
if (namep)
*namep = filename;
else
free (filename);
return fd;
#endif /* !USE_MKSTEMP */