third set of ANSI C changes: const function parameters

This commit is contained in:
Chet Ramey
2023-01-03 11:59:43 -05:00
parent a61ffa78ed
commit b2613ad1c0
43 changed files with 477 additions and 445 deletions
+1 -1
View File
@@ -73,7 +73,7 @@ extern int errno;
the inode corresponding to PATH/DIR is identical to THISINO. */
#if !defined (D_FILENO_AVAILABLE)
static int
_path_checkino (char *dotp, char *name, ino_t thisino)
_path_checkino (const char *dotp, const char *name, ino_t thisino)
{
char *fullpath;
int r, e;
+2 -2
View File
@@ -94,7 +94,7 @@ static char rcsid[] = "$Id: inet_addr.c,v 1.5 1996/08/14 03:48:37 drepper Exp $"
* The value returned is in network order.
*/
u_long
inet_addr(register const char *cp)
inet_addr(const char *cp)
{
struct in_addr val;
@@ -112,7 +112,7 @@ inet_addr(register const char *cp)
* cannot distinguish between failure and a local broadcast address.
*/
int
inet_aton(register const char *cp, struct in_addr *addr)
inet_aton(const char *cp, struct in_addr *addr)
{
register u_bits32_t val;
register int base, n;
+10 -10
View File
@@ -67,21 +67,21 @@ extern int inet_aton (const char *, struct in_addr *);
#endif
#ifndef HAVE_GETADDRINFO
static int _getaddr (char *, struct in_addr *);
static int _getserv (char *, int, unsigned short *);
static int _netopen4 (char *, char *, int);
static int _getaddr (const char *, struct in_addr *);
static int _getserv (const char *, int, unsigned short *);
static int _netopen4 (const char *, const char *, int);
#else /* HAVE_GETADDRINFO */
static int _netopen6 (char *, char *, int);
static int _netopen6 (const char *, const char *, int);
#endif
static int _netopen (char *, char *, int);
static int _netopen (const char *, const char *, int);
#ifndef HAVE_GETADDRINFO
/* Stuff the internet address corresponding to HOST into AP, in network
byte order. Return 1 on success, 0 on failure. */
static int
_getaddr (char *host, struct in_addr *ap)
_getaddr (const char *host, struct in_addr *ap)
{
struct hostent *h;
int r;
@@ -112,7 +112,7 @@ _getaddr (char *host, struct in_addr *ap)
/* Return 1 if SERV is a valid port number and stuff the converted value into
PP in network byte order. */
static int
_getserv (char *serv, int proto, unsigned short *pp)
_getserv (const char *serv, int proto, unsigned short *pp)
{
intmax_t l;
unsigned short s;
@@ -149,7 +149,7 @@ _getserv (char *serv, int proto, unsigned short *pp)
* traditional BSD mechanisms. Returns the connected socket or -1 on error.
*/
static int
_netopen4(char *host, char *serv, int typ)
_netopen4(const char *host, const char *serv, int typ)
{
struct in_addr ina;
struct sockaddr_in sin;
@@ -202,7 +202,7 @@ _netopen4(char *host, char *serv, int typ)
* on error.
*/
static int
_netopen6 (char *host, char *serv, int typ)
_netopen6 (const char *host, const char *serv, int typ)
{
int s, e;
struct addrinfo hints, *res, *res0;
@@ -265,7 +265,7 @@ _netopen6 (char *host, char *serv, int typ)
* Returns the connected socket or -1 on error.
*/
static int
_netopen(char *host, char *serv, int typ)
_netopen(const char *host, const char *serv, int typ)
{
#ifdef HAVE_GETADDRINFO
return (_netopen6 (host, serv, typ));
+2 -2
View File
@@ -40,7 +40,7 @@
#include <maxpath.h>
#include <stdc.h>
static int mindist (char *, char *, char *);
static int mindist (const char *, char *, char *);
static int spdist (char *, char *);
/*
@@ -102,7 +102,7 @@ spname(char *oldname, char *newname)
* Search directory for a guess
*/
static int
mindist(char *dir, char *guess, char *best)
mindist(const char *dir, char *guess, char *best)
{
DIR *fd;
struct dirent *dp;
+3 -3
View File
@@ -97,7 +97,7 @@ strlist_dispose (STRINGLIST *sl)
}
int
strlist_remove (STRINGLIST *sl, char *s)
strlist_remove (STRINGLIST *sl, const char *s)
{
int r;
@@ -179,7 +179,7 @@ strlist_append (STRINGLIST *m1, STRINGLIST *m2)
}
STRINGLIST *
strlist_prefix_suffix (STRINGLIST *sl, char *prefix, char *suffix)
strlist_prefix_suffix (STRINGLIST *sl, const char *prefix, const char *suffix)
{
int plen, slen, tlen, llen, i;
char *t;
@@ -211,7 +211,7 @@ strlist_prefix_suffix (STRINGLIST *sl, char *prefix, char *suffix)
}
void
strlist_print (STRINGLIST *sl, char *prefix)
strlist_print (STRINGLIST *sl, const char *prefix)
{
register int i;
+4 -4
View File
@@ -60,7 +60,7 @@ strvec_mresize (char **array, int nsize)
/* Return the length of ARRAY, a NULL terminated array of char *. */
int
strvec_len (char **array)
strvec_len (char * const *array)
{
register int i;
@@ -92,7 +92,7 @@ strvec_dispose (char **array)
}
int
strvec_remove (char **array, char *name)
strvec_remove (char **array, const char *name)
{
register int i, j;
char *x;
@@ -115,7 +115,7 @@ strvec_remove (char **array, char *name)
/* Find NAME in ARRAY. Return the index of NAME, or -1 if not present.
ARRAY should be NULL terminated. */
int
strvec_search (char **array, char *name)
strvec_search (char **array, const char *name)
{
int i;
@@ -128,7 +128,7 @@ strvec_search (char **array, char *name)
/* Allocate and return a new copy of ARRAY and its contents. */
char **
strvec_copy (char **array)
strvec_copy (char * const *array)
{
register int i;
int len;
+1 -1
View File
@@ -35,7 +35,7 @@
/* Find the length of S, but scan at most MAXLEN characters. If no '\0'
terminator is found within the first MAXLEN characters, return MAXLEN. */
size_t
strnlen (register const char *s, size_t maxlen)
strnlen (const char *s, size_t maxlen)
{
register const char *e;
size_t n;
+5 -5
View File
@@ -48,7 +48,7 @@
quote CTLESC and CTLNUL with CTLESC. If (flags&4) is non-zero, we want
to remove the backslash before any unrecognized escape sequence. */
char *
ansicstr (char *string, int len, int flags, int *sawc, int *rlen)
ansicstr (const char *string, int len, int flags, int *sawc, int *rlen)
{
int c, temp;
char *ret, *r, *s;
@@ -71,7 +71,7 @@ ansicstr (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 = string; s && *s; )
for (r = ret, s = (char *)string; s && *s; )
{
c = *s++;
if (c != '\\' || *s == '\0')
@@ -225,7 +225,7 @@ ansicstr (char *string, int len, int flags, int *sawc, int *rlen)
/* Take a string STR, possibly containing non-printing characters, and turn it
into a $'...' ANSI-C style quoted string. Returns a new string. */
char *
ansic_quote (char *str, int flags, int *rlen)
ansic_quote (const char *str, int flags, int *rlen)
{
char *r, *ret, *s;
int l, rsize;
@@ -246,7 +246,7 @@ ansic_quote (char *str, int flags, int *rlen)
*r++ = '$';
*r++ = '\'';
for (s = str; c = *s; s++)
for (s = (char *)str; c = *s; s++)
{
b = l = 1; /* 1 == add backslash; 0 == no backslash */
clen = 1;
@@ -367,7 +367,7 @@ ansic_shouldquote (const char *string)
/* $'...' ANSI-C expand the portion of STRING between START and END and
return the result. The result cannot be longer than the input string. */
char *
ansiexpand (char *string, int start, int end, int *lenp)
ansiexpand (const char *string, int start, int end, int *lenp)
{
char *temp, *t;
int len, tlen;
+10 -7
View File
@@ -135,9 +135,10 @@ sh_seedrand (void)
}
char *
sh_mktmpname (char *nameroot, int flags)
sh_mktmpname (const char *nameroot, int flags)
{
char *filename, *tdir, *lroot;
char *filename, *tdir;
const char *lroot;
struct stat sb;
int r, tdlen;
static int seeded = 0;
@@ -196,9 +197,10 @@ sh_mktmpname (char *nameroot, int flags)
}
int
sh_mktmpfd (char *nameroot, int flags, char **namep)
sh_mktmpfd (const char *nameroot, int flags, char **namep)
{
char *filename, *tdir, *lroot;
char *filename, *tdir;
const char *lroot;
int fd, tdlen;
filename = (char *)xmalloc (PATH_MAX + 1);
@@ -259,7 +261,7 @@ sh_mktmpfd (char *nameroot, int flags, char **namep)
}
FILE *
sh_mktmpfp (char *nameroot, int flags, char **namep)
sh_mktmpfp (const char *nameroot, int flags, char **namep)
{
int fd;
FILE *fp;
@@ -274,9 +276,10 @@ sh_mktmpfp (char *nameroot, int flags, char **namep)
}
char *
sh_mktmpdir (char *nameroot, int flags)
sh_mktmpdir (const char *nameroot, int flags)
{
char *filename, *tdir, *lroot, *dirname;
char *filename, *tdir, *dirname;
const char *lroot;
int fd, tdlen;
#ifdef USE_MKDTEMP
+3 -3
View File
@@ -57,7 +57,7 @@ static int multiplier[7] = { 1, 100000, 10000, 1000, 100, 10, 1 };
Return 1 if value converted; 0 if invalid integer for either whole or
fractional parts. */
int
uconvert(char *s, long *ip, long *up, char **ep)
uconvert(const char *s, long *ip, long *up, char **ep)
{
int n, mult;
long ipart, upart;
@@ -69,10 +69,10 @@ uconvert(char *s, long *ip, long *up, char **ep)
if (s && (*s == '-' || *s == '+'))
{
mult = (*s == '-') ? -1 : 1;
p = s + 1;
p = (char *)s + 1;
}
else
p = s;
p = (char *)s;
for ( ; p && *p; p++)
{
+1 -1
View File
@@ -44,7 +44,7 @@ extern int zwrite (int, char *, ssize_t);
/* Dump contents of file descriptor FD to OFD. FN is the filename for
error messages (not used right now). */
int
zcatfd (int fd, int ofd, char *fn)
zcatfd (int fd, int ofd, const char *fn)
{
ssize_t nr;
int rval;