From 97d82cb4b15f18701d239609308aa41c3b89d75c Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Thu, 25 Jun 2020 12:11:56 +0000 Subject: Clean-up compat functions, not using "register" any more, and fix some signatures (constify) matching nowadays standards. All backported from core-8-branch with modifications. --- compat/fixstrtod.c | 2 +- compat/gettod.c | 5 +++-- compat/memcmp.c | 10 +++++----- compat/opendir.c | 22 +++++++++++----------- compat/strncasecmp.c | 16 ++++++++-------- compat/strstr.c | 12 ++++++------ compat/strtod.c | 14 +++++++------- compat/strtol.c | 7 +++---- compat/strtoul.c | 16 ++++++++-------- compat/waitpid.c | 4 ++-- 10 files changed, 54 insertions(+), 54 deletions(-) diff --git a/compat/fixstrtod.c b/compat/fixstrtod.c index 91f309e..63fb8ef 100644 --- a/compat/fixstrtod.c +++ b/compat/fixstrtod.c @@ -1,4 +1,4 @@ -/* +/* * fixstrtod.c -- * * Source code for the "fixstrtod" procedure. This procedure is diff --git a/compat/gettod.c b/compat/gettod.c index 28e1432..f6651d4 100644 --- a/compat/gettod.c +++ b/compat/gettod.c @@ -1,4 +1,4 @@ -/* +/* * gettod.c -- * * This file provides the gettimeofday function on systems @@ -21,10 +21,11 @@ gettimeofday( struct timezone *tz) { struct timeb t; + (void)tz; ftime(&t); tp->tv_sec = t.time; - tp->tv_usec = t. millitm * 1000; + tp->tv_usec = t.millitm * 1000; return 0; } diff --git a/compat/memcmp.c b/compat/memcmp.c index 5fce528..c4e25a8 100644 --- a/compat/memcmp.c +++ b/compat/memcmp.c @@ -15,7 +15,7 @@ * Here is the prototype just in case it is not included in tclPort.h. */ -int memcmp(CONST VOID *s1, CONST VOID *s2, size_t n); +int memcmp(const void *s1, const void *s2, size_t n); /* *---------------------------------------------------------------------- @@ -38,12 +38,12 @@ int memcmp(CONST VOID *s1, CONST VOID *s2, size_t n); int memcmp( - CONST VOID *s1, /* First string. */ - CONST VOID *s2, /* Second string. */ + const void *s1, /* First string. */ + const void *s2, /* Second string. */ size_t n) /* Length to compare. */ { - CONST unsigned char *ptr1 = (CONST unsigned char *) s1; - CONST unsigned char *ptr2 = (CONST unsigned char *) s2; + const unsigned char *ptr1 = (const unsigned char *) s1; + const unsigned char *ptr2 = (const unsigned char *) s2; for ( ; n-- ; ptr1++, ptr2++) { unsigned char u1 = *ptr1, u2 = *ptr2; diff --git a/compat/opendir.c b/compat/opendir.c index 3fe70c1..25a7ada 100644 --- a/compat/opendir.c +++ b/compat/opendir.c @@ -1,4 +1,4 @@ -/* +/* * opendir.c -- * * This file provides dirent-style directory-reading procedures for V7 @@ -10,7 +10,7 @@ #undef DIRSIZ #define DIRSIZ(dp) \ - ((sizeof (struct dirent) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3)) + ((sizeof(struct dirent) - (MAXNAMLEN+1)) + (((dp)->d_namlen+1 + 3) &~ 3)) /* * open a directory. @@ -20,9 +20,9 @@ DIR * opendir( char *name) { - register DIR *dirp; - register int fd; - char *myname; + DIR *dirp; + int fd; + const char *myname; myname = ((*name == '\0') ? "." : name); if ((fd = open(myname, 0, 0)) == -1) { @@ -45,14 +45,14 @@ opendir( #ifndef pyr #define ODIRSIZ 14 -struct olddirect { +struct olddirect { ino_t od_ino; char od_name[ODIRSIZ]; }; #else /* a Pyramid in the ATT universe */ #define ODIRSIZ 248 -struct olddirect { +struct olddirect { long od_ino; short od_fill1, od_fill2; char od_name[ODIRSIZ]; @@ -65,9 +65,9 @@ struct olddirect { struct dirent * readdir( - register DIR *dirp) + DIR *dirp) { - register struct olddirect *dp; + struct olddirect *dp; static struct dirent dir; for (;;) { @@ -101,10 +101,10 @@ readdir( void closedir( - register DIR *dirp) + DIR *dirp) { close(dirp->dd_fd); dirp->dd_fd = -1; dirp->dd_loc = 0; - ckfree((char *) dirp); + ckfree(dirp); } diff --git a/compat/strncasecmp.c b/compat/strncasecmp.c index 76cf549..0a69f35 100644 --- a/compat/strncasecmp.c +++ b/compat/strncasecmp.c @@ -1,4 +1,4 @@ -/* +/* * strncasecmp.c -- * * Source code for the "strncasecmp" library routine. @@ -18,7 +18,7 @@ * sequences. */ -static unsigned char charmap[] = { +static const unsigned char charmap[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, @@ -57,8 +57,8 @@ static unsigned char charmap[] = { * Here are the prototypes just in case they are not included in tclPort.h. */ -int strncasecmp(CONST char *s1, CONST char *s2, size_t n); -int strcasecmp(CONST char *s1, CONST char *s2); +int strncasecmp(const char *s1, const char *s2, size_t n); +int strcasecmp(const char *s1, const char *s2); /* *---------------------------------------------------------------------- @@ -79,8 +79,8 @@ int strcasecmp(CONST char *s1, CONST char *s2); int strcasecmp( - CONST char *s1, /* First string. */ - CONST char *s2) /* Second string. */ + const char *s1, /* First string. */ + const char *s2) /* Second string. */ { unsigned char u1, u2; @@ -114,8 +114,8 @@ strcasecmp( int strncasecmp( - CONST char *s1, /* First string. */ - CONST char *s2, /* Second string. */ + const char *s1, /* First string. */ + const char *s2, /* Second string. */ size_t length) /* Maximum number of characters to compare * (stop earlier if the end of either string * is reached). */ diff --git a/compat/strstr.c b/compat/strstr.c index 6698c9f..35386d0 100644 --- a/compat/strstr.c +++ b/compat/strstr.c @@ -1,4 +1,4 @@ -/* +/* * strstr.c -- * * Source code for the "strstr" library routine. @@ -36,10 +36,10 @@ char * strstr( - register char *string, /* String to search. */ - char *substring) /* Substring to try to find in string. */ + const char *string, /* String to search. */ + const char *substring) /* Substring to try to find in string. */ { - register char *a, *b; + const char *a, *b; /* * First scan quickly through the two strings looking for a @@ -49,7 +49,7 @@ strstr( b = substring; if (*b == 0) { - return string; + return (char *)string; } for ( ; *string != 0; string += 1) { if (*string != *b) { @@ -58,7 +58,7 @@ strstr( a = string; while (1) { if (*b == 0) { - return string; + return (char *)string; } if (*a++ != *b++) { break; diff --git a/compat/strtod.c b/compat/strtod.c index 1147825..b3b02d9 100644 --- a/compat/strtod.c +++ b/compat/strtod.c @@ -1,4 +1,4 @@ -/* +/* * strtod.c -- * * Source code for the "strtod" library procedure. @@ -61,7 +61,7 @@ static double powersOf10[] = { /* Table giving binary powers of 10. Entry */ double strtod( - CONST char *string, /* A decimal ASCII floating-point number, + const char *string, /* A decimal ASCII floating-point number, * optionally preceded by white space. Must * have form "-I.FE-X", where I is the integer * part of the mantissa, F is the fractional @@ -77,8 +77,8 @@ strtod( { int sign, expSign = FALSE; double fraction, dblExp, *d; - register CONST char *p; - register int c; + const char *p; + int c; int exp = 0; /* Exponent read from "EX" field. */ int fracExp = 0; /* Exponent that derives from the fractional * part. Under normal circumstatnces, it is @@ -92,7 +92,7 @@ strtod( int mantSize; /* Number of digits in mantissa. */ int decPt; /* Number of mantissa digits BEFORE decimal * point. */ - CONST char *pExp; /* Temporarily holds location of exponent in + const char *pExp; /* Temporarily holds location of exponent in * string. */ /* @@ -137,7 +137,7 @@ strtod( * has more than 18 digits, ignore the extras, since they can't affect the * value anyway. */ - + pExp = p; p -= mantSize; if (decPt < 0) { @@ -217,7 +217,7 @@ strtod( * by processing the exponent one bit at a time to combine many powers of * 2 of 10. Then combine the exponent with the fraction. */ - + if (exp < 0) { expSign = TRUE; exp = -exp; diff --git a/compat/strtol.c b/compat/strtol.c index 793f094..a9866f4 100644 --- a/compat/strtol.c +++ b/compat/strtol.c @@ -1,4 +1,4 @@ -/* +/* * strtol.c -- * * Source code for the "strtol" library procedure. @@ -10,7 +10,6 @@ * this file, and for a DISCLAIMER OF ALL WARRANTIES. */ -#include #include "tclInt.h" /* @@ -34,7 +33,7 @@ long int strtol( - CONST char *string, /* String of ASCII digits, possibly preceded + const char *string, /* String of ASCII digits, possibly preceded * by white space. For bases greater than 10, * either lower- or upper-case digits may be * used. */ @@ -46,7 +45,7 @@ strtol( * hex, "0" means octal, anything else means * decimal. */ { - register CONST char *p; + const char *p; long result; /* diff --git a/compat/strtoul.c b/compat/strtoul.c index 9d3f372..af63036 100644 --- a/compat/strtoul.c +++ b/compat/strtoul.c @@ -1,4 +1,4 @@ -/* +/* * strtoul.c -- * * Source code for the "strtoul" library procedure. @@ -18,7 +18,7 @@ * characters). */ -static char cvtIn[] = { +static const char cvtIn[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, /* '0' - '9' */ 100, 100, 100, 100, 100, 100, 100, /* punctuation */ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, /* 'A' - 'Z' */ @@ -50,7 +50,7 @@ static char cvtIn[] = { unsigned long int strtoul( - CONST char *string, /* String of ASCII digits, possibly preceded + const char *string, /* String of ASCII digits, possibly preceded * by white space. For bases greater than 10, * either lower- or upper-case digits may be * used. */ @@ -62,9 +62,9 @@ strtoul( * hex, "0" means octal, anything else means * decimal. */ { - register CONST char *p; - register unsigned long int result = 0; - register unsigned digit; + const char *p; + unsigned long int result = 0; + unsigned digit; int anyDigits = 0; int negative=0; int overflow=0; @@ -90,7 +90,7 @@ strtoul( * If no base was provided, pick one from the leading characters of the * string. */ - + if (base == 0) { if (*p == '0') { p += 1; @@ -206,7 +206,7 @@ strtoul( if (overflow) { errno = ERANGE; return ULONG_MAX; - } + } if (negative) { return -result; } diff --git a/compat/waitpid.c b/compat/waitpid.c index 8f65799..6f43934 100644 --- a/compat/waitpid.c +++ b/compat/waitpid.c @@ -1,4 +1,4 @@ -/* +/* * waitpid.c -- * * This procedure emulates the POSIX waitpid kernel call on BSD systems @@ -70,7 +70,7 @@ waitpid( int options) /* OR'ed combination of WNOHANG and * WUNTRACED. */ { - register WaitInfo *waitPtr, *prevPtr; + WaitInfo *waitPtr, *prevPtr; pid_t result; WAIT_STATUS_TYPE status; -- cgit v0.12