final set of ANSI C changes

This commit is contained in:
Chet Ramey
2023-01-05 15:09:06 -05:00
parent 5b512e1121
commit 2e725f7346
84 changed files with 390 additions and 347 deletions
+3 -2
View File
@@ -1,7 +1,7 @@
/* getenv.c - get environment variable value from the shell's variable
list. */
/* Copyright (C) 1997-2002 Free Software Foundation, Inc.
/* Copyright (C) 1997-2002,2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -70,7 +70,8 @@ getenv (const char *name)
}
else if (environ)
{
register int i, len;
int i;
size_t len;
/* In some cases, s5r3 invokes getenv() before main(); BSD systems
using gprof also exhibit this behavior. This means that
+2 -2
View File
@@ -1,6 +1,6 @@
/* makepath.c - glue PATH and DIR together into a full pathname. */
/* Copyright (C) 1987-2020,2022 Free Software Foundation, Inc.
/* Copyright (C) 1987-2020,2022-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -69,7 +69,7 @@ static char *nullpath = "";
char *
sh_makepath (const char *path, const char *dir, int flags)
{
int dirlen, pathlen;
size_t dirlen, pathlen;
char *ret, *xpath, *xdir, *r, *s;
if (path == 0 || *path == '\0')
+5 -3
View File
@@ -1,6 +1,6 @@
/* mbscasecmp - case-insensitive multibyte string comparison. */
/* Copyright (C) 2009-2022 Free Software Foundation, Inc.
/* Copyright (C) 2009-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -33,8 +33,10 @@
int
mbscasecmp (const char *mbs1, const char *mbs2)
{
int len1, len2, mb_cur_max;
wchar_t c1, c2, l1, l2;
size_t len1, len2;
int mb_cur_max;
wchar_t c1, c2;
wint_t l1, l2;
mbstate_t state1 = { 0 }, state2 = { 0 };
len1 = len2 = 0;
+3 -3
View File
@@ -56,7 +56,7 @@ extern int errno;
char *
strchr (const char *string, int c)
{
register char *s;
char *s;
for (s = string; s && *s; s++)
if (*s == c)
@@ -68,9 +68,9 @@ strchr (const char *string, int c)
char *
strrchr (const char *string, int c)
{
register char *s, *t;
char *s, *t;
for (s = string, t = (char *)NULL; s && *s; s++)
for (s = string, t = NULL; s && *s; s++)
if (*s == c)
t = s;
return (t);
+4 -3
View File
@@ -1,6 +1,6 @@
/* pathphys.c -- return pathname with all symlinks expanded. */
/* Copyright (C) 2000-2020,2022 Free Software Foundation, Inc.
/* Copyright (C) 2000-2020,2022-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -49,7 +49,7 @@ extern int errno;
extern char *get_working_directory (char *);
static inline int
_path_readlink (char *path, char *buf, int bufsiz)
_path_readlink (char *path, char *buf, size_t bufsiz)
{
#ifdef HAVE_READLINK
return readlink (path, buf, bufsiz);
@@ -73,7 +73,8 @@ sh_physpath (char *path, int flags)
{
char tbuf[PATH_MAX+1], linkbuf[PATH_MAX+1];
char *result, *p, *q, *qsave, *qbase, *workpath;
int double_slash_path, linklen, nlink;
int double_slash_path, nlink;
size_t linklen;
linklen = strlen (path);
+6 -5
View File
@@ -94,7 +94,7 @@ static const char bstab[256] =
char *
sh_single_quote (const char *string)
{
register int c;
int c;
char *result, *r;
const char *s;
@@ -133,7 +133,7 @@ sh_single_quote (const char *string)
char *
sh_double_quote (const char *string)
{
register unsigned char c;
unsigned char c;
int mb_cur_max;
char *result, *r;
size_t slen;
@@ -178,11 +178,12 @@ sh_double_quote (const char *string)
/* Turn S into a simple double-quoted string. If FLAGS is non-zero, quote
double quote characters in S with backslashes. */
char *
sh_mkdoublequoted (const char *s, int slen, int flags)
sh_mkdoublequoted (const char *s, size_t slen, int flags)
{
char *r, *ret;
const char *send;
int rlen, mb_cur_max;
int mb_cur_max;
size_t rlen;
DECLARE_MBSTATE;
send = s + slen;
@@ -218,7 +219,7 @@ sh_mkdoublequoted (const char *s, int slen, int flags)
char *
sh_un_double_quote (char *string)
{
register int c, pass_next;
int c, pass_next;
char *result, *r, *s;
r = result = (char *)xmalloc (strlen (string) + 1);
+1 -1
View File
@@ -1135,7 +1135,7 @@ static char *
groupnum (char *s)
{
char *se, *ret, *re, *g;
int len, slen;
size_t len, slen;
if (grouping == 0 || *grouping <= 0 || *grouping == CHAR_MAX)
return ((char *)NULL);
+2 -2
View File
@@ -1,6 +1,6 @@
/* spell.c -- spelling correction for pathnames. */
/* Copyright (C) 2000-2022 Free Software Foundation, Inc.
/* Copyright (C) 2000-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -184,7 +184,7 @@ spdist(char *cur, char *new)
char *
dirspell (char *dirname)
{
int n;
size_t n;
char *guess;
n = (strlen (dirname) * 3 + 1) / 2 + 1;
+8 -8
View File
@@ -40,7 +40,7 @@ STRINGLIST *
strlist_create (size_t n)
{
STRINGLIST *ret;
register int i;
int i;
ret = (STRINGLIST *)xmalloc (sizeof (STRINGLIST));
if (n)
@@ -62,7 +62,7 @@ strlist_create (size_t n)
STRINGLIST *
strlist_resize (STRINGLIST *sl, size_t n)
{
register int i;
size_t i;
if (sl == 0)
return (sl = strlist_create (n));
@@ -114,7 +114,7 @@ STRINGLIST *
strlist_copy (STRINGLIST *sl)
{
STRINGLIST *new;
register int i;
int i;
if (sl == 0)
return ((STRINGLIST *)0);
@@ -139,7 +139,7 @@ STRINGLIST *
strlist_merge (STRINGLIST *m1, STRINGLIST *m2)
{
STRINGLIST *sl;
int i, n, l1, l2;
size_t i, n, l1, l2;
l1 = m1 ? m1->list_len : 0;
l2 = m2 ? m2->list_len : 0;
@@ -158,7 +158,7 @@ strlist_merge (STRINGLIST *m1, STRINGLIST *m2)
STRINGLIST *
strlist_append (STRINGLIST *m1, STRINGLIST *m2)
{
register int i, n, len1, len2;
size_t i, n, len1, len2;
if (m1 == 0)
return (m2 ? strlist_copy (m2) : (STRINGLIST *)0);
@@ -181,7 +181,7 @@ strlist_append (STRINGLIST *m1, STRINGLIST *m2)
STRINGLIST *
strlist_prefix_suffix (STRINGLIST *sl, const char *prefix, const char *suffix)
{
int plen, slen, tlen, llen, i;
size_t plen, slen, tlen, llen, i;
char *t;
if (sl == 0 || sl->list == 0 || sl->list_len == 0)
@@ -213,7 +213,7 @@ strlist_prefix_suffix (STRINGLIST *sl, const char *prefix, const char *suffix)
void
strlist_print (STRINGLIST *sl, const char *prefix)
{
register int i;
int i;
if (sl == 0)
return;
@@ -224,7 +224,7 @@ strlist_print (STRINGLIST *sl, const char *prefix)
void
strlist_walk (STRINGLIST *sl, sh_strlist_map_func_t *func)
{
register int i;
int i;
if (sl == 0)
return;
+12 -9
View File
@@ -1,6 +1,6 @@
/* strtrans.c - Translate and untranslate strings with ANSI-C escape sequences. */
/* Copyright (C) 2000-2015,2022 Free Software Foundation, Inc.
/* Copyright (C) 2000-2015,2022-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -51,16 +51,17 @@ char *
ansicstr (const char *string, int len, int flags, int *sawc, int *rlen)
{
int c, temp;
char *ret, *r, *s;
char *ret, *r;
const char *s;
unsigned long v;
size_t clen;
int b, mb_cur_max;
int mb_cur_max;
#if defined (HANDLE_MULTIBYTE)
wchar_t wc;
#endif
if (string == 0 || *string == '\0')
return ((char *)NULL);
return ((char *)0);
mb_cur_max = MB_CUR_MAX;
#if defined (HANDLE_MULTIBYTE)
@@ -71,7 +72,7 @@ ansicstr (const char *string, int len, int flags, int *sawc, int *rlen)
#else
ret = (char *)xmalloc (2*len + 1); /* 2*len for possible CTLESC */
#endif
for (r = ret, s = (char *)string; s && *s; )
for (r = ret, s = string; s && *s; )
{
c = *s++;
if (c != '\\' || *s == '\0')
@@ -227,8 +228,9 @@ ansicstr (const char *string, int len, int flags, int *sawc, int *rlen)
char *
ansic_quote (const char *str, int flags, int *rlen)
{
char *r, *ret, *s;
int l, rsize;
char *r, *ret;
const char *s;
size_t l, rsize;
unsigned char c;
size_t clen;
int b;
@@ -246,9 +248,10 @@ ansic_quote (const char *str, int flags, int *rlen)
*r++ = '$';
*r++ = '\'';
for (s = (char *)str; c = *s; s++)
for (s = str; c = *s; s++)
{
b = l = 1; /* 1 == add backslash; 0 == no backslash */
b = 1; /* 1 == add backslash; 0 == no backslash */
l = 1;
clen = 1;
switch (c)
+4 -3
View File
@@ -2,7 +2,7 @@
* tmpfile.c - functions to create and safely open temp files for the shell.
*/
/* Copyright (C) 2000-2020,2022 Free Software Foundation, Inc.
/* Copyright (C) 2000-2020,2022-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -278,11 +278,12 @@ sh_mktmpfp (const char *nameroot, int flags, char **namep)
char *
sh_mktmpdir (const char *nameroot, int flags)
{
char *filename, *tdir, *dirname;
char *filename;
#ifdef USE_MKDTEMP
char *tdir, *dirname;
const char *lroot;
int fd, tdlen;
#ifdef USE_MKDTEMP
filename = (char *)xmalloc (PATH_MAX + 1);
tdir = get_tmpdir (flags);
tdlen = strlen (tdir);
+2 -1
View File
@@ -87,10 +87,11 @@ int
fsleep(unsigned int sec, unsigned int usec)
{
int e, r;
sigset_t blocked_sigs, prevmask;
sigset_t blocked_sigs;
#if defined (HAVE_PSELECT)
struct timespec ts;
#else
sigset_t prevmask;
struct timeval tv;
#endif
+2 -2
View File
@@ -48,7 +48,7 @@ utf8_mbscmp (const char *s1, const char *s2)
char *
utf8_mbsmbchar (const char *str)
{
register char *s;
char *s;
for (s = (char *)str; *s; s++)
if ((*s & 0xc0) == 0x80)
@@ -59,7 +59,7 @@ utf8_mbsmbchar (const char *str)
int
utf8_mbsnlen(const char *src, size_t srclen, int maxlen)
{
register int sind, count;
int sind, count;
for (sind = count = 0; src[sind] && sind <= maxlen; sind++)
{
+3 -3
View File
@@ -1,7 +1,7 @@
/* zgetline - read a line of input from a specified file descriptor and return
a pointer to a newly-allocated buffer containing the data. */
/* Copyright (C) 2008-2020,2022 Free Software Foundation, Inc.
/* Copyright (C) 2008-2020,2022-2023 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -63,8 +63,8 @@ typedef ssize_t creadfunc_t (int, char *);
ssize_t
zgetline (int fd, char **lineptr, size_t *n, int delim, int unbuffered_read)
{
int retval;
size_t nr;
ssize_t retval;
ssize_t nr;
char *line, c;
if (lineptr == 0 || n == 0 || (*lineptr == 0 && *n != 0))
+1 -1
View File
@@ -45,7 +45,7 @@ extern ssize_t zread (int, char *, size_t);
/* Dump contents of file descriptor FD to *OSTR. FN is the filename for
error messages (not used right now). */
int
zmapfd (int fd, char **ostr, char *fn)
zmapfd (int fd, char **ostr, const char *fn)
{
ssize_t nr;
int rval;