mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-07-04 19:00:50 +02:00
new GLOBSORT variable
This commit is contained in:
@@ -102,7 +102,7 @@ cc_t old_vtime;
|
||||
struct termios term;
|
||||
|
||||
int
|
||||
main()
|
||||
main(int c, char **v)
|
||||
{
|
||||
fd_set fds;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* fileman.c - file manager example for readline library. */
|
||||
|
||||
/* Copyright (C) 1987-2009 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1987-2009,2023 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of the GNU Readline Library (Readline), a library for
|
||||
reading lines of text with interactive input and history editing.
|
||||
@@ -61,24 +61,24 @@
|
||||
# include <readline/history.h>
|
||||
#endif
|
||||
|
||||
extern char *xmalloc PARAMS((size_t));
|
||||
extern char *xmalloc (size_t);
|
||||
|
||||
void initialize_readline PARAMS((void));
|
||||
void too_dangerous PARAMS((char *));
|
||||
void initialize_readline (void);
|
||||
void too_dangerous (char *);
|
||||
|
||||
int execute_line PARAMS((char *));
|
||||
int valid_argument PARAMS((char *, char *));
|
||||
int execute_line (char *);
|
||||
int valid_argument (char *, char *);
|
||||
|
||||
/* The names of functions that actually do the manipulation. */
|
||||
int com_list PARAMS((char *));
|
||||
int com_view PARAMS((char *));
|
||||
int com_rename PARAMS((char *));
|
||||
int com_stat PARAMS((char *));
|
||||
int com_pwd PARAMS((char *));
|
||||
int com_delete PARAMS((char *));
|
||||
int com_help PARAMS((char *));
|
||||
int com_cd PARAMS((char *));
|
||||
int com_quit PARAMS((char *));
|
||||
int com_list (char *);
|
||||
int com_view (char *);
|
||||
int com_rename (char *);
|
||||
int com_stat (char *);
|
||||
int com_pwd (char *);
|
||||
int com_delete (char *);
|
||||
int com_help (char *);
|
||||
int com_cd (char *);
|
||||
int com_quit (char *);
|
||||
|
||||
/* A structure which contains information on the commands this program
|
||||
can understand. */
|
||||
@@ -105,8 +105,11 @@ COMMAND commands[] = {
|
||||
};
|
||||
|
||||
/* Forward declarations. */
|
||||
char *stripwhite ();
|
||||
COMMAND *find_command ();
|
||||
char *dupstr (char *);
|
||||
int execute_line (char *);
|
||||
char *stripwhite (char *);
|
||||
|
||||
COMMAND *find_command (char *);
|
||||
|
||||
/* The name of this program, as taken from argv[0]. */
|
||||
char *progname;
|
||||
@@ -115,8 +118,7 @@ char *progname;
|
||||
int done;
|
||||
|
||||
char *
|
||||
dupstr (s)
|
||||
char *s;
|
||||
dupstr (char *s)
|
||||
{
|
||||
char *r;
|
||||
|
||||
@@ -125,45 +127,9 @@ dupstr (s)
|
||||
return (r);
|
||||
}
|
||||
|
||||
int
|
||||
main (argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
{
|
||||
char *line, *s;
|
||||
|
||||
progname = argv[0];
|
||||
|
||||
initialize_readline (); /* Bind our completer. */
|
||||
|
||||
/* Loop reading and executing lines until the user quits. */
|
||||
for ( ; done == 0; )
|
||||
{
|
||||
line = readline ("FileMan: ");
|
||||
|
||||
if (!line)
|
||||
break;
|
||||
|
||||
/* Remove leading and trailing whitespace from the line.
|
||||
Then, if there is anything left, add it to the history list
|
||||
and execute it. */
|
||||
s = stripwhite (line);
|
||||
|
||||
if (*s)
|
||||
{
|
||||
add_history (s);
|
||||
execute_line (s);
|
||||
}
|
||||
|
||||
free (line);
|
||||
}
|
||||
exit (0);
|
||||
}
|
||||
|
||||
/* Execute a command line. */
|
||||
int
|
||||
execute_line (line)
|
||||
char *line;
|
||||
execute_line (char *line)
|
||||
{
|
||||
register int i;
|
||||
COMMAND *command;
|
||||
@@ -202,8 +168,7 @@ execute_line (line)
|
||||
/* Look up NAME as the name of a command, and return a pointer to that
|
||||
command. Return a NULL pointer if NAME isn't a command name. */
|
||||
COMMAND *
|
||||
find_command (name)
|
||||
char *name;
|
||||
find_command (char *name)
|
||||
{
|
||||
register int i;
|
||||
|
||||
@@ -217,8 +182,7 @@ find_command (name)
|
||||
/* Strip whitespace from the start and end of STRING. Return a pointer
|
||||
into STRING. */
|
||||
char *
|
||||
stripwhite (string)
|
||||
char *string;
|
||||
stripwhite (char *string)
|
||||
{
|
||||
register char *s, *t;
|
||||
|
||||
@@ -242,14 +206,14 @@ stripwhite (string)
|
||||
/* */
|
||||
/* **************************************************************** */
|
||||
|
||||
char *command_generator PARAMS((const char *, int));
|
||||
char **fileman_completion PARAMS((const char *, int, int));
|
||||
char *command_generator (const char *, int);
|
||||
char **fileman_completion (const char *, int, int);
|
||||
|
||||
/* Tell the GNU Readline library how to complete. We want to try to complete
|
||||
on command names if this is the first word in the line, or on filenames
|
||||
if not. */
|
||||
void
|
||||
initialize_readline ()
|
||||
initialize_readline (void)
|
||||
{
|
||||
/* Allow conditional parsing of the ~/.inputrc file. */
|
||||
rl_readline_name = "FileMan";
|
||||
@@ -264,9 +228,7 @@ initialize_readline ()
|
||||
in case we want to do some simple parsing. Return the array of matches,
|
||||
or NULL if there aren't any. */
|
||||
char **
|
||||
fileman_completion (text, start, end)
|
||||
const char *text;
|
||||
int start, end;
|
||||
fileman_completion (const char *text, int start, int end)
|
||||
{
|
||||
char **matches;
|
||||
|
||||
@@ -285,9 +247,7 @@ fileman_completion (text, start, end)
|
||||
to start from scratch; without any state (i.e. STATE == 0), then we
|
||||
start at the top of the list. */
|
||||
char *
|
||||
command_generator (text, state)
|
||||
const char *text;
|
||||
int state;
|
||||
command_generator (const char *text, int state)
|
||||
{
|
||||
static int list_index, len;
|
||||
char *name;
|
||||
@@ -504,3 +464,36 @@ valid_argument (caller, arg)
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
char *line, *s;
|
||||
|
||||
progname = argv[0];
|
||||
|
||||
initialize_readline (); /* Bind our completer. */
|
||||
|
||||
/* Loop reading and executing lines until the user quits. */
|
||||
for ( ; done == 0; )
|
||||
{
|
||||
line = readline ("FileMan: ");
|
||||
|
||||
if (!line)
|
||||
break;
|
||||
|
||||
/* Remove leading and trailing whitespace from the line.
|
||||
Then, if there is anything left, add it to the history list
|
||||
and execute it. */
|
||||
s = stripwhite (line);
|
||||
|
||||
if (*s)
|
||||
{
|
||||
add_history (s);
|
||||
execute_line (s);
|
||||
}
|
||||
|
||||
free (line);
|
||||
}
|
||||
exit (0);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* manexamp.c -- The examples which appear in the documentation are here. */
|
||||
|
||||
/* Copyright (C) 1987-2009 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1987-2009,2023 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of the GNU Readline Library (Readline), a library for
|
||||
reading lines of text with interactive input and history editing.
|
||||
@@ -18,9 +18,35 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Readline. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#if defined (HAVE_CONFIG_H)
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_UNISTD_H
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <readline/readline.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <locale.h>
|
||||
|
||||
#ifndef errno
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
#if defined (READLINE_LIBRARY)
|
||||
# include "readline.h"
|
||||
# include "history.h"
|
||||
#else
|
||||
# include <readline/readline.h>
|
||||
# include <readline/history.h>
|
||||
#endif
|
||||
|
||||
/* **************************************************************** */
|
||||
/* */
|
||||
@@ -33,7 +59,7 @@ static char *line_read = (char *)NULL;
|
||||
|
||||
/* Read a string, and return a pointer to it. Returns NULL on EOF. */
|
||||
char *
|
||||
rl_gets ()
|
||||
rl_gets (void)
|
||||
{
|
||||
/* If the buffer has already been allocated, return the memory
|
||||
to the free pool. */
|
||||
@@ -60,10 +86,11 @@ rl_gets ()
|
||||
/* **************************************************************** */
|
||||
|
||||
/* Invert the case of the COUNT following characters. */
|
||||
invert_case_line (count, key)
|
||||
int count, key;
|
||||
int
|
||||
invert_case_line (int count, int key)
|
||||
{
|
||||
register int start, end;
|
||||
int start, end;
|
||||
int direction;
|
||||
|
||||
start = rl_point;
|
||||
|
||||
@@ -92,7 +119,7 @@ invert_case_line (count, key)
|
||||
}
|
||||
|
||||
if (start == end)
|
||||
return;
|
||||
return 0;
|
||||
|
||||
/* Tell readline that we are modifying the line, so save the undo
|
||||
information. */
|
||||
@@ -108,4 +135,5 @@ invert_case_line (count, key)
|
||||
|
||||
/* Move point to on top of the last character changed. */
|
||||
rl_point = end - direction;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ cb_linehandler (char *line)
|
||||
}
|
||||
|
||||
static char *
|
||||
cb_readline ()
|
||||
cb_readline (void)
|
||||
{
|
||||
fd_set fds;
|
||||
int r, err;
|
||||
@@ -102,15 +102,13 @@ else if (RL_ISSTATE (RL_STATE_NSEARCH))
|
||||
}
|
||||
|
||||
void
|
||||
sigint_sighandler (s)
|
||||
int s;
|
||||
sigint_sighandler (int s)
|
||||
{
|
||||
saw_signal = s;
|
||||
}
|
||||
|
||||
int
|
||||
sigint_handler (s)
|
||||
int s;
|
||||
sigint_handler (int s)
|
||||
{
|
||||
rl_free_line_state ();
|
||||
rl_callback_sigcleanup ();
|
||||
|
||||
@@ -59,7 +59,7 @@ static char *progname;
|
||||
static char *deftext;
|
||||
|
||||
static int
|
||||
set_deftext ()
|
||||
set_deftext (void)
|
||||
{
|
||||
if (deftext)
|
||||
{
|
||||
@@ -71,16 +71,14 @@ set_deftext ()
|
||||
}
|
||||
|
||||
static void
|
||||
usage()
|
||||
usage(void)
|
||||
{
|
||||
fprintf (stderr, "%s: usage: %s [-p prompt] [-u unit] [-d default] [-n nchars]\n",
|
||||
progname, progname);
|
||||
}
|
||||
|
||||
int
|
||||
main (argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
char *temp, *prompt;
|
||||
struct stat sb;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* usage: rlcat
|
||||
*/
|
||||
|
||||
/* Copyright (C) 1987-2009 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1987-2009,2023 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of the GNU Readline Library (Readline), a library for
|
||||
reading lines of text with interactive input and history editing.
|
||||
@@ -64,27 +64,26 @@ extern int errno;
|
||||
extern int optind;
|
||||
extern char *optarg;
|
||||
|
||||
static int stdcat();
|
||||
static int fcopy(FILE *);
|
||||
static int stdcat(int, char **);
|
||||
|
||||
static char *progname;
|
||||
static int vflag;
|
||||
|
||||
static void
|
||||
usage()
|
||||
usage(void)
|
||||
{
|
||||
fprintf (stderr, "%s: usage: %s [-vEVN] [filename]\n", progname, progname);
|
||||
}
|
||||
|
||||
int
|
||||
main (argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
main (int argc, char **argv)
|
||||
{
|
||||
char *temp;
|
||||
int opt, Vflag, Nflag;
|
||||
|
||||
#ifdef HAVE_SETLOCALE
|
||||
setlocale (LC_ALL, ""):
|
||||
setlocale (LC_ALL, "");
|
||||
#endif
|
||||
|
||||
progname = strrchr(argv[0], '/');
|
||||
@@ -134,8 +133,7 @@ main (argc, argv)
|
||||
}
|
||||
|
||||
static int
|
||||
fcopy(fp)
|
||||
FILE *fp;
|
||||
fcopy(FILE *fp)
|
||||
{
|
||||
int c;
|
||||
char *x;
|
||||
@@ -155,9 +153,7 @@ fcopy(fp)
|
||||
}
|
||||
|
||||
int
|
||||
stdcat (argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
stdcat (int argc, char **argv)
|
||||
{
|
||||
int i, fd, r;
|
||||
char *s;
|
||||
|
||||
@@ -42,8 +42,7 @@ static int masterfd = -1;
|
||||
static int slavefd;
|
||||
|
||||
void
|
||||
sigint (s)
|
||||
int s;
|
||||
sigint (int s)
|
||||
{
|
||||
tty_reset (STDIN_FILENO);
|
||||
close (masterfd);
|
||||
@@ -53,14 +52,13 @@ sigint (s)
|
||||
}
|
||||
|
||||
void
|
||||
sigwinch (s)
|
||||
int s;
|
||||
sigwinch (int s)
|
||||
{
|
||||
rl_resize_terminal ();
|
||||
}
|
||||
|
||||
static int
|
||||
user_input()
|
||||
user_input(void)
|
||||
{
|
||||
int size;
|
||||
const int MAX = 1024;
|
||||
@@ -78,7 +76,7 @@ user_input()
|
||||
}
|
||||
|
||||
static int
|
||||
readline_input()
|
||||
readline_input(void)
|
||||
{
|
||||
const int MAX = 1024;
|
||||
char *buf = (char *)malloc(MAX+1);
|
||||
@@ -124,7 +122,7 @@ rlctx_send_user_command(char *line)
|
||||
}
|
||||
|
||||
static void
|
||||
custom_deprep_term_function ()
|
||||
custom_deprep_term_function (void)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -226,9 +224,10 @@ static enum { RESET, TCBREAK } ttystate = RESET;
|
||||
*
|
||||
* Returns: 0 on success, -1 on error
|
||||
*/
|
||||
int tty_cbreak(int fd){
|
||||
int tty_cbreak(int fd)
|
||||
{
|
||||
struct termios buf;
|
||||
int ttysavefd = -1;
|
||||
int ttysavefd = -1;
|
||||
|
||||
if(tcgetattr(fd, &save_termios) < 0)
|
||||
return -1;
|
||||
@@ -316,7 +315,7 @@ int tty_reset(int fd)
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
main(int c, char **v)
|
||||
{
|
||||
int val;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/* */
|
||||
/* **************************************************************** */
|
||||
|
||||
/* Copyright (C) 1987-2009 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1987-2009,2023 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of the GNU Readline Library (Readline), a library for
|
||||
reading lines of text with interactive input and history editing.
|
||||
@@ -48,10 +48,8 @@ extern void exit();
|
||||
# include <readline/history.h>
|
||||
#endif
|
||||
|
||||
extern HIST_ENTRY **history_list ();
|
||||
|
||||
int
|
||||
main ()
|
||||
main (int c, char **v)
|
||||
{
|
||||
char *temp, *prompt;
|
||||
int done;
|
||||
|
||||
+28
-2
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user