mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-06-30 08:59:56 +02:00
Bash-5.3-alpha release
This commit is contained in:
@@ -100,13 +100,14 @@ INC = -I. -I.. -I$(topdir) -I$(topdir)/lib -I$(topdir)/builtins -I${srcdir} \
|
||||
.c.o:
|
||||
$(SHOBJ_CC) $(SHOBJ_CFLAGS) $(CCFLAGS) $(INC) -c -o $@ $<
|
||||
|
||||
|
||||
ALLPROG = print truefalse sleep finfo logname basename dirname fdflags \
|
||||
tty pathchk tee head mkdir rmdir mkfifo mktemp printenv id whoami \
|
||||
uname sync push ln unlink realpath strftime mypid setpgid seq rm \
|
||||
accept csv dsv cut stat getconf
|
||||
accept csv dsv cut stat getconf kv strptime
|
||||
OTHERPROG = necho hello cat pushd asort
|
||||
|
||||
SUBDIRS = perl
|
||||
|
||||
all: $(SHOBJ_STATUS)
|
||||
|
||||
supported: $(ALLPROG)
|
||||
@@ -225,12 +226,18 @@ csv: csv.o
|
||||
dsv: dsv.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ dsv.o $(SHOBJ_LIBS)
|
||||
|
||||
kv: kv.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ kv.o $(SHOBJ_LIBS)
|
||||
|
||||
cut: cut.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ cut.o $(SHOBJ_LIBS)
|
||||
|
||||
strftime: strftime.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ strftime.o $(SHOBJ_LIBS)
|
||||
|
||||
strptime: strptime.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ strptime.o $(SHOBJ_LIBS)
|
||||
|
||||
mypid: mypid.o
|
||||
$(SHOBJ_LD) $(SHOBJ_LDFLAGS) $(SHOBJ_XLDFLAGS) -o $@ mypid.o $(SHOBJ_LIBS)
|
||||
|
||||
@@ -259,14 +266,20 @@ pushd: pushd.o
|
||||
|
||||
clean:
|
||||
$(RM) $(ALLPROG) $(OTHERPROG) *.o
|
||||
-( cd perl && ${MAKE} ${MFLAGS} $@ )
|
||||
-for subdir in $(SUBDIRS); do \
|
||||
( cd $$subdir && test -f Makefile && ${MAKE} ${MFLAGS} $@ ) ; \
|
||||
done
|
||||
|
||||
mostlyclean: clean
|
||||
-( cd perl && ${MAKE} ${MFLAGS} $@ )
|
||||
-for subdir in $(SUBDIRS); do \
|
||||
( cd $$subdir && test -f Makefile && ${MAKE} ${MFLAGS} $@ ) ; \
|
||||
done
|
||||
|
||||
distclean maintainer-clean: clean
|
||||
$(RM) Makefile Makefile.inc Makefile.sample pushd.c
|
||||
-( cd perl && ${MAKE} ${MFLAGS} $@ )
|
||||
-for subdir in $(SUBDIRS); do \
|
||||
( cd $$subdir && test -f Makefile && ${MAKE} ${MFLAGS} $@ ) ; \
|
||||
done
|
||||
|
||||
installdirs:
|
||||
@${SHELL} $(SUPPORT_SRC)mkinstalldirs $(DESTDIR)$(loadablesdir)
|
||||
@@ -298,6 +311,14 @@ uninstall-unsupported:
|
||||
install: install-$(SHOBJ_STATUS)
|
||||
uninstall: uninstall-$(SHOBJ_STATUS)
|
||||
|
||||
OBJS = print.o truefalse.o accept.o sleep.o finfo.o getconf.o logname.o \
|
||||
basename.o dirname.o tty.o pathchk.o tee.o head.o rmdir.o necho.o \
|
||||
hello.o cat.o csv.o dsv.o kv.o cut.o printenv.o id.o whoami.o uname.o \
|
||||
sync.o push.o mkdir.o mktemp.o realpath.o strftime.o setpgid.o stat.o \
|
||||
fdflags.o seq.o asort.o strptime.o
|
||||
|
||||
${OBJS}: ${BUILD_DIR}/config.h
|
||||
|
||||
print.o: print.c
|
||||
truefalse.o: truefalse.c
|
||||
accept.o: accept.c
|
||||
@@ -317,6 +338,7 @@ hello.o: hello.c
|
||||
cat.o: cat.c
|
||||
csv.o: csv.c
|
||||
dsv.o: dsv.c
|
||||
kv.o: kv.c
|
||||
cut.o: cut.c
|
||||
printenv.o: printenv.c
|
||||
id.o: id.c
|
||||
@@ -333,3 +355,4 @@ stat.o: stat.c
|
||||
fdflags.o: fdflags.c
|
||||
seq.o: seq.c
|
||||
asort.o: asort.c
|
||||
strptime.o: strptime.c
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
/* accept - listen for and accept a remote network connection on a given port */
|
||||
|
||||
/*
|
||||
Copyright (C) 2020 Free Software Foundation, Inc.
|
||||
Copyright (C) 2020,2022,2023 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash.
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
@@ -42,8 +41,7 @@
|
||||
static int accept_bind_variable (char *, int);
|
||||
|
||||
int
|
||||
accept_builtin (list)
|
||||
WORD_LIST *list;
|
||||
accept_builtin (WORD_LIST *list)
|
||||
{
|
||||
SHELL_VAR *v;
|
||||
intmax_t iport;
|
||||
@@ -105,7 +103,7 @@ accept_builtin (list)
|
||||
return (EX_USAGE);
|
||||
}
|
||||
|
||||
if (legal_number (list->word->word, &iport) == 0 || iport < 0 || iport > TYPE_MAXIMUM (unsigned short))
|
||||
if (valid_number (list->word->word, &iport) == 0 || iport < 0 || iport > TYPE_MAXIMUM (unsigned short))
|
||||
{
|
||||
builtin_error ("%s: invalid port number", list->word->word);
|
||||
return (EXECUTION_FAILURE);
|
||||
@@ -194,9 +192,7 @@ accept_builtin (list)
|
||||
}
|
||||
|
||||
static int
|
||||
accept_bind_variable (varname, intval)
|
||||
char *varname;
|
||||
int intval;
|
||||
accept_bind_variable (char *varname, int intval)
|
||||
{
|
||||
SHELL_VAR *v;
|
||||
char ibuf[INT_STRLEN_BOUND (int) + 1], *p;
|
||||
|
||||
+23
-15
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 2020 Free Software Foundation, Inc.
|
||||
Copyright (C) 2020,2022,2023 Free Software Foundation, Inc.
|
||||
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -14,6 +14,8 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Bash. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/* Contributed by Geir Hauge <geir.hauge@gmail.com> */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
@@ -36,7 +38,8 @@ static int reverse_flag;
|
||||
static int numeric_flag;
|
||||
|
||||
static int
|
||||
compare(const void *p1, const void *p2) {
|
||||
compare(const void *p1, const void *p2)
|
||||
{
|
||||
const sort_element e1 = *(sort_element *) p1;
|
||||
const sort_element e2 = *(sort_element *) p2;
|
||||
|
||||
@@ -55,7 +58,8 @@ compare(const void *p1, const void *p2) {
|
||||
}
|
||||
|
||||
static int
|
||||
sort_index(SHELL_VAR *dest, SHELL_VAR *source) {
|
||||
sort_index(SHELL_VAR *dest, SHELL_VAR *source)
|
||||
{
|
||||
HASH_TABLE *hash;
|
||||
BUCKET_CONTENTS *bucket;
|
||||
sort_element *sa;
|
||||
@@ -70,7 +74,7 @@ sort_index(SHELL_VAR *dest, SHELL_VAR *source) {
|
||||
if (assoc_p(source)) {
|
||||
hash = assoc_cell(source);
|
||||
n = hash->nentries;
|
||||
sa = xmalloc(n * sizeof(sort_element));
|
||||
sa = n ? xmalloc(n * sizeof(sort_element)) : 0;
|
||||
i = 0;
|
||||
for ( j = 0; j < hash->nbuckets; ++j ) {
|
||||
bucket = hash->bucket_array[j];
|
||||
@@ -89,7 +93,7 @@ sort_index(SHELL_VAR *dest, SHELL_VAR *source) {
|
||||
else {
|
||||
array = array_cell(source);
|
||||
n = array_num_elements(array);
|
||||
sa = xmalloc(n * sizeof(sort_element));
|
||||
sa = n ? xmalloc(n * sizeof(sort_element)) : 0;
|
||||
i = 0;
|
||||
|
||||
for (ae = element_forw(array->head); ae != array->head; ae = element_forw(ae)) {
|
||||
@@ -105,12 +109,12 @@ sort_index(SHELL_VAR *dest, SHELL_VAR *source) {
|
||||
// sanity check
|
||||
if ( i != n ) {
|
||||
builtin_error("%s: corrupt array", source->name);
|
||||
xfree (sa);
|
||||
return EXECUTION_FAILURE;
|
||||
}
|
||||
|
||||
qsort(sa, n, sizeof(sort_element), compare);
|
||||
|
||||
array_flush(dest_array);
|
||||
if (n)
|
||||
qsort(sa, n, sizeof(sort_element), compare);
|
||||
|
||||
for ( i = 0; i < n; ++i ) {
|
||||
if ( assoc_p(source) )
|
||||
@@ -121,11 +125,13 @@ sort_index(SHELL_VAR *dest, SHELL_VAR *source) {
|
||||
array_insert(dest_array, i, key);
|
||||
}
|
||||
|
||||
xfree (sa);
|
||||
return EXECUTION_SUCCESS;
|
||||
}
|
||||
|
||||
static int
|
||||
sort_inplace(SHELL_VAR *var) {
|
||||
sort_inplace(SHELL_VAR *var)
|
||||
{
|
||||
size_t i, n;
|
||||
ARRAY *a;
|
||||
ARRAY_ELEMENT *ae;
|
||||
@@ -152,6 +158,7 @@ sort_inplace(SHELL_VAR *var) {
|
||||
// sanity check
|
||||
if ( i != n ) {
|
||||
builtin_error("%s: corrupt array", var->name);
|
||||
xfree (sa);
|
||||
return EXECUTION_FAILURE;
|
||||
}
|
||||
|
||||
@@ -174,7 +181,8 @@ sort_inplace(SHELL_VAR *var) {
|
||||
}
|
||||
|
||||
int
|
||||
asort_builtin(WORD_LIST *list) {
|
||||
asort_builtin(WORD_LIST *list)
|
||||
{
|
||||
SHELL_VAR *var, *var2;
|
||||
char *word;
|
||||
int opt, ret;
|
||||
@@ -202,7 +210,7 @@ asort_builtin(WORD_LIST *list) {
|
||||
return EX_USAGE;
|
||||
}
|
||||
|
||||
if (legal_identifier (list->word->word) == 0) {
|
||||
if (valid_identifier (list->word->word) == 0) {
|
||||
sh_invalidid (list->word->word);
|
||||
return EXECUTION_FAILURE;
|
||||
}
|
||||
@@ -212,18 +220,18 @@ asort_builtin(WORD_LIST *list) {
|
||||
builtin_usage();
|
||||
return EX_USAGE;
|
||||
}
|
||||
if (legal_identifier (list->next->word->word) == 0) {
|
||||
if (valid_identifier (list->next->word->word) == 0) {
|
||||
sh_invalidid (list->next->word->word);
|
||||
return EXECUTION_FAILURE;
|
||||
}
|
||||
var = find_or_make_array_variable(list->word->word, 1);
|
||||
if (var == 0)
|
||||
return EXECUTION_FAILURE;
|
||||
var2 = find_variable(list->next->word->word);
|
||||
if ( !var2 || ( !array_p(var2) && !assoc_p(var2) ) ) {
|
||||
builtin_error("%s: Not an array", list->next->word->word);
|
||||
return EXECUTION_FAILURE;
|
||||
}
|
||||
var = builtin_find_indexed_array(list->word->word, 1);
|
||||
if (var == 0)
|
||||
return EXECUTION_FAILURE;
|
||||
return sort_index(var, var2);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/* See Makefile for compilation details. */
|
||||
|
||||
/*
|
||||
Copyright (C) 1999-2020 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999-2020,2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash.
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
@@ -33,8 +33,7 @@
|
||||
#include "bashgetopt.h"
|
||||
|
||||
int
|
||||
basename_builtin (list)
|
||||
WORD_LIST *list;
|
||||
basename_builtin (WORD_LIST *list)
|
||||
{
|
||||
int slen, sufflen, off;
|
||||
char *string, *suffix, *fn;
|
||||
|
||||
@@ -32,13 +32,11 @@
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
extern char *strerror ();
|
||||
extern char **make_builtin_argv ();
|
||||
extern char *strerror (int);
|
||||
extern char **make_builtin_argv (WORD_LIST *, int *);
|
||||
|
||||
static int
|
||||
fcopy(fd, fn)
|
||||
int fd;
|
||||
char *fn;
|
||||
fcopy(int fd, char *fn)
|
||||
{
|
||||
char buf[4096], *s;
|
||||
int n, w, e;
|
||||
@@ -70,9 +68,7 @@ char *fn;
|
||||
}
|
||||
|
||||
int
|
||||
cat_main (argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
cat_main (int argc, char **argv)
|
||||
{
|
||||
int i, fd, r;
|
||||
char *s;
|
||||
@@ -105,8 +101,7 @@ char **argv;
|
||||
}
|
||||
|
||||
int
|
||||
cat_builtin(list)
|
||||
WORD_LIST *list;
|
||||
cat_builtin(WORD_LIST *list)
|
||||
{
|
||||
char **v;
|
||||
int c, r;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
fields */
|
||||
|
||||
/*
|
||||
Copyright (C) 2020 Free Software Foundation, Inc.
|
||||
Copyright (C) 2020,2022 Free Software Foundation, Inc.
|
||||
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -39,9 +39,7 @@
|
||||
element of array variable CSV, starting at index 0. The format of LINE is
|
||||
as described in RFC 4180. */
|
||||
static int
|
||||
csvsplit (csv, line, dstring)
|
||||
SHELL_VAR *csv;
|
||||
char *line, *dstring;
|
||||
csvsplit (SHELL_VAR *csv, char *line, char *dstring)
|
||||
{
|
||||
arrayind_t ind;
|
||||
char *field, *prev, *buf, *xbuf;
|
||||
@@ -103,8 +101,7 @@ csvsplit (csv, line, dstring)
|
||||
}
|
||||
|
||||
int
|
||||
csv_builtin (list)
|
||||
WORD_LIST *list;
|
||||
csv_builtin (WORD_LIST *list)
|
||||
{
|
||||
int opt, rval;
|
||||
char *array_name, *csvstring;
|
||||
@@ -132,7 +129,7 @@ csv_builtin (list)
|
||||
if (array_name == 0)
|
||||
array_name = CSV_ARRAY_DEFAULT;
|
||||
|
||||
if (legal_identifier (array_name) == 0)
|
||||
if (valid_identifier (array_name) == 0)
|
||||
{
|
||||
sh_invalidid (array_name);
|
||||
return (EXECUTION_FAILURE);
|
||||
@@ -174,16 +171,14 @@ csv_builtin (list)
|
||||
/* Called when builtin is enabled and loaded from the shared object. If this
|
||||
function returns 0, the load fails. */
|
||||
int
|
||||
csv_builtin_load (name)
|
||||
char *name;
|
||||
csv_builtin_load (char *name)
|
||||
{
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Called when builtin is disabled. */
|
||||
void
|
||||
csv_builtin_unload (name)
|
||||
char *name;
|
||||
csv_builtin_unload (char *name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
+19
-49
@@ -2,7 +2,7 @@
|
||||
or print them to the standard output */
|
||||
|
||||
/*
|
||||
Copyright (C) 2020 Free Software Foundation, Inc.
|
||||
Copyright (C) 2020,2022,2023 Free Software Foundation, Inc.
|
||||
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -61,8 +61,7 @@ struct cutop
|
||||
};
|
||||
|
||||
static int
|
||||
poscmp (a, b)
|
||||
void *a, *b;
|
||||
poscmp (const void *a, const void *b)
|
||||
{
|
||||
struct cutpos *p1, *p2;
|
||||
|
||||
@@ -72,9 +71,7 @@ poscmp (a, b)
|
||||
}
|
||||
|
||||
static int
|
||||
getlist (arg, opp)
|
||||
char *arg;
|
||||
struct cutpos **opp;
|
||||
getlist (char *arg, struct cutpos **opp)
|
||||
{
|
||||
char *ntok, *ltok, *larg;
|
||||
int s, e;
|
||||
@@ -96,7 +93,7 @@ getlist (arg, opp)
|
||||
s = BOL;
|
||||
else
|
||||
{
|
||||
if (legal_number (ntok, &num) == 0 || (int)num != num || num <= 0)
|
||||
if (valid_number (ntok, &num) == 0 || (int)num != num || num <= 0)
|
||||
{
|
||||
builtin_error ("%s: invalid list value", ntok);
|
||||
*opp = poslist;
|
||||
@@ -111,7 +108,7 @@ getlist (arg, opp)
|
||||
e = EOL;
|
||||
else
|
||||
{
|
||||
if (legal_number (ltok, &num) == 0 || (int)num != num || num <= 0)
|
||||
if (valid_number (ltok, &num) == 0 || (int)num != num || num <= 0)
|
||||
{
|
||||
builtin_error ("%s: invalid list value", ltok);
|
||||
*opp = poslist;
|
||||
@@ -146,10 +143,7 @@ getlist (arg, opp)
|
||||
}
|
||||
|
||||
static int
|
||||
cutbytes (v, line, ops)
|
||||
SHELL_VAR *v;
|
||||
char *line;
|
||||
struct cutop *ops;
|
||||
cutbytes (SHELL_VAR *v, char *line, struct cutop *ops)
|
||||
{
|
||||
arrayind_t ind;
|
||||
char *buf, *bmap;
|
||||
@@ -197,10 +191,7 @@ cutbytes (v, line, ops)
|
||||
}
|
||||
|
||||
static int
|
||||
cutchars (v, line, ops)
|
||||
SHELL_VAR *v;
|
||||
char *line;
|
||||
struct cutop *ops;
|
||||
cutchars (SHELL_VAR *v, char *line, struct cutop *ops)
|
||||
{
|
||||
arrayind_t ind;
|
||||
char *buf, *bmap;
|
||||
@@ -272,10 +263,7 @@ cutchars (v, line, ops)
|
||||
bitmap approach as cut{bytes,chars} and assign them to the array variable
|
||||
V or print them on stdout. This function obeys SFLAG. */
|
||||
static int
|
||||
cutfields (v, line, ops)
|
||||
SHELL_VAR *v;
|
||||
char *line;
|
||||
struct cutop *ops;
|
||||
cutfields (SHELL_VAR *v, char *line, struct cutop *ops)
|
||||
{
|
||||
arrayind_t ind;
|
||||
char *buf, *bmap, *field, **fields, delim[2];
|
||||
@@ -362,10 +350,7 @@ cutfields (v, line, ops)
|
||||
}
|
||||
|
||||
static int
|
||||
cutline (v, line, ops)
|
||||
SHELL_VAR *v;
|
||||
char *line;
|
||||
struct cutop *ops;
|
||||
cutline (SHELL_VAR *v, char *line, struct cutop *ops)
|
||||
{
|
||||
int rval;
|
||||
|
||||
@@ -380,10 +365,7 @@ cutline (v, line, ops)
|
||||
}
|
||||
|
||||
static int
|
||||
cutfile (v, list, ops)
|
||||
SHELL_VAR *v;
|
||||
WORD_LIST *list;
|
||||
struct cutop *ops;
|
||||
cutfile (SHELL_VAR *v, WORD_LIST *list, struct cutop *ops)
|
||||
{
|
||||
int fd, unbuffered_read;
|
||||
char *line, *b;
|
||||
@@ -437,9 +419,7 @@ cutfile (v, list, ops)
|
||||
#define OPTSET(x) ((cutflags & (x)) ? 1 : 0)
|
||||
|
||||
static int
|
||||
cut_internal (which, list)
|
||||
int which; /* not used yet */
|
||||
WORD_LIST *list;
|
||||
cut_internal (int which, WORD_LIST *list)
|
||||
{
|
||||
int opt, rval, cutflags, delim, npos;
|
||||
char *array_name, *cutstring, *list_arg;
|
||||
@@ -497,7 +477,7 @@ cut_internal (which, list)
|
||||
}
|
||||
list = loptend;
|
||||
|
||||
if (array_name && (legal_identifier (array_name) == 0))
|
||||
if (array_name && (valid_identifier (array_name) == 0))
|
||||
{
|
||||
sh_invalidid (array_name);
|
||||
return (EXECUTION_FAILURE);
|
||||
@@ -523,22 +503,13 @@ cut_internal (which, list)
|
||||
}
|
||||
|
||||
if (array_name)
|
||||
{
|
||||
v = find_or_make_array_variable (array_name, 1);
|
||||
if (v == 0 || readonly_p (v) || noassign_p (v))
|
||||
{
|
||||
v = builtin_find_indexed_array (array_name, 1);
|
||||
if (v == 0)
|
||||
{
|
||||
if (v && readonly_p (v))
|
||||
err_readonly (array_name);
|
||||
free (poslist);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
else if (array_p (v) == 0)
|
||||
{
|
||||
builtin_error ("%s: not an indexed array", array_name);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
if (invisible_p (v))
|
||||
VUNSETATTR (v, att_invisible);
|
||||
array_flush (array_cell (v));
|
||||
}
|
||||
|
||||
op.flags = cutflags;
|
||||
@@ -562,19 +533,18 @@ cut_internal (which, list)
|
||||
else
|
||||
rval = cutfile (v, list, &op);
|
||||
|
||||
free (poslist);
|
||||
return (rval);
|
||||
}
|
||||
|
||||
int
|
||||
lcut_builtin (list)
|
||||
WORD_LIST *list;
|
||||
lcut_builtin (WORD_LIST *list)
|
||||
{
|
||||
return (cut_internal (0, list));
|
||||
}
|
||||
|
||||
int
|
||||
cut_builtin (list)
|
||||
WORD_LIST *list;
|
||||
cut_builtin (WORD_LIST *list)
|
||||
{
|
||||
return (cut_internal (1, list));
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/* See Makefile for compilation details. */
|
||||
|
||||
/*
|
||||
Copyright (C) 1999-2009 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999-2009,2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash.
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
@@ -33,8 +33,7 @@
|
||||
#include "bashgetopt.h"
|
||||
|
||||
int
|
||||
dirname_builtin (list)
|
||||
WORD_LIST *list;
|
||||
dirname_builtin (WORD_LIST *list)
|
||||
{
|
||||
int slen;
|
||||
char *string;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
array with the fields */
|
||||
|
||||
/*
|
||||
Copyright (C) 2022 Free Software Foundation, Inc.
|
||||
Copyright (C) 2022,2023 Free Software Foundation, Inc.
|
||||
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -52,10 +52,7 @@
|
||||
null fields. If you want to preserve the quote characters in the generated
|
||||
fields, pass F_PRESERVE; by default, this removes them. */
|
||||
static int
|
||||
dsvsplit (dsv, line, dstring, flags)
|
||||
SHELL_VAR *dsv;
|
||||
char *line, *dstring;
|
||||
int flags;
|
||||
dsvsplit (SHELL_VAR *dsv, char *line, char *dstring, int flags)
|
||||
{
|
||||
arrayind_t ind;
|
||||
char *field, *prev, *buf, *xbuf;
|
||||
@@ -163,8 +160,7 @@ dsvsplit (dsv, line, dstring, flags)
|
||||
}
|
||||
|
||||
int
|
||||
dsv_builtin (list)
|
||||
WORD_LIST *list;
|
||||
dsv_builtin (WORD_LIST *list)
|
||||
{
|
||||
int opt, rval, flags;
|
||||
char *array_name, *dsvstring, *delims;
|
||||
@@ -207,7 +203,7 @@ dsv_builtin (list)
|
||||
if (array_name == 0)
|
||||
array_name = DSV_ARRAY_DEFAULT;
|
||||
|
||||
if (legal_identifier (array_name) == 0)
|
||||
if (valid_identifier (array_name) == 0)
|
||||
{
|
||||
sh_invalidid (array_name);
|
||||
return (EXECUTION_FAILURE);
|
||||
@@ -249,16 +245,14 @@ dsv_builtin (list)
|
||||
/* Called when builtin is enabled and loaded from the shared object. If this
|
||||
function returns 0, the load fails. */
|
||||
int
|
||||
dsv_builtin_load (name)
|
||||
char *name;
|
||||
dsv_builtin_load (char *name)
|
||||
{
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Called when builtin is disabled. */
|
||||
void
|
||||
dsv_builtin_unload (name)
|
||||
char *name;
|
||||
dsv_builtin_unload (char *name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/* See Makefile for compilation details. */
|
||||
|
||||
/*
|
||||
Copyright (C) 2017-2022 Free Software Foundation, Inc.
|
||||
Copyright (C) 2017-2023 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash.
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
@@ -98,9 +98,21 @@ static const struct
|
||||
# define O_NOSIGPIPE 0
|
||||
#endif
|
||||
|
||||
#ifndef O_NDELAY
|
||||
/* Solaris has this */
|
||||
# define O_NDELAY 0
|
||||
#endif
|
||||
|
||||
#ifndef O_LARGEFILE
|
||||
/* HP-UX has this */
|
||||
# define O_LARGEFILE 0
|
||||
#endif
|
||||
|
||||
#ifndef O_CLOEXEC
|
||||
# define IGNOREFLAGS (O_RDONLY|O_WRONLY|O_RDWR)
|
||||
# define ALLFLAGS (O_APPEND|O_ASYNC|O_SYNC|O_NONBLOCK|O_FSYNC|O_DSYNC|\
|
||||
O_RSYNC|O_ALT_IO|O_DIRECT|O_NOATIME|O_NOSIGPIPE)
|
||||
O_RSYNC|O_ALT_IO|O_DIRECT|O_NOATIME|O_NOSIGPIPE|O_NDELAY|O_LARGEFILE|\
|
||||
IGNOREFLAGS)
|
||||
|
||||
/* An unused bit in the file status flags word we can use to pass around the
|
||||
state of close-on-exec. */
|
||||
@@ -120,7 +132,7 @@ extern int errno;
|
||||
|
||||
/* FIX THIS */
|
||||
static int
|
||||
getallflags ()
|
||||
getallflags (void)
|
||||
{
|
||||
int i, allflags;
|
||||
|
||||
@@ -164,6 +176,7 @@ printone(int fd, int p, int verbose)
|
||||
if ((f = getflags(fd, p)) == -1)
|
||||
return;
|
||||
|
||||
/* maybe make the file descriptor printing optional if only one argument */
|
||||
printf ("%d:", fd);
|
||||
|
||||
for (i = 0; i < N_FLAGS; i++)
|
||||
@@ -224,16 +237,14 @@ parseflags(char *s, int *p, int *n)
|
||||
}
|
||||
|
||||
static void
|
||||
setone(int fd, char *v, int verbose)
|
||||
setone(int fd, int pos, int neg, int verbose)
|
||||
{
|
||||
int f, n, pos, neg, cloexec;
|
||||
int f, n, cloexec;
|
||||
|
||||
f = getflags(fd, 1);
|
||||
if (f == -1)
|
||||
return;
|
||||
|
||||
parseflags(v, &pos, &neg);
|
||||
|
||||
cloexec = -1;
|
||||
|
||||
if ((pos & O_CLOEXEC) && (f & O_CLOEXEC) == 0)
|
||||
@@ -257,7 +268,7 @@ setone(int fd, char *v, int verbose)
|
||||
}
|
||||
|
||||
static int
|
||||
getmaxfd ()
|
||||
getmaxfd (void)
|
||||
{
|
||||
int maxfd, ignore;
|
||||
|
||||
@@ -281,6 +292,7 @@ int
|
||||
fdflags_builtin (WORD_LIST *list)
|
||||
{
|
||||
int opt, maxfd, i, num, verbose, setflag;
|
||||
int pos, neg;
|
||||
char *setspec;
|
||||
WORD_LIST *l;
|
||||
intmax_t inum;
|
||||
@@ -311,6 +323,9 @@ fdflags_builtin (WORD_LIST *list)
|
||||
if (list == 0 && setflag)
|
||||
return (EXECUTION_SUCCESS);
|
||||
|
||||
if (setflag)
|
||||
parseflags (setspec, &pos, &neg);
|
||||
|
||||
if (list == 0)
|
||||
{
|
||||
maxfd = getmaxfd ();
|
||||
@@ -327,7 +342,7 @@ fdflags_builtin (WORD_LIST *list)
|
||||
opt = EXECUTION_SUCCESS;
|
||||
for (l = list; l; l = l->next)
|
||||
{
|
||||
if (legal_number (l->word->word, &inum) == 0 || inum < 0)
|
||||
if (valid_number (l->word->word, &inum) == 0 || inum < 0)
|
||||
{
|
||||
builtin_error ("%s: invalid file descriptor", l->word->word);
|
||||
opt = EXECUTION_FAILURE;
|
||||
@@ -335,12 +350,12 @@ fdflags_builtin (WORD_LIST *list)
|
||||
}
|
||||
num = inum; /* truncate to int */
|
||||
if (setflag)
|
||||
setone (num, setspec, verbose);
|
||||
setone (num, pos, neg, verbose);
|
||||
else
|
||||
printone (num, 1, verbose);
|
||||
}
|
||||
|
||||
return (opt);
|
||||
return (sh_chkwrite (opt));
|
||||
}
|
||||
|
||||
char *fdflags_doc[] =
|
||||
|
||||
+48
-96
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright (C) 1999-2009 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999-2009,2022,2023 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash.
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
@@ -51,14 +51,18 @@
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
extern char **make_builtin_argv ();
|
||||
extern char **make_builtin_argv (WORD_LIST *, int *);
|
||||
|
||||
static void perms();
|
||||
static int printst();
|
||||
static int printsome();
|
||||
static void printmode();
|
||||
static int printfinfo();
|
||||
static int finfo_main();
|
||||
static struct stat *getstat(char *);
|
||||
static int printinfo(char *);
|
||||
static int getperm(int);
|
||||
|
||||
static void perms(int);
|
||||
static int printst(struct stat *);
|
||||
static int printsome(char *, int);
|
||||
static void printmode(int);
|
||||
static int printfinfo(char *);
|
||||
static int finfo_main(int, char **);
|
||||
|
||||
extern int sh_optind;
|
||||
extern char *sh_optarg;
|
||||
@@ -91,21 +95,7 @@ static int pmask;
|
||||
#define OPTIONS "acdgiflmnopsuACGMP:U"
|
||||
|
||||
static int
|
||||
octal(s)
|
||||
char *s;
|
||||
{
|
||||
int r;
|
||||
|
||||
r = *s - '0';
|
||||
while (*++s >= '0' && *s <= '7')
|
||||
r = (r * 8) + (*s - '0');
|
||||
return r;
|
||||
}
|
||||
|
||||
static int
|
||||
finfo_main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
finfo_main(int argc, char **argv)
|
||||
{
|
||||
register int i;
|
||||
int mode, flags, opt;
|
||||
@@ -134,7 +124,14 @@ char **argv;
|
||||
case 'n': flags |= OPT_NLINK; break;
|
||||
case 'o': flags |= OPT_OPERM; break;
|
||||
case 'p': flags |= OPT_PERM; break;
|
||||
case 'P': flags |= OPT_PMASK; pmask = octal(sh_optarg); break;
|
||||
case 'P':
|
||||
flags |= OPT_PMASK;
|
||||
pmask = read_octal(sh_optarg);
|
||||
if (pmask < 0) {
|
||||
builtin_error ("invalid mode: %s", sh_optarg);
|
||||
return(1);
|
||||
}
|
||||
break;
|
||||
case 's': flags |= OPT_SIZE; break;
|
||||
case 'u': flags |= OPT_UID; break;
|
||||
case 'U': flags |= OPT_UID|OPT_ASCII; break;
|
||||
@@ -157,15 +154,14 @@ char **argv;
|
||||
}
|
||||
|
||||
static struct stat *
|
||||
getstat(f)
|
||||
char *f;
|
||||
getstat(char *f)
|
||||
{
|
||||
static struct stat st;
|
||||
int fd, r;
|
||||
intmax_t lfd;
|
||||
|
||||
if (strncmp(f, "/dev/fd/", 8) == 0) {
|
||||
if ((legal_number(f + 8, &lfd) == 0) || (int)lfd != lfd) {
|
||||
if ((valid_number(f + 8, &lfd) == 0) || (int)lfd != lfd) {
|
||||
builtin_error("%s: invalid fd", f + 8);
|
||||
return ((struct stat *)0);
|
||||
}
|
||||
@@ -185,8 +181,7 @@ char *f;
|
||||
}
|
||||
|
||||
static int
|
||||
printfinfo(f)
|
||||
char *f;
|
||||
printfinfo(char *f)
|
||||
{
|
||||
struct stat *st;
|
||||
|
||||
@@ -195,15 +190,13 @@ char *f;
|
||||
}
|
||||
|
||||
static int
|
||||
getperm(m)
|
||||
int m;
|
||||
getperm(int m)
|
||||
{
|
||||
return (m & (S_IRWXU|S_IRWXG|S_IRWXO|S_ISUID|S_ISGID));
|
||||
}
|
||||
|
||||
static void
|
||||
perms(m)
|
||||
int m;
|
||||
perms(int m)
|
||||
{
|
||||
char ubits[4], gbits[4], obits[4]; /* u=rwx,g=rwx,o=rwx */
|
||||
int i;
|
||||
@@ -246,8 +239,7 @@ int m;
|
||||
}
|
||||
|
||||
static void
|
||||
printmode(mode)
|
||||
int mode;
|
||||
printmode(int mode)
|
||||
{
|
||||
if (S_ISBLK(mode))
|
||||
printf("S_IFBLK ");
|
||||
@@ -272,8 +264,7 @@ int mode;
|
||||
}
|
||||
|
||||
static int
|
||||
printst(st)
|
||||
struct stat *st;
|
||||
printst(struct stat *st)
|
||||
{
|
||||
struct passwd *pw;
|
||||
struct group *gr;
|
||||
@@ -309,15 +300,14 @@ struct stat *st;
|
||||
}
|
||||
|
||||
static int
|
||||
printsome(f, flags)
|
||||
char *f;
|
||||
int flags;
|
||||
printsome(char *f, int flags)
|
||||
{
|
||||
struct stat *st;
|
||||
struct passwd *pw;
|
||||
struct group *gr;
|
||||
int p;
|
||||
char *b;
|
||||
intmax_t xtime;
|
||||
|
||||
st = getstat(f);
|
||||
if (st == NULL)
|
||||
@@ -325,20 +315,23 @@ int flags;
|
||||
|
||||
/* Print requested info */
|
||||
if (flags & OPT_ATIME) {
|
||||
xtime = st->st_atime;
|
||||
if (flags & OPT_ASCII)
|
||||
printf("%s", ctime(&st->st_atime));
|
||||
else
|
||||
printf("%ld\n", st->st_atime);
|
||||
printf("%jd\n", xtime);
|
||||
} else if (flags & OPT_MTIME) {
|
||||
xtime = st->st_mtime;
|
||||
if (flags & OPT_ASCII)
|
||||
printf("%s", ctime(&st->st_mtime));
|
||||
else
|
||||
printf("%ld\n", st->st_mtime);
|
||||
printf("%jd\n", xtime);
|
||||
} else if (flags & OPT_CTIME) {
|
||||
xtime = st->st_ctime;
|
||||
if (flags & OPT_ASCII)
|
||||
printf("%s", ctime(&st->st_ctime));
|
||||
else
|
||||
printf("%ld\n", st->st_ctime);
|
||||
printf("%jd\n", xtime);
|
||||
} else if (flags & OPT_DEV)
|
||||
printf("%lu\n", (unsigned long)st->st_dev);
|
||||
else if (flags & OPT_INO)
|
||||
@@ -391,8 +384,7 @@ int flags;
|
||||
|
||||
#ifndef NOBUILTIN
|
||||
int
|
||||
finfo_builtin(list)
|
||||
WORD_LIST *list;
|
||||
finfo_builtin(WORD_LIST *list)
|
||||
{
|
||||
int c, r;
|
||||
char **v;
|
||||
@@ -447,34 +439,26 @@ struct builtin finfo_struct = {
|
||||
#endif
|
||||
|
||||
#ifdef NOBUILTIN
|
||||
#if defined (PREFER_STDARG)
|
||||
# include <stdarg.h>
|
||||
#else
|
||||
# if defined (PREFER_VARARGS)
|
||||
# include <varargs.h>
|
||||
# endif
|
||||
#endif
|
||||
#include <stdarg.h>
|
||||
|
||||
char *this_command_name;
|
||||
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char **argv;
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
this_command_name = argv[0];
|
||||
exit(finfo_main(argc, argv));
|
||||
}
|
||||
|
||||
void
|
||||
builtin_usage()
|
||||
builtin_usage(void)
|
||||
{
|
||||
fprintf(stderr, "%s: usage: %s [-%s] [file ...]\n", prog, prog, OPTIONS);
|
||||
}
|
||||
|
||||
#ifndef HAVE_STRERROR
|
||||
char *
|
||||
strerror(e)
|
||||
int e;
|
||||
strerror(int e)
|
||||
{
|
||||
static char ebuf[40];
|
||||
extern int sys_nerr;
|
||||
@@ -488,23 +472,20 @@ int e;
|
||||
}
|
||||
#endif
|
||||
|
||||
char *
|
||||
xmalloc(s)
|
||||
size_t s;
|
||||
PTR_T
|
||||
xmalloc(size_t s)
|
||||
{
|
||||
char *ret;
|
||||
extern char *malloc();
|
||||
|
||||
ret = malloc(s);
|
||||
if (ret)
|
||||
return (ret);
|
||||
fprintf(stderr, "%s: cannot malloc %d bytes\n", prog, s);
|
||||
fprintf(stderr, "%s: cannot malloc %zu bytes\n", prog, s);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
char *
|
||||
base_pathname(p)
|
||||
char *p;
|
||||
base_pathname(char *p)
|
||||
{
|
||||
char *t;
|
||||
|
||||
@@ -514,9 +495,7 @@ char *p;
|
||||
}
|
||||
|
||||
int
|
||||
legal_number (string, result)
|
||||
char *string;
|
||||
long *result;
|
||||
valid_number (char *string, long result)
|
||||
{
|
||||
int sign;
|
||||
long value;
|
||||
@@ -575,9 +554,7 @@ extern int optind;
|
||||
extern char *optarg;
|
||||
|
||||
int
|
||||
sh_getopt(c, v, o)
|
||||
int c;
|
||||
char **v, *o;
|
||||
sh_getopt(int c, char **v, char *o)
|
||||
{
|
||||
int r;
|
||||
|
||||
@@ -587,43 +564,18 @@ char **v, *o;
|
||||
return r;
|
||||
}
|
||||
|
||||
#if defined (USE_VARARGS)
|
||||
void
|
||||
#if defined (PREFER_STDARG)
|
||||
builtin_error (const char *format, ...)
|
||||
#else
|
||||
builtin_error (format, va_alist)
|
||||
const char *format;
|
||||
va_dcl
|
||||
#endif
|
||||
{
|
||||
va_list args;
|
||||
|
||||
if (this_command_name && *this_command_name)
|
||||
fprintf (stderr, "%s: ", this_command_name);
|
||||
|
||||
#if defined (PREFER_STDARG)
|
||||
va_start (args, format);
|
||||
#else
|
||||
va_start (args);
|
||||
#endif
|
||||
|
||||
vfprintf (stderr, format, args);
|
||||
va_end (args);
|
||||
fprintf (stderr, "\n");
|
||||
}
|
||||
#else
|
||||
void
|
||||
builtin_error (format, arg1, arg2, arg3, arg4, arg5)
|
||||
char *format, *arg1, *arg2, *arg3, *arg4, *arg5;
|
||||
{
|
||||
if (this_command_name && *this_command_name)
|
||||
fprintf (stderr, "%s: ", this_command_name);
|
||||
|
||||
fprintf (stderr, format, arg1, arg2, arg3, arg4, arg5);
|
||||
fprintf (stderr, "\n");
|
||||
fflush (stderr);
|
||||
}
|
||||
#endif /* !USE_VARARGS */
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 1991-2021 Free Software Foundation, Inc.
|
||||
/* Copyright (C) 1991-2023 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
@@ -21,7 +21,7 @@
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <error.h>
|
||||
#include <libintl.h>
|
||||
#include <gettext.h>
|
||||
#include <locale.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
@@ -43,6 +43,11 @@ extern int errno;
|
||||
#define VAL_SSIZE_MAX -1004
|
||||
#define VAL_SIZE_MAX -1005
|
||||
|
||||
/* We don't want to collide with anything else. */
|
||||
#ifndef _CS_PATH
|
||||
#define _CS_PATH -1001
|
||||
#endif
|
||||
|
||||
struct conf
|
||||
{
|
||||
const char *name;
|
||||
@@ -120,7 +125,7 @@ static const struct conf vars[] =
|
||||
#ifdef _SC_CHAR_MAX
|
||||
{ "CHAR_MAX", _SC_CHAR_MAX, SYSCONF },
|
||||
#else
|
||||
{ "CHAR_BIT", CHAR_MAX, CONSTANT },
|
||||
{ "CHAR_MAX", CHAR_MAX, CONSTANT },
|
||||
#endif
|
||||
#ifdef _SC_CHAR_MIN
|
||||
{ "CHAR_MIN", _SC_CHAR_MIN, SYSCONF },
|
||||
@@ -269,9 +274,15 @@ static const struct conf vars[] =
|
||||
#ifdef _SC_AVPHYS_PAGES
|
||||
{ "_AVPHYS_PAGES", _SC_AVPHYS_PAGES, SYSCONF },
|
||||
#endif
|
||||
#ifdef _SC_NPROCESSORS_CONF
|
||||
{ "_NPROCESSORS_CONF", _SC_NPROCESSORS_CONF, SYSCONF },
|
||||
#endif
|
||||
#ifdef _SC_NPROCESSORS_ONLN
|
||||
{ "_NPROCESSORS_ONLN", _SC_NPROCESSORS_ONLN, SYSCONF },
|
||||
#endif
|
||||
#ifdef _SC_PHYS_PAGES
|
||||
{ "_PHYS_PAGES", _SC_PHYS_PAGES, SYSCONF },
|
||||
#endif
|
||||
#ifdef _SC_ARG_MAX
|
||||
{ "_POSIX_ARG_MAX", _SC_ARG_MAX, SYSCONF },
|
||||
#else
|
||||
@@ -329,7 +340,9 @@ static const struct conf vars[] =
|
||||
{ "_POSIX_PRIORITIZED_IO", _SC_PRIORITIZED_IO, SYSCONF },
|
||||
#endif
|
||||
{ "_POSIX_PRIORITY_SCHEDULING", _SC_PRIORITY_SCHEDULING, SYSCONF },
|
||||
#ifdef _SC_REALTIME_SIGNALS
|
||||
{ "_POSIX_REALTIME_SIGNALS", _SC_REALTIME_SIGNALS, SYSCONF },
|
||||
#endif
|
||||
{ "_POSIX_SAVED_IDS", _SC_SAVED_IDS, SYSCONF },
|
||||
#ifdef _SC_SELECT
|
||||
{ "_POSIX_SELECT", _SC_SELECT, SYSCONF },
|
||||
@@ -366,7 +379,9 @@ static const struct conf vars[] =
|
||||
{ "_POSIX_THREAD_PROCESS_SHARED", _SC_THREAD_PROCESS_SHARED, SYSCONF },
|
||||
{ "_POSIX_THREAD_SAFE_FUNCTIONS", _SC_THREAD_SAFE_FUNCTIONS, SYSCONF },
|
||||
{ "_POSIX_TIMERS", _SC_TIMERS, SYSCONF },
|
||||
#ifdef _SC_TIMER_MAX
|
||||
{ "TIMER_MAX", _SC_TIMER_MAX, SYSCONF },
|
||||
#endif
|
||||
#ifdef _POSIX_TZNAME_MAX
|
||||
{ "_POSIX_TZNAME_MAX", _SC_TZNAME_MAX, SYSCONF },
|
||||
#else
|
||||
@@ -743,8 +758,12 @@ static const struct conf vars[] =
|
||||
{ "_POSIX_C_LANG_SUPPORT_R", _SC_C_LANG_SUPPORT_R, SYSCONF },
|
||||
#endif
|
||||
{ "_POSIX_CLOCK_SELECTION", _SC_CLOCK_SELECTION, SYSCONF },
|
||||
#ifdef _SC_CPUTIME
|
||||
{ "_POSIX_CPUTIME", _SC_CPUTIME, SYSCONF },
|
||||
#endif
|
||||
#ifdef _SC_THREAD_CPUTIME
|
||||
{ "_POSIX_THREAD_CPUTIME", _SC_THREAD_CPUTIME, SYSCONF },
|
||||
#endif
|
||||
#ifdef _SC_DEVICE_SPECIFIC
|
||||
{ "_POSIX_DEVICE_SPECIFIC", _SC_DEVICE_SPECIFIC, SYSCONF },
|
||||
#endif
|
||||
@@ -826,7 +845,9 @@ static const struct conf vars[] =
|
||||
#ifdef _SC_AIO_PRIO_DELTA_MAX
|
||||
{ "AIO_PRIO_DELTA_MAX", _SC_AIO_PRIO_DELTA_MAX, SYSCONF },
|
||||
#endif
|
||||
#ifdef _SC_DELAYTIMER_MAX
|
||||
{ "DELAYTIMER_MAX", _SC_DELAYTIMER_MAX, SYSCONF },
|
||||
#endif
|
||||
{ "HOST_NAME_MAX", _SC_HOST_NAME_MAX, SYSCONF },
|
||||
{ "LOGIN_NAME_MAX", _SC_LOGIN_NAME_MAX, SYSCONF },
|
||||
{ "MQ_OPEN_MAX", _SC_MQ_OPEN_MAX, SYSCONF },
|
||||
@@ -846,15 +867,21 @@ static const struct conf vars[] =
|
||||
#ifdef _SC_TRACE_LOG
|
||||
{ "_POSIX_TRACE_LOG", _SC_TRACE_LOG, SYSCONF },
|
||||
#endif
|
||||
#ifdef _SC_RTSIG_MAX
|
||||
{ "RTSIG_MAX", _SC_RTSIG_MAX, SYSCONF },
|
||||
#endif
|
||||
#ifdef _SC_SEM_NSEMS_MAX
|
||||
{ "SEM_NSEMS_MAX", _SC_SEM_NSEMS_MAX, SYSCONF },
|
||||
#endif
|
||||
#ifdef _SC_SEM_VALUE_MAX
|
||||
{ "SEM_VALUE_MAX", _SC_SEM_VALUE_MAX, SYSCONF },
|
||||
#endif
|
||||
#ifdef _SC_SIGQUEUE_MAX
|
||||
{ "SIGQUEUE_MAX", _SC_SIGQUEUE_MAX, SYSCONF },
|
||||
#endif
|
||||
#ifdef _PC_FILESIZEBITS
|
||||
{ "FILESIZEBITS", _PC_FILESIZEBITS, PATHCONF },
|
||||
#endif
|
||||
#ifdef _PC_ALLOC_SIZE_MIN
|
||||
{ "POSIX_ALLOC_SIZE_MIN", _PC_ALLOC_SIZE_MIN, PATHCONF },
|
||||
#endif
|
||||
@@ -870,7 +897,9 @@ static const struct conf vars[] =
|
||||
#ifdef _PC_REC_XFER_ALIGN
|
||||
{ "POSIX_REC_XFER_ALIGN", _PC_REC_XFER_ALIGN, PATHCONF },
|
||||
#endif
|
||||
#ifdef _PC_SYMLINK_MAX
|
||||
{ "SYMLINK_MAX", _PC_SYMLINK_MAX, PATHCONF },
|
||||
#endif
|
||||
#ifdef _PC_2_SYMLINKS
|
||||
{ "POSIX2_SYMLINKS", _PC_2_SYMLINKS, PATHCONF },
|
||||
#endif
|
||||
@@ -912,10 +941,35 @@ static const struct conf vars[] =
|
||||
};
|
||||
|
||||
static int getconf_print (const struct conf *, const char *, int);
|
||||
static int getconf_all (void);
|
||||
static int getconf_all (WORD_LIST *);
|
||||
static int getconf_one (WORD_LIST *);
|
||||
static int getconf_internal (const struct conf *, int);
|
||||
|
||||
#ifndef HAVE_CONFSTR
|
||||
/* If we don't have confstr, this will only support `getconf PATH'. */
|
||||
|
||||
static size_t
|
||||
confstr (int name, char *buf, size_t len)
|
||||
{
|
||||
char *p;
|
||||
size_t n;
|
||||
|
||||
switch (name)
|
||||
{
|
||||
case _CS_PATH:
|
||||
p = conf_standard_path ();
|
||||
n = STRLEN (p) + 1;
|
||||
if (len != 0 && buf != 0)
|
||||
strlcpy (buf, p, len);
|
||||
free (p);
|
||||
return n;
|
||||
default:
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif /* !HAVE_CONFSTR */
|
||||
|
||||
static int
|
||||
getconf_internal (const struct conf *c, int all)
|
||||
{
|
||||
@@ -981,17 +1035,23 @@ getconf_internal (const struct conf *c, int all)
|
||||
}
|
||||
|
||||
static int
|
||||
getconf_all (void)
|
||||
getconf_all (WORD_LIST *list)
|
||||
{
|
||||
const struct conf *c;
|
||||
char *path;
|
||||
int r;
|
||||
|
||||
r = EXECUTION_SUCCESS;
|
||||
path = list ? list->word->word : 0;
|
||||
for (c = vars; c->name != NULL; ++c)
|
||||
{
|
||||
if (c->call == PATHCONF && path == 0)
|
||||
continue; /* Don't print pathconf vars if no path supplied */
|
||||
#if 0
|
||||
if (c->call != PATHCONF && path)
|
||||
continue; /* Only print pathconf vars if path supplied */
|
||||
#endif
|
||||
printf("%-35s", c->name);
|
||||
path = "/"; /* XXX for now */
|
||||
if (getconf_print (c, path, 1) == EXECUTION_FAILURE)
|
||||
r = EXECUTION_FAILURE;
|
||||
}
|
||||
@@ -1019,12 +1079,12 @@ getconf_one (WORD_LIST *list)
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
if (c->call_name == PATHCONF && list->next == 0)
|
||||
if (c->call == PATHCONF && list->next == 0)
|
||||
{
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
else if (c->call_name != PATHCONF && list->next)
|
||||
else if (c->call != PATHCONF && list->next)
|
||||
{
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
@@ -1135,13 +1195,19 @@ getconf_builtin (WORD_LIST *list)
|
||||
}
|
||||
|
||||
list = loptend;
|
||||
if ((aflag == 0 && list == 0) || (aflag && list) || list_length(list) > 2)
|
||||
if ((aflag == 0 && list == 0) || (list && list_length((GENERIC_LIST *)list) > 2))
|
||||
{
|
||||
builtin_usage();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
else if (aflag && list && (list->word == 0 || list->word->word == 0 || *list->word->word == 0))
|
||||
{
|
||||
/* No null pathnames with -a */
|
||||
builtin_usage();
|
||||
return (EX_USAGE);
|
||||
}
|
||||
|
||||
r = aflag ? getconf_all () : getconf_one (list);
|
||||
r = aflag ? getconf_all (list) : getconf_one (list);
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -1158,6 +1224,6 @@ struct builtin getconf_struct = {
|
||||
getconf_builtin,
|
||||
BUILTIN_ENABLED,
|
||||
getconf_doc,
|
||||
"getconf -[ah] or getconf [-v spec] sysvar or getconf [-v spec] pathvar pathname",
|
||||
"getconf -[ah] [file] or getconf [-v spec] sysvar or getconf [-v spec] pathvar pathname",
|
||||
0
|
||||
};
|
||||
|
||||
@@ -125,12 +125,4 @@
|
||||
# define WORD_BIT (sizeof (int) * CHAR_BIT)
|
||||
#endif
|
||||
|
||||
#if !defined (PRIdMAX)
|
||||
# if HAVE_LONG_LONG
|
||||
# define PRIdMAX "lld"
|
||||
# else
|
||||
# define PRIdMAX "ld"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#endif /* _GETCONF_H */
|
||||
|
||||
@@ -46,8 +46,7 @@ extern int errno;
|
||||
#endif
|
||||
|
||||
static void
|
||||
munge_list (list)
|
||||
WORD_LIST *list;
|
||||
munge_list (WORD_LIST *list)
|
||||
{
|
||||
WORD_LIST *l, *nl;
|
||||
WORD_DESC *wd;
|
||||
@@ -69,9 +68,7 @@ munge_list (list)
|
||||
}
|
||||
|
||||
static int
|
||||
file_head (fp, cnt)
|
||||
FILE *fp;
|
||||
int cnt;
|
||||
file_head (FILE *fp, int cnt)
|
||||
{
|
||||
int ch;
|
||||
|
||||
@@ -94,8 +91,7 @@ file_head (fp, cnt)
|
||||
}
|
||||
|
||||
int
|
||||
head_builtin (list)
|
||||
WORD_LIST *list;
|
||||
head_builtin (WORD_LIST *list)
|
||||
{
|
||||
int nline, opt, rval;
|
||||
WORD_LIST *l;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/* See Makefile for compilation details. */
|
||||
|
||||
/*
|
||||
Copyright (C) 1999-2009 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999-2009,2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash.
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
@@ -48,8 +48,7 @@
|
||||
A builtin command returns EXECUTION_SUCCESS for success and
|
||||
EXECUTION_FAILURE to indicate failure. */
|
||||
int
|
||||
hello_builtin (list)
|
||||
WORD_LIST *list;
|
||||
hello_builtin (WORD_LIST *list)
|
||||
{
|
||||
printf("hello world\n");
|
||||
fflush (stdout);
|
||||
@@ -57,8 +56,7 @@ hello_builtin (list)
|
||||
}
|
||||
|
||||
int
|
||||
hello_builtin_load (s)
|
||||
char *s;
|
||||
hello_builtin_load (char *s)
|
||||
{
|
||||
printf ("hello builtin loaded\n");
|
||||
fflush (stdout);
|
||||
@@ -66,8 +64,7 @@ hello_builtin_load (s)
|
||||
}
|
||||
|
||||
void
|
||||
hello_builtin_unload (s)
|
||||
char *s;
|
||||
hello_builtin_unload (char *s)
|
||||
{
|
||||
printf ("hello builtin unloaded\n");
|
||||
fflush (stdout);
|
||||
|
||||
+14
-20
@@ -10,7 +10,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright (C) 1999-2009 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999-2009,2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash.
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
@@ -41,9 +41,9 @@
|
||||
#endif
|
||||
|
||||
#if !defined (HAVE_GETPW_DECLS)
|
||||
extern struct passwd *getpwuid ();
|
||||
extern struct passwd *getpwuid (uid_t);
|
||||
#endif
|
||||
extern struct group *getgrgid ();
|
||||
extern struct group *getgrgid (gid_t);
|
||||
|
||||
#include "shell.h"
|
||||
#include "builtins.h"
|
||||
@@ -66,16 +66,15 @@ static gid_t rgid, egid;
|
||||
|
||||
static char *id_user;
|
||||
|
||||
static int inituser ();
|
||||
static int inituser (char *);
|
||||
|
||||
static int id_pruser ();
|
||||
static int id_prgrp ();
|
||||
static int id_prgroups ();
|
||||
static int id_prall ();
|
||||
static int id_pruser (int);
|
||||
static int id_prgrp (int);
|
||||
static int id_prgroups (char *);
|
||||
static int id_prall (char *);
|
||||
|
||||
int
|
||||
id_builtin (list)
|
||||
WORD_LIST *list;
|
||||
id_builtin (WORD_LIST *list)
|
||||
{
|
||||
int opt;
|
||||
char *user;
|
||||
@@ -134,8 +133,7 @@ id_builtin (list)
|
||||
}
|
||||
|
||||
static int
|
||||
inituser (uname)
|
||||
char *uname;
|
||||
inituser (char *uname)
|
||||
{
|
||||
struct passwd *pwd;
|
||||
|
||||
@@ -162,8 +160,7 @@ inituser (uname)
|
||||
|
||||
/* Print the name or value of user ID UID. */
|
||||
static int
|
||||
id_pruser (uid)
|
||||
int uid;
|
||||
id_pruser (int uid)
|
||||
{
|
||||
struct passwd *pwd = NULL;
|
||||
int r;
|
||||
@@ -186,8 +183,7 @@ id_pruser (uid)
|
||||
/* Print the name or value of group ID GID. */
|
||||
|
||||
static int
|
||||
id_prgrp (gid)
|
||||
int gid;
|
||||
id_prgrp (int gid)
|
||||
{
|
||||
struct group *grp = NULL;
|
||||
int r;
|
||||
@@ -209,8 +205,7 @@ id_prgrp (gid)
|
||||
}
|
||||
|
||||
static int
|
||||
id_prgroups (uname)
|
||||
char *uname;
|
||||
id_prgroups (char *uname)
|
||||
{
|
||||
int *glist, ng, i, r;
|
||||
|
||||
@@ -243,8 +238,7 @@ id_prgroups (uname)
|
||||
}
|
||||
|
||||
static int
|
||||
id_prall (uname)
|
||||
char *uname;
|
||||
id_prall (char *uname)
|
||||
{
|
||||
int r, i, ng, *glist;
|
||||
struct passwd *pwd;
|
||||
|
||||
+8
-10
@@ -3,7 +3,7 @@
|
||||
/* See Makefile for compilation details. */
|
||||
|
||||
/*
|
||||
Copyright (C) 1999-2020 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash.
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
@@ -42,18 +42,19 @@
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
typedef int unix_link_syscall_t PARAMS((const char *, const char *));
|
||||
typedef int unix_link_syscall_t (const char *, const char *);
|
||||
|
||||
#define LN_SYMLINK 0x01
|
||||
#define LN_UNLINK 0x02
|
||||
#define LN_NOFOLLOW 0x04
|
||||
|
||||
static unix_link_syscall_t *linkfn;
|
||||
static int dolink ();
|
||||
|
||||
static char *mkdirpath (char *, char *);
|
||||
static int dolink (char *, char *, int);
|
||||
|
||||
int
|
||||
ln_builtin (list)
|
||||
WORD_LIST *list;
|
||||
ln_builtin (WORD_LIST *list)
|
||||
{
|
||||
int rval, opt, flags;
|
||||
WORD_LIST *l;
|
||||
@@ -125,8 +126,7 @@ ln_builtin (list)
|
||||
}
|
||||
|
||||
static char *
|
||||
mkdirpath (dir, file)
|
||||
char *dir, *file;
|
||||
mkdirpath (char *dir, char *file)
|
||||
{
|
||||
int dlen, flen;
|
||||
char *ret;
|
||||
@@ -152,9 +152,7 @@ mkdirpath (dir, file)
|
||||
#endif
|
||||
|
||||
static int
|
||||
dolink (src, dst, flags)
|
||||
char *src, *dst;
|
||||
int flags;
|
||||
dolink (char *src, char *dst, int flags)
|
||||
{
|
||||
struct stat ssb, dsb;
|
||||
int exists;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* logname - print login name of current user */
|
||||
|
||||
/*
|
||||
Copyright (C) 1999-2009 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999-2009,2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash.
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
@@ -36,8 +36,7 @@ extern int errno;
|
||||
#endif
|
||||
|
||||
int
|
||||
logname_builtin (list)
|
||||
WORD_LIST *list;
|
||||
logname_builtin (WORD_LIST *list)
|
||||
{
|
||||
char *np;
|
||||
|
||||
|
||||
+54
-40
@@ -3,7 +3,7 @@
|
||||
/* See Makefile for compilation details. */
|
||||
|
||||
/*
|
||||
Copyright (C) 1999-2009 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999-2009,2022-2023 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash.
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
@@ -42,15 +42,14 @@ extern int errno;
|
||||
|
||||
#define ISOCTAL(c) ((c) >= '0' && (c) <= '7')
|
||||
|
||||
extern int parse_symbolic_mode ();
|
||||
extern int parse_symbolic_mode (char *, mode_t);
|
||||
|
||||
static int make_path ();
|
||||
static int make_path (char *, int, int, int);
|
||||
|
||||
static int original_umask;
|
||||
|
||||
int
|
||||
mkdir_builtin (list)
|
||||
WORD_LIST *list;
|
||||
mkdir_builtin (WORD_LIST *list)
|
||||
{
|
||||
int opt, pflag, mflag, omode, rval, nmode, parent_mode;
|
||||
char *mode;
|
||||
@@ -134,15 +133,14 @@ mkdir_builtin (list)
|
||||
this changes the process's umask; make sure that all paths leading to a
|
||||
return reset it to ORIGINAL_UMASK */
|
||||
static int
|
||||
make_path (path, user_mode, nmode, parent_mode)
|
||||
char *path;
|
||||
int user_mode;
|
||||
int nmode, parent_mode;
|
||||
make_path (char *path, int user_mode, int nmode, int parent_mode)
|
||||
{
|
||||
int oumask;
|
||||
mode_t oumask;
|
||||
struct stat sb;
|
||||
char *p, *npath;
|
||||
int tail;
|
||||
|
||||
/* If we don't have to do any work, don't do any work. */
|
||||
if (stat (path, &sb) == 0)
|
||||
{
|
||||
if (S_ISDIR (sb.st_mode) == 0)
|
||||
@@ -170,48 +168,64 @@ make_path (path, user_mode, nmode, parent_mode)
|
||||
while (*p == '/')
|
||||
p++;
|
||||
|
||||
while (p = strchr (p, '/'))
|
||||
tail = 0;
|
||||
while (tail == 0)
|
||||
{
|
||||
*p = '\0';
|
||||
if (stat (npath, &sb) != 0)
|
||||
if (*p == '\0')
|
||||
tail = 1;
|
||||
else
|
||||
p = strchr (p, '/');
|
||||
if (p)
|
||||
*p = '\0';
|
||||
else
|
||||
tail = 1;
|
||||
if (mkdir (npath, 0) < 0)
|
||||
{
|
||||
if (mkdir (npath, 0))
|
||||
/* "Each dir operand that names an existing directory shall be
|
||||
ignored without error." */
|
||||
if (errno == EEXIST || errno == EISDIR)
|
||||
{
|
||||
int e = errno;
|
||||
int fail = 0;
|
||||
|
||||
if (stat (npath, &sb) != 0)
|
||||
{
|
||||
fail = 1;
|
||||
builtin_error ("cannot create directory `%s': %s", npath, strerror (e));
|
||||
}
|
||||
else if (e == EEXIST && S_ISDIR (sb.st_mode) == 0)
|
||||
{
|
||||
fail = 1;
|
||||
builtin_error ("`%s': file exists but is not a directory", npath);
|
||||
}
|
||||
if (fail)
|
||||
{
|
||||
umask (original_umask);
|
||||
free (npath);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
builtin_error ("cannot create directory `%s': %s", npath, strerror (errno));
|
||||
umask (original_umask);
|
||||
free (npath);
|
||||
return 1;
|
||||
}
|
||||
if (chmod (npath, parent_mode) != 0)
|
||||
{
|
||||
builtin_error ("cannot chmod directory `%s': %s", npath, strerror (errno));
|
||||
umask (original_umask);
|
||||
free (npath);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if (S_ISDIR (sb.st_mode) == 0)
|
||||
{
|
||||
builtin_error ("`%s': file exists but is not a directory", npath);
|
||||
umask (original_umask);
|
||||
free (npath);
|
||||
return 1;
|
||||
}
|
||||
|
||||
*p++ = '/'; /* restore slash */
|
||||
while (*p == '/')
|
||||
if (chmod (npath, (tail == 0) ? parent_mode : nmode) != 0)
|
||||
{
|
||||
builtin_error ("cannot chmod directory `%s': %s", npath, strerror (errno));
|
||||
umask (original_umask);
|
||||
free (npath);
|
||||
return 1;
|
||||
}
|
||||
if (tail == 0)
|
||||
*p++ = '/'; /* restore slash */
|
||||
while (p && *p == '/') /* skip consecutive slashes or trailing slash */
|
||||
p++;
|
||||
}
|
||||
|
||||
/* Create the final directory component. */
|
||||
if (stat (npath, &sb) && mkdir (npath, nmode))
|
||||
{
|
||||
builtin_error ("cannot create directory `%s': %s", npath, strerror (errno));
|
||||
umask (original_umask);
|
||||
free (npath);
|
||||
return 1;
|
||||
}
|
||||
|
||||
umask (original_umask);
|
||||
free (npath);
|
||||
return 0;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/* See Makefile for compilation details. */
|
||||
|
||||
/*
|
||||
Copyright (C) 1999-2020 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999-2020,2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash.
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
@@ -42,13 +42,12 @@ extern int errno;
|
||||
|
||||
#define ISOCTAL(c) ((c) >= '0' && (c) <= '7')
|
||||
|
||||
extern int parse_symbolic_mode ();
|
||||
extern int parse_symbolic_mode (char *, mode_t);
|
||||
|
||||
static int original_umask;
|
||||
|
||||
int
|
||||
mkfifo_builtin (list)
|
||||
WORD_LIST *list;
|
||||
mkfifo_builtin (WORD_LIST *list)
|
||||
{
|
||||
int opt, mflag, omode, rval, nmode, basemode;
|
||||
char *mode;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* mktemp - create temporary file or directory */
|
||||
|
||||
/*
|
||||
Copyright (C) 2019 Free Software Foundation, Inc.
|
||||
Copyright (C) 2019,2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash.
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
@@ -32,8 +32,7 @@
|
||||
#define DEFAULT_PREFIX "shtmp"
|
||||
|
||||
int
|
||||
mktemp_builtin (list)
|
||||
WORD_LIST *list;
|
||||
mktemp_builtin (WORD_LIST *list)
|
||||
{
|
||||
WORD_LIST *l;
|
||||
int rval, opt, fd, mflags, base_mflags;
|
||||
@@ -76,7 +75,7 @@ mktemp_builtin (list)
|
||||
|
||||
if (varname) /* check for validity, not readonly */
|
||||
{
|
||||
if (legal_identifier (varname) == 0)
|
||||
if (valid_identifier (varname) == 0)
|
||||
{
|
||||
if (qflag == 0)
|
||||
sh_invalidid (varname);
|
||||
|
||||
@@ -32,11 +32,7 @@
|
||||
while (0)
|
||||
|
||||
static SHELL_VAR *
|
||||
assign_mypid (
|
||||
SHELL_VAR *self,
|
||||
char *value,
|
||||
arrayind_t unused,
|
||||
char *key )
|
||||
assign_mypid (SHELL_VAR *self, char *value, arrayind_t unused, char *key)
|
||||
{
|
||||
return (self);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
existing builtin. */
|
||||
|
||||
/*
|
||||
Copyright (C) 1999-2009 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999-2009,2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash.
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
@@ -20,14 +20,14 @@
|
||||
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 <stdio.h>
|
||||
#include "builtins.h"
|
||||
#include "shell.h"
|
||||
#include <stdio.h>
|
||||
|
||||
int
|
||||
necho_builtin (list)
|
||||
WORD_LIST *list;
|
||||
necho_builtin (WORD_LIST *list)
|
||||
{
|
||||
print_word_list (list, " ");
|
||||
printf("\n");
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
/* See Makefile for compilation details. */
|
||||
|
||||
/*
|
||||
Copyright (C) 1999-2009 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999-2009,2022,2023 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash.
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
@@ -94,13 +94,12 @@ extern int errno;
|
||||
# define NAME_MAX_FOR(p) NAME_MAX
|
||||
#endif
|
||||
|
||||
extern char *strerror ();
|
||||
extern char *strerror (int);
|
||||
|
||||
static int validate_path ();
|
||||
static int validate_path (char *, int);
|
||||
|
||||
int
|
||||
pathchk_builtin (list)
|
||||
WORD_LIST *list;
|
||||
pathchk_builtin (WORD_LIST *list)
|
||||
{
|
||||
int retval, pflag, opt;
|
||||
|
||||
@@ -185,8 +184,7 @@ static char const portable_chars[256] =
|
||||
/* If PATH contains only portable characters, return 1, else 0. */
|
||||
|
||||
static int
|
||||
portable_chars_only (path)
|
||||
const char *path;
|
||||
portable_chars_only (const char *path)
|
||||
{
|
||||
const char *p;
|
||||
|
||||
@@ -206,9 +204,7 @@ portable_chars_only (path)
|
||||
#else
|
||||
# define SAFE_STAT(name, buf) safe_stat (name, buf)
|
||||
static inline int
|
||||
safe_stat (name, buf)
|
||||
const char *name;
|
||||
struct stat *buf;
|
||||
safe_stat (const char *name, struct stat *buf)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@@ -224,8 +220,7 @@ safe_stat (name, buf)
|
||||
2 if it doesn't exist. */
|
||||
|
||||
static int
|
||||
dir_ok (path)
|
||||
const char *path;
|
||||
dir_ok (const char *path)
|
||||
{
|
||||
struct stat stats;
|
||||
|
||||
@@ -255,8 +250,7 @@ dir_ok (path)
|
||||
}
|
||||
|
||||
static char *
|
||||
xstrdup (s)
|
||||
char *s;
|
||||
xstrdup (char *s)
|
||||
{
|
||||
return (savestring (s));
|
||||
}
|
||||
@@ -276,9 +270,7 @@ xstrdup (s)
|
||||
Return 0 if all of these tests are successful, 1 if any fail. */
|
||||
|
||||
static int
|
||||
validate_path (path, portability)
|
||||
char *path;
|
||||
int portability;
|
||||
validate_path (char *path, int portability)
|
||||
{
|
||||
int path_max;
|
||||
int last_elem; /* Nonzero if checking last element of path. */
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright (C) 1999-2009 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999-2009,2022,2023 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash.
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
@@ -42,8 +42,8 @@
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
int print_builtin ();
|
||||
static int printargs ();
|
||||
int print_builtin (WORD_LIST *);
|
||||
static int printargs (WORD_LIST *, FILE *);
|
||||
|
||||
static FILE *ofp;
|
||||
|
||||
@@ -72,8 +72,7 @@ struct builtin print_struct = {
|
||||
#endif
|
||||
|
||||
int
|
||||
print_builtin (list)
|
||||
WORD_LIST *list;
|
||||
print_builtin (WORD_LIST *list)
|
||||
{
|
||||
int c, r, nflag, raw, ofd, sflag;
|
||||
intmax_t lfd;
|
||||
@@ -110,7 +109,7 @@ print_builtin (list)
|
||||
case 'p':
|
||||
break; /* NOP */
|
||||
case 'u':
|
||||
if (all_digits (list_optarg) && legal_number (list_optarg, &lfd) && lfd == (int)lfd)
|
||||
if (all_digits (list_optarg) && valid_number (list_optarg, &lfd) && lfd == (int)lfd)
|
||||
ofd = lfd;
|
||||
else
|
||||
{
|
||||
@@ -170,9 +169,7 @@ opt_end:
|
||||
}
|
||||
|
||||
static int
|
||||
printargs (list, ofp)
|
||||
WORD_LIST *list;
|
||||
FILE *ofp;
|
||||
printargs (WORD_LIST *list, FILE *ofp)
|
||||
{
|
||||
WORD_LIST *l;
|
||||
char *ostr;
|
||||
@@ -180,7 +177,7 @@ printargs (list, ofp)
|
||||
|
||||
for (sawc = 0, l = list; l; l = l->next)
|
||||
{
|
||||
ostr = ansicstr (l->word->word, strlen (l->word->word), 0, &sawc, (int *)0);
|
||||
ostr = ansicstr (l->word->word, strlen (l->word->word), 0, &sawc, 0);
|
||||
if (ostr)
|
||||
fprintf (ofp, "%s", ostr);
|
||||
free (ostr);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright (C) 1999-2009 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999-2009, 2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash.
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
@@ -34,8 +34,7 @@
|
||||
extern char **export_env;
|
||||
|
||||
int
|
||||
printenv_builtin (list)
|
||||
WORD_LIST *list;
|
||||
printenv_builtin (WORD_LIST *list)
|
||||
{
|
||||
register char **envp;
|
||||
int opt;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright (C) 1999-2020 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999-2020,2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash.
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
@@ -39,8 +39,7 @@ extern pid_t dollar_dollar_pid;
|
||||
extern int last_command_exit_value;
|
||||
|
||||
int
|
||||
push_builtin (list)
|
||||
WORD_LIST *list;
|
||||
push_builtin (WORD_LIST *list)
|
||||
{
|
||||
pid_t pid;
|
||||
int xstatus, opt;
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright (C) 1999-2009,2021,2022 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999-2009,2021,2022,2023 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash.
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
@@ -61,7 +61,7 @@
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
extern char *sh_realpath();
|
||||
extern char *sh_realpath(const char *, char *);
|
||||
|
||||
int
|
||||
realpath_builtin(WORD_LIST *list)
|
||||
@@ -122,7 +122,7 @@ realpath_builtin(WORD_LIST *list)
|
||||
}
|
||||
|
||||
#if defined (ARRAY_VARS)
|
||||
if (aflag && legal_identifier (aname) == 0) {
|
||||
if (aflag && valid_identifier (aname) == 0) {
|
||||
sh_invalidid(aname);
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/* See Makefile for compilation details. */
|
||||
|
||||
/*
|
||||
Copyright (C) 2016 Free Software Foundation, Inc.
|
||||
Copyright (C) 2016,2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash.
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
@@ -114,8 +114,7 @@ rm_file(const char *fname)
|
||||
}
|
||||
|
||||
int
|
||||
rm_builtin (list)
|
||||
WORD_LIST *list;
|
||||
rm_builtin (WORD_LIST *list)
|
||||
{
|
||||
const char *name;
|
||||
WORD_LIST *l;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/* See Makefile for compilation details. */
|
||||
|
||||
/*
|
||||
Copyright (C) 1999-2009 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999-2009,2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash.
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
@@ -33,8 +33,7 @@ extern int errno;
|
||||
#endif
|
||||
|
||||
int
|
||||
rmdir_builtin (list)
|
||||
WORD_LIST *list;
|
||||
rmdir_builtin (WORD_LIST *list)
|
||||
{
|
||||
int rval;
|
||||
WORD_LIST *l;
|
||||
|
||||
+10
-30
@@ -1,5 +1,5 @@
|
||||
/* seq - print sequence of numbers to standard output.
|
||||
Copyright (C) 2018-2020 Free Software Foundation, Inc.
|
||||
Copyright (C) 2018-2022 Free Software Foundation, Inc.
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@@ -35,18 +35,6 @@
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
#if defined (PRI_MACROS_BROKEN)
|
||||
# undef PRIdMAX
|
||||
#endif
|
||||
|
||||
#if !defined (PRIdMAX)
|
||||
# if HAVE_LONG_LONG
|
||||
# define PRIdMAX "lld"
|
||||
# else
|
||||
# define PRIdMAX "ld"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined (HAVE_LONG_DOUBLE) && HAVE_DECL_STRTOLD && !defined(STRTOLD_BROKEN)
|
||||
typedef long double floatmax_t;
|
||||
# define FLOATMAX_CONV "L"
|
||||
@@ -61,8 +49,8 @@ typedef double floatmax_t;
|
||||
# define FLOATMAX_FMT "%g"
|
||||
# define FLOATMAX_WFMT "%0.f"
|
||||
#endif
|
||||
static floatmax_t getfloatmax PARAMS((const char *));
|
||||
static char *genformat PARAMS((floatmax_t, floatmax_t, floatmax_t));
|
||||
static floatmax_t getfloatmax (const char *);
|
||||
static char *genformat (floatmax_t, floatmax_t, floatmax_t);
|
||||
|
||||
#define MAX(a, b) (((a) < (b))? (b) : (a))
|
||||
|
||||
@@ -81,8 +69,7 @@ static char decimal_point;
|
||||
|
||||
/* Pretty much the same as the version in builtins/printf.def */
|
||||
static floatmax_t
|
||||
getfloatmax (arg)
|
||||
const char *arg;
|
||||
getfloatmax (const char *arg)
|
||||
{
|
||||
floatmax_t ret;
|
||||
char *ep;
|
||||
@@ -181,8 +168,7 @@ long_double_format (char const *fmt)
|
||||
|
||||
/* Return the number of digits following the decimal point in NUMBUF */
|
||||
static int
|
||||
getprec (numbuf)
|
||||
const char *numbuf;
|
||||
getprec (const char *numbuf)
|
||||
{
|
||||
int p;
|
||||
char *dp;
|
||||
@@ -196,8 +182,7 @@ getprec (numbuf)
|
||||
|
||||
/* Return the default format given FIRST, INCR, and LAST. */
|
||||
static char *
|
||||
genformat (first, incr, last)
|
||||
floatmax_t first, incr, last;
|
||||
genformat (floatmax_t first, floatmax_t incr, floatmax_t last)
|
||||
{
|
||||
static char buf[6 + 2 * INT_STRLEN_BOUND (int)];
|
||||
int wfirst, wlast, width;
|
||||
@@ -242,9 +227,7 @@ genformat (first, incr, last)
|
||||
}
|
||||
|
||||
int
|
||||
print_fltseq (fmt, first, last, incr)
|
||||
const char *fmt;
|
||||
floatmax_t first, last, incr;
|
||||
print_fltseq (const char *fmt, floatmax_t first, floatmax_t last, floatmax_t incr)
|
||||
{
|
||||
int n;
|
||||
floatmax_t next;
|
||||
@@ -270,8 +253,7 @@ print_fltseq (fmt, first, last, incr)
|
||||
|
||||
/* must be <= INT_STRLEN_BOUND(intmax_t) */
|
||||
int
|
||||
width_needed (num)
|
||||
intmax_t num;
|
||||
width_needed (intmax_t num)
|
||||
{
|
||||
int ret;
|
||||
|
||||
@@ -285,8 +267,7 @@ width_needed (num)
|
||||
}
|
||||
|
||||
int
|
||||
print_intseq (ifirst, ilast, iincr)
|
||||
intmax_t ifirst, ilast, iincr;
|
||||
print_intseq (intmax_t ifirst, intmax_t ilast, intmax_t iincr)
|
||||
{
|
||||
char intwfmt[6 + INT_STRLEN_BOUND(int) + sizeof (PRIdMAX)];
|
||||
const char *s;
|
||||
@@ -323,8 +304,7 @@ print_intseq (ifirst, ilast, iincr)
|
||||
}
|
||||
|
||||
int
|
||||
seq_builtin (list)
|
||||
WORD_LIST *list;
|
||||
seq_builtin (WORD_LIST *list)
|
||||
{
|
||||
floatmax_t first, last, incr;
|
||||
intmax_t ifirst, ilast, iincr;
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
Originally contributed by Jason Vas Dias <jason.vas.dias@gmail.com>
|
||||
|
||||
Copyright (C) 2018-2023 Free Software Foundation, Inc.
|
||||
|
||||
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
|
||||
@@ -42,8 +44,7 @@
|
||||
#endif
|
||||
|
||||
int
|
||||
setpgid_builtin (list)
|
||||
WORD_LIST *list;
|
||||
setpgid_builtin (WORD_LIST *list)
|
||||
{
|
||||
register WORD_LIST *wl;
|
||||
intmax_t pid_arg, pgid_arg;
|
||||
@@ -68,7 +69,7 @@ setpgid_builtin (list)
|
||||
return (EX_USAGE);
|
||||
}
|
||||
|
||||
if (legal_number (pidstr, &pid_arg) == 0)
|
||||
if (valid_number (pidstr, &pid_arg) == 0)
|
||||
{
|
||||
builtin_error ("%s: pid argument must be numeric", pidstr);
|
||||
return (EXECUTION_FAILURE);
|
||||
@@ -80,7 +81,7 @@ setpgid_builtin (list)
|
||||
}
|
||||
pid = pid_arg;
|
||||
|
||||
if (legal_number (pgidstr, &pgid_arg) == 0)
|
||||
if (valid_number (pgidstr, &pgid_arg) == 0)
|
||||
{
|
||||
builtin_error ("%s: pgrp argument must be numeric", pgidstr);
|
||||
return (EXECUTION_FAILURE);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright (C) 1999-2021 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash.
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
@@ -135,6 +135,7 @@ sleep_builtin (WORD_LIST *list)
|
||||
if (list->word && ISOPTION (list->word->word, '-'))
|
||||
list = list->next;
|
||||
|
||||
/* Reject options and negative arguments */
|
||||
if (*list->word->word == '-' || list->next) {
|
||||
builtin_usage ();
|
||||
return (EX_USAGE);
|
||||
@@ -146,8 +147,7 @@ sleep_builtin (WORD_LIST *list)
|
||||
*
|
||||
* A heuristic: if the conversion failed, but the argument appears to
|
||||
* contain a GNU-like interval specifier (e.g. "1m30s"), try to parse
|
||||
* it. If we can't, return the right exit code to tell
|
||||
* execute_builtin to try and execute a disk command instead.
|
||||
* it. If we can't, it's an error.
|
||||
*/
|
||||
if (r == 0 && (strchr ("dhms", *ep) || strpbrk (list->word->word, "dhms")))
|
||||
r = parse_gnutimefmt (list->word->word, &sec, &usec);
|
||||
|
||||
+15
-34
@@ -3,7 +3,7 @@
|
||||
/* See Makefile for compilation details. */
|
||||
|
||||
/*
|
||||
Copyright (C) 2016,2022 Free Software Foundation, Inc.
|
||||
Copyright (C) 2016,2022-2023 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash.
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
@@ -80,17 +80,14 @@ static char *arraysubs[] =
|
||||
static char *stattime (time_t, const char *);
|
||||
|
||||
static int
|
||||
getstat (fname, flags, sp)
|
||||
const char *fname;
|
||||
int flags;
|
||||
struct stat *sp;
|
||||
getstat (const char *fname, int flags, struct stat *sp)
|
||||
{
|
||||
intmax_t lfd;
|
||||
int fd, r;
|
||||
|
||||
if (strncmp (fname, "/dev/fd/", 8) == 0)
|
||||
{
|
||||
if ((legal_number(fname + 8, &lfd) == 0) || (int)lfd != lfd)
|
||||
if ((valid_number(fname + 8, &lfd) == 0) || (int)lfd != lfd)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
@@ -109,9 +106,7 @@ getstat (fname, flags, sp)
|
||||
}
|
||||
|
||||
static char *
|
||||
statlink (fname, sp)
|
||||
char *fname;
|
||||
struct stat *sp;
|
||||
statlink (char *fname, struct stat *sp)
|
||||
{
|
||||
#if defined (HAVE_READLINK)
|
||||
char linkbuf[PATH_MAX];
|
||||
@@ -128,8 +123,7 @@ statlink (fname, sp)
|
||||
}
|
||||
|
||||
static char *
|
||||
octalperms (m)
|
||||
int m;
|
||||
octalperms (int m)
|
||||
{
|
||||
int operms;
|
||||
char *ret;
|
||||
@@ -170,8 +164,7 @@ octalperms (m)
|
||||
}
|
||||
|
||||
static char *
|
||||
statperms (m)
|
||||
int m;
|
||||
statperms (int m)
|
||||
{
|
||||
char ubits[4], gbits[4], obits[4]; /* u=rwx,g=rwx,o=rwx */
|
||||
int i;
|
||||
@@ -217,8 +210,7 @@ statperms (m)
|
||||
}
|
||||
|
||||
static char *
|
||||
statmode(mode)
|
||||
int mode;
|
||||
statmode(int mode)
|
||||
{
|
||||
char *modestr, *m;
|
||||
|
||||
@@ -260,9 +252,7 @@ statmode(mode)
|
||||
}
|
||||
|
||||
static char *
|
||||
stattime (t, timefmt)
|
||||
time_t t;
|
||||
const char *timefmt;
|
||||
stattime (time_t t, const char *timefmt)
|
||||
{
|
||||
char *tbuf, *ret;
|
||||
const char *fmt;
|
||||
@@ -271,6 +261,8 @@ stattime (t, timefmt)
|
||||
|
||||
fmt = timefmt ? timefmt : DEFTIMEFMT;
|
||||
tm = localtime (&t);
|
||||
if (tm == 0)
|
||||
return (itos (t));
|
||||
|
||||
ret = xmalloc (TIMELEN_MAX);
|
||||
|
||||
@@ -282,12 +274,7 @@ stattime (t, timefmt)
|
||||
}
|
||||
|
||||
static char *
|
||||
statval (which, fname, flags, fmt, sp)
|
||||
int which;
|
||||
char *fname;
|
||||
int flags;
|
||||
char *fmt;
|
||||
struct stat *sp;
|
||||
statval (int which, char *fname, int flags, char *fmt, struct stat *sp)
|
||||
{
|
||||
int temp;
|
||||
|
||||
@@ -332,13 +319,7 @@ statval (which, fname, flags, fmt, sp)
|
||||
}
|
||||
|
||||
static int
|
||||
loadstat (vname, var, fname, flags, fmt, sp)
|
||||
char *vname;
|
||||
SHELL_VAR *var;
|
||||
char *fname;
|
||||
int flags;
|
||||
char *fmt;
|
||||
struct stat *sp;
|
||||
loadstat (char *vname, SHELL_VAR *var, char *fname, int flags, char *fmt, struct stat *sp)
|
||||
{
|
||||
int i;
|
||||
char *key, *value;
|
||||
@@ -349,13 +330,13 @@ loadstat (vname, var, fname, flags, fmt, sp)
|
||||
key = savestring (arraysubs[i]);
|
||||
value = statval (i, fname, flags, fmt, sp);
|
||||
v = bind_assoc_variable (var, vname, key, value, ASS_FORCE);
|
||||
free (value);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
stat_builtin (list)
|
||||
WORD_LIST *list;
|
||||
stat_builtin (WORD_LIST *list)
|
||||
{
|
||||
int opt, flags;
|
||||
char *aname, *fname, *timefmt;
|
||||
@@ -390,7 +371,7 @@ stat_builtin (list)
|
||||
}
|
||||
}
|
||||
|
||||
if (legal_identifier (aname) == 0)
|
||||
if (valid_identifier (aname) == 0)
|
||||
{
|
||||
sh_invalidid (aname);
|
||||
return (EXECUTION_FAILURE);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/* See Makefile for compilation details. */
|
||||
|
||||
/*
|
||||
Copyright (C) 1999-2009 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999-2009,2022-2023 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash.
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
@@ -37,8 +37,7 @@
|
||||
#include "bashgetopt.h"
|
||||
|
||||
int
|
||||
strftime_builtin (list)
|
||||
WORD_LIST *list;
|
||||
strftime_builtin (WORD_LIST *list)
|
||||
{
|
||||
char *format, *tbuf;
|
||||
size_t tbsize, tsize;
|
||||
@@ -68,7 +67,7 @@ strftime_builtin (list)
|
||||
|
||||
if (list && list->word->word)
|
||||
{
|
||||
n = legal_number (list->word->word, &i);
|
||||
n = valid_number (list->word->word, &i);
|
||||
if (n == 0 || i < 0 || i != (time_t)i)
|
||||
{
|
||||
sh_invalidnum (list->word->word);
|
||||
@@ -81,6 +80,12 @@ strftime_builtin (list)
|
||||
secs = NOW;
|
||||
|
||||
t = localtime (&secs);
|
||||
if (t == 0)
|
||||
{
|
||||
builtin_error ("%s: timestamp out of range", list && list->word->word ? list->word->word : "now");
|
||||
return (EXECUTION_FAILURE);
|
||||
}
|
||||
|
||||
|
||||
tbsize = strlen (format) * 4;
|
||||
tbuf = 0;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* sync - sync the disks by forcing pending filesystem writes to complete */
|
||||
|
||||
/*
|
||||
Copyright (C) 1999-2009 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999-2009,2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash.
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
@@ -23,23 +23,69 @@
|
||||
#ifdef HAVE_UNISTD_H
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "builtins.h"
|
||||
#include "shell.h"
|
||||
#include "common.h"
|
||||
#include "bashgetopt.h"
|
||||
|
||||
#ifndef errno
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
int
|
||||
sync_builtin (list)
|
||||
WORD_LIST *list;
|
||||
sync_builtin (WORD_LIST *list)
|
||||
{
|
||||
sync();
|
||||
return (EXECUTION_SUCCESS);
|
||||
int fd, status;
|
||||
WORD_LIST *l;
|
||||
char *fn;
|
||||
|
||||
if (no_options (list))
|
||||
return (EX_USAGE);
|
||||
list = loptend;
|
||||
|
||||
if (list == 0)
|
||||
{
|
||||
sync();
|
||||
return (EXECUTION_SUCCESS);
|
||||
}
|
||||
|
||||
status = EXECUTION_SUCCESS;
|
||||
for (l = list; l; l = l->next)
|
||||
{
|
||||
fn = l->word->word;
|
||||
fd = open (fn, O_WRONLY);
|
||||
if (fd < 0)
|
||||
fd = open (fn, O_RDONLY);
|
||||
|
||||
if (fd < 0)
|
||||
{
|
||||
file_error (fn);
|
||||
status = EXECUTION_FAILURE;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (fsync (fd) < 0)
|
||||
{
|
||||
builtin_error ("%s: cannot sync: %s", fn, strerror (errno));
|
||||
status = EXECUTION_FAILURE;
|
||||
}
|
||||
close (fd);
|
||||
}
|
||||
|
||||
return (status);
|
||||
}
|
||||
|
||||
char *sync_doc[] = {
|
||||
"Sync disks.",
|
||||
""
|
||||
"Force completion of pending disk writes",
|
||||
"Sync disks or specified files.",
|
||||
"",
|
||||
"If one or more FILEs is supplied, force completion of pending writes",
|
||||
"to those files. Otherwise, force completion of any pending disk",
|
||||
"writes.",
|
||||
"",
|
||||
"Exit Status: zero unless any FILE could not be synced.",
|
||||
(char *)NULL
|
||||
};
|
||||
|
||||
@@ -48,6 +94,6 @@ struct builtin sync_struct = {
|
||||
sync_builtin, /* function implementing the builtin */
|
||||
BUILTIN_ENABLED, /* initial flags for builtin */
|
||||
sync_doc, /* array of long documentation strings. */
|
||||
"sync", /* usage synopsis; becomes short_doc */
|
||||
"sync [file ...]", /* usage synopsis; becomes short_doc */
|
||||
0 /* reserved for internal use */
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/* See Makefile for compilation details. */
|
||||
|
||||
/*
|
||||
Copyright (C) 1999-2021 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash.
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
@@ -58,11 +58,10 @@ static FLIST *tee_flist;
|
||||
|
||||
extern int interrupt_immediately;
|
||||
|
||||
extern char *strerror ();
|
||||
extern char *strerror (int);
|
||||
|
||||
int
|
||||
tee_builtin (list)
|
||||
WORD_LIST *list;
|
||||
tee_builtin (WORD_LIST *list)
|
||||
{
|
||||
int opt, append, nointr, rval, fd, fflags;
|
||||
int n, nr, nw;
|
||||
|
||||
@@ -17,11 +17,10 @@
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
extern char *strerror ();
|
||||
extern char *strerror (int);
|
||||
|
||||
int
|
||||
template_builtin (list)
|
||||
WORD_LIST *list;
|
||||
template_builtin (WORD_LIST *list)
|
||||
{
|
||||
int opt, rval;
|
||||
|
||||
@@ -45,16 +44,14 @@ template_builtin (list)
|
||||
/* Called when `template' is enabled and loaded from the shared object. If this
|
||||
function returns 0, the load fails. */
|
||||
int
|
||||
template_builtin_load (name)
|
||||
char *name;
|
||||
template_builtin_load (char *name)
|
||||
{
|
||||
return (1);
|
||||
}
|
||||
|
||||
/* Called when `template' is disabled. */
|
||||
void
|
||||
template_builtin_unload (name)
|
||||
char *name;
|
||||
template_builtin_unload (char *name)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* true and false builtins */
|
||||
|
||||
/*
|
||||
Copyright (C) 1999-2009 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999-2009,2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash.
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
@@ -26,15 +26,13 @@
|
||||
#include "common.h"
|
||||
|
||||
int
|
||||
true_builtin (list)
|
||||
WORD_LIST *list;
|
||||
true_builtin (WORD_LIST *list)
|
||||
{
|
||||
return EXECUTION_SUCCESS;
|
||||
}
|
||||
|
||||
int
|
||||
false_builtin (list)
|
||||
WORD_LIST *list;
|
||||
false_builtin (WORD_LIST *list)
|
||||
{
|
||||
return EXECUTION_FAILURE;
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/* See Makefile for compilation details. */
|
||||
|
||||
/*
|
||||
Copyright (C) 1999-2021 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999-2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash.
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
@@ -28,11 +28,10 @@
|
||||
#include "bashgetopt.h"
|
||||
#include "common.h"
|
||||
|
||||
extern char *ttyname ();
|
||||
extern char *ttyname (int);
|
||||
|
||||
int
|
||||
tty_builtin (list)
|
||||
WORD_LIST *list;
|
||||
tty_builtin (WORD_LIST *list)
|
||||
{
|
||||
int opt, sflag;
|
||||
char *t;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright (C) 1999-2009 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999-2009,2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash.
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
@@ -59,13 +59,12 @@ struct utsname {
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
static void uprint();
|
||||
static void uprint(int, char *);
|
||||
|
||||
static int uname_flags;
|
||||
|
||||
int
|
||||
uname_builtin (list)
|
||||
WORD_LIST *list;
|
||||
uname_builtin (WORD_LIST *list)
|
||||
{
|
||||
int opt, r;
|
||||
struct utsname uninfo;
|
||||
@@ -134,9 +133,7 @@ uname_builtin (list)
|
||||
}
|
||||
|
||||
static void
|
||||
uprint (flag, info)
|
||||
int flag;
|
||||
char *info;
|
||||
uprint (int flag, char *info)
|
||||
{
|
||||
if (uname_flags & flag)
|
||||
{
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
fsck clean up the file system. */
|
||||
|
||||
/*
|
||||
Copyright (C) 1999-2009 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999-2009,2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash.
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
@@ -39,8 +39,7 @@ extern int errno;
|
||||
#endif
|
||||
|
||||
int
|
||||
unlink_builtin (list)
|
||||
WORD_LIST *list;
|
||||
unlink_builtin (WORD_LIST *list)
|
||||
{
|
||||
if (list == 0)
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
Copyright (C) 1999-2009 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999-2009,2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Bash.
|
||||
Bash is free software: you can redistribute it and/or modify
|
||||
@@ -29,8 +29,7 @@
|
||||
#include "common.h"
|
||||
|
||||
int
|
||||
whoami_builtin (list)
|
||||
WORD_LIST *list;
|
||||
whoami_builtin (WORD_LIST *list)
|
||||
{
|
||||
int opt;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user