summaryrefslogtreecommitdiffstats
path: root/compat
diff options
context:
space:
mode:
authordkf <donal.k.fellows@manchester.ac.uk>2007-04-16 13:36:33 (GMT)
committerdkf <donal.k.fellows@manchester.ac.uk>2007-04-16 13:36:33 (GMT)
commit3b2f0df2b4603b0565ad30e1e15ae9f0bfe3cb5f (patch)
tree88437ef1c667959b00a3b86ee638cc3a94300aab /compat
parentb443cf5d2f6f6c75dc77a88987ed558a2fca9ba5 (diff)
downloadtcl-3b2f0df2b4603b0565ad30e1e15ae9f0bfe3cb5f.zip
tcl-3b2f0df2b4603b0565ad30e1e15ae9f0bfe3cb5f.tar.gz
tcl-3b2f0df2b4603b0565ad30e1e15ae9f0bfe3cb5f.tar.bz2
Complete the purge of K&R function definitions from manually-written code.
Diffstat (limited to 'compat')
-rw-r--r--compat/fixstrtod.c10
-rw-r--r--compat/gettod.c9
-rw-r--r--compat/opendir.c119
-rw-r--r--compat/strncasecmp.c46
-rw-r--r--compat/strstr.c29
-rw-r--r--compat/strtod.c63
-rw-r--r--compat/strtol.c40
-rw-r--r--compat/strtoll.c39
-rw-r--r--compat/strtoul.c71
-rw-r--r--compat/strtoull.c61
-rw-r--r--compat/tmpnam.c36
-rw-r--r--compat/waitpid.c93
12 files changed, 299 insertions, 317 deletions
diff --git a/compat/fixstrtod.c b/compat/fixstrtod.c
index 165b7d1..a779e22 100644
--- a/compat/fixstrtod.c
+++ b/compat/fixstrtod.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: fixstrtod.c,v 1.2 1998/09/14 18:39:44 stanton Exp $
+ * RCS: @(#) $Id: fixstrtod.c,v 1.3 2007/04/16 13:36:34 dkf Exp $
*/
#include <stdio.h>
@@ -22,12 +22,12 @@
* somes systems (e.g. SunOS 4.1.4) stdlib.h doesn't declare strtod.
*/
-extern double strtod();
+extern double strtod(char *, char **);
double
-fixstrtod(string, endPtr)
- char *string;
- char **endPtr;
+fixstrtod(
+ char *string,
+ char **endPtr)
{
double d;
d = strtod(string, endPtr);
diff --git a/compat/gettod.c b/compat/gettod.c
index 98758e6..179491b 100644
--- a/compat/gettod.c
+++ b/compat/gettod.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: gettod.c,v 1.3 2004/04/06 22:25:47 dgp Exp $
+ * RCS: @(#) $Id: gettod.c,v 1.4 2007/04/16 13:36:34 dkf Exp $
*/
#include "tclPort.h"
@@ -18,11 +18,12 @@
#undef timezone
int
-gettimeofday(tp, tz)
-struct timeval *tp;
-struct timezone *tz;
+gettimeofday(
+ struct timeval *tp,
+ struct timezone *tz)
{
struct timeb t;
+
ftime(&t);
tp->tv_sec = t.time;
tp->tv_usec = t. millitm * 1000;
diff --git a/compat/opendir.c b/compat/opendir.c
index 0b97156..6c8f263 100644
--- a/compat/opendir.c
+++ b/compat/opendir.c
@@ -1,13 +1,11 @@
/*
* opendir.c --
*
- * This file provides dirent-style directory-reading procedures
- * for V7 Unix systems that don't have such procedures. The
- * origin of this code is unclear, but it seems to have come
- * originally from Larry Wall.
+ * This file provides dirent-style directory-reading procedures for V7
+ * Unix systems that don't have such procedures. The origin of this code
+ * is unclear, but it seems to have come originally from Larry Wall.
*
- *
- * RCS: @(#) $Id: opendir.c,v 1.3 2004/04/06 22:25:48 dgp Exp $
+ * RCS: @(#) $Id: opendir.c,v 1.4 2007/04/16 13:36:34 dkf Exp $
*/
#include "tclInt.h"
@@ -19,24 +17,28 @@
/*
* open a directory.
*/
+
DIR *
-opendir(name)
-char *name;
+opendir(
+ char *name)
{
- register DIR *dirp;
- register int fd;
- char *myname;
+ register DIR *dirp;
+ register int fd;
+ char *myname;
- myname = ((*name == '\0') ? "." : name);
- if ((fd = open(myname, 0, 0)) == -1)
- return NULL;
- if ((dirp = (DIR *)ckalloc(sizeof(DIR))) == NULL) {
- close (fd);
- return NULL;
- }
- dirp->dd_fd = fd;
- dirp->dd_loc = 0;
- return dirp;
+ myname = ((*name == '\0') ? "." : name);
+ if ((fd = open(myname, 0, 0)) == -1) {
+ return NULL;
+ }
+ dirp = (DIR *) ckalloc(sizeof(DIR));
+ if (dirp == NULL) {
+ /* unreachable? */
+ close(fd);
+ return NULL;
+ }
+ dirp->dd_fd = fd;
+ dirp->dd_loc = 0;
+ return dirp;
}
/*
@@ -46,62 +48,65 @@ char *name;
#define ODIRSIZ 14
struct olddirect {
- ino_t od_ino;
- char od_name[ODIRSIZ];
+ ino_t od_ino;
+ char od_name[ODIRSIZ];
};
#else /* a Pyramid in the ATT universe */
#define ODIRSIZ 248
struct olddirect {
- long od_ino;
- short od_fill1, od_fill2;
- char od_name[ODIRSIZ];
+ long od_ino;
+ short od_fill1, od_fill2;
+ char od_name[ODIRSIZ];
};
#endif
/*
* get next entry in a directory.
*/
+
struct dirent *
-readdir(dirp)
-register DIR *dirp;
+readdir(
+ register DIR *dirp)
{
- register struct olddirect *dp;
- static struct dirent dir;
+ register struct olddirect *dp;
+ static struct dirent dir;
- for (;;) {
- if (dirp->dd_loc == 0) {
- dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf,
- DIRBLKSIZ);
- if (dirp->dd_size <= 0)
- return NULL;
- }
- if (dirp->dd_loc >= dirp->dd_size) {
- dirp->dd_loc = 0;
- continue;
- }
- dp = (struct olddirect *)(dirp->dd_buf + dirp->dd_loc);
- dirp->dd_loc += sizeof(struct olddirect);
- if (dp->od_ino == 0)
- continue;
- dir.d_ino = dp->od_ino;
- strncpy(dir.d_name, dp->od_name, ODIRSIZ);
- dir.d_name[ODIRSIZ] = '\0'; /* insure null termination */
- dir.d_namlen = strlen(dir.d_name);
- dir.d_reclen = DIRSIZ(&dir);
- return (&dir);
+ for (;;) {
+ if (dirp->dd_loc == 0) {
+ dirp->dd_size = read(dirp->dd_fd, dirp->dd_buf, DIRBLKSIZ);
+ if (dirp->dd_size <= 0) {
+ return NULL;
+ }
+ }
+ if (dirp->dd_loc >= dirp->dd_size) {
+ dirp->dd_loc = 0;
+ continue;
}
+ dp = (struct olddirect *)(dirp->dd_buf + dirp->dd_loc);
+ dirp->dd_loc += sizeof(struct olddirect);
+ if (dp->od_ino == 0) {
+ continue;
+ }
+ dir.d_ino = dp->od_ino;
+ strncpy(dir.d_name, dp->od_name, ODIRSIZ);
+ dir.d_name[ODIRSIZ] = '\0'; /* insure null termination */
+ dir.d_namlen = strlen(dir.d_name);
+ dir.d_reclen = DIRSIZ(&dir);
+ return &dir;
+ }
}
/*
* close a directory.
*/
+
void
-closedir(dirp)
-register DIR *dirp;
+closedir(
+ register DIR *dirp)
{
- close(dirp->dd_fd);
- dirp->dd_fd = -1;
- dirp->dd_loc = 0;
- ckfree((char *) dirp);
+ close(dirp->dd_fd);
+ dirp->dd_fd = -1;
+ dirp->dd_loc = 0;
+ ckfree((char *) dirp);
}
diff --git a/compat/strncasecmp.c b/compat/strncasecmp.c
index ca2bf91..d752ba8 100644
--- a/compat/strncasecmp.c
+++ b/compat/strncasecmp.c
@@ -6,18 +6,18 @@
* Copyright (c) 1988-1993 The Regents of the University of California.
* Copyright (c) 1995-1996 Sun Microsystems, Inc.
*
- * See the file "license.terms" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ * See the file "license.terms" for information on usage and redistribution of
+ * this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: strncasecmp.c,v 1.2 1998/09/14 18:39:45 stanton Exp $
+ * RCS: @(#) $Id: strncasecmp.c,v 1.3 2007/04/16 13:36:34 dkf Exp $
*/
#include "tclPort.h"
/*
- * This array is designed for mapping upper and lower case letter
- * together for a case independent comparison. The mappings are
- * based upon ASCII character sequences.
+ * This array is designed for mapping upper and lower case letter together for
+ * a case independent comparison. The mappings are based upon ASCII character
+ * sequences.
*/
static unsigned char charmap[] = {
@@ -56,14 +56,11 @@ static unsigned char charmap[] = {
};
/*
- * Here are the prototypes just in case they are not included
- * in tclPort.h.
+ * Here are the prototypes just in case they are not included in tclPort.h.
*/
-int strncasecmp _ANSI_ARGS_((CONST char *s1,
- CONST char *s2, size_t n));
-int strcasecmp _ANSI_ARGS_((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);
/*
*----------------------------------------------------------------------
@@ -73,9 +70,8 @@ int strcasecmp _ANSI_ARGS_((CONST char *s1,
* Compares two strings, ignoring case differences.
*
* Results:
- * Compares two null-terminated strings s1 and s2, returning -1, 0,
- * or 1 if s1 is lexicographically less than, equal to, or greater
- * than s2.
+ * Compares two null-terminated strings s1 and s2, returning -1, 0, or 1
+ * if s1 is lexicographically less than, equal to, or greater than s2.
*
* Side effects:
* None.
@@ -84,9 +80,9 @@ int strcasecmp _ANSI_ARGS_((CONST char *s1,
*/
int
-strcasecmp(s1, s2)
- CONST char *s1; /* First string. */
- CONST char *s2; /* Second string. */
+strcasecmp(
+ CONST char *s1, /* First string. */
+ CONST char *s2) /* Second string. */
{
unsigned char u1, u2;
@@ -108,9 +104,9 @@ strcasecmp(s1, s2)
* Compares two strings, ignoring case differences.
*
* Results:
- * Compares up to length chars of s1 and s2, returning -1, 0, or 1
- * if s1 is lexicographically less than, equal to, or greater
- * than s2 over those characters.
+ * Compares up to length chars of s1 and s2, returning -1, 0, or 1 if s1
+ * is lexicographically less than, equal to, or greater than s2 over
+ * those characters.
*
* Side effects:
* None.
@@ -119,10 +115,10 @@ strcasecmp(s1, s2)
*/
int
-strncasecmp(s1, s2, length)
- CONST char *s1; /* First string. */
- CONST char *s2; /* Second string. */
- size_t length; /* Maximum number of characters to compare
+strncasecmp(
+ 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 015d61b..8679fe3 100644
--- a/compat/strstr.c
+++ b/compat/strstr.c
@@ -6,10 +6,10 @@
* Copyright (c) 1988-1993 The Regents of the University of California.
* Copyright (c) 1994 Sun Microsystems, Inc.
*
- * See the file "license.terms" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ * See the file "license.terms" for information on usage and redistribution of
+ * this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: strstr.c,v 1.6 2005/05/10 18:33:54 kennykb Exp $
+ * RCS: @(#) $Id: strstr.c,v 1.7 2007/04/16 13:36:34 dkf Exp $
*/
#include "tcl.h"
@@ -25,12 +25,10 @@
* Locate the first instance of a substring in a string.
*
* Results:
- * If string contains substring, the return value is the
- * location of the first matching instance of substring
- * in string. If string doesn't contain substring, the
- * return value is 0. Matching is done on an exact
- * character-for-character basis with no wildcards or special
- * characters.
+ * If string contains substring, the return value is the location of the
+ * first matching instance of substring in string. If string doesn't
+ * contain substring, the return value is 0. Matching is done on an exact
+ * character-for-character basis with no wildcards or special characters.
*
* Side effects:
* None.
@@ -39,15 +37,16 @@
*/
char *
-strstr(string, substring)
- register char *string; /* String to search. */
- char *substring; /* Substring to try to find in string. */
+strstr(
+ register char *string, /* String to search. */
+ char *substring) /* Substring to try to find in string. */
{
register char *a, *b;
- /* First scan quickly through the two strings looking for a
- * single-character match. When it's found, then compare the
- * rest of the substring.
+ /*
+ * First scan quickly through the two strings looking for a
+ * single-character match. When it's found, then compare the rest of the
+ * substring.
*/
b = substring;
diff --git a/compat/strtod.c b/compat/strtod.c
index b75d72e..9e494b1 100644
--- a/compat/strtod.c
+++ b/compat/strtod.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: strtod.c,v 1.7 2004/04/06 22:25:48 dgp Exp $
+ * RCS: @(#) $Id: strtod.c,v 1.8 2007/04/16 13:36:34 dkf Exp $
*/
#include "tclInt.h"
@@ -62,20 +62,19 @@ static double powersOf10[] = { /* Table giving binary powers of 10. Entry */
*/
double
-strtod(string, endPtr)
- 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 part of the mantissa, and X
- * is the exponent. Either of the signs
- * may be "+", "-", or omitted. Either I
- * or F may be omitted, or both. The decimal
- * point isn't necessary unless F is present.
- * The "E" may actually be an "e". E and X
- * may both be omitted (but not just one).
- */
- char **endPtr; /* If non-NULL, store terminating character's
+strtod(
+ 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
+ * part of the mantissa, and X is the
+ * exponent. Either of the signs may be "+",
+ * "-", or omitted. Either I or F may be
+ * omitted, or both. The decimal point isn't
+ * necessary unless F is present. The "E" may
+ * actually be an "e". E and X may both be
+ * omitted (but not just one). */
+ char **endPtr) /* If non-NULL, store terminating character's
* address here. */
{
int sign, expSign = FALSE;
@@ -84,19 +83,19 @@ strtod(string, endPtr)
register 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
+ * part. Under normal circumstatnces, it is
* the negative of the number of digits in F.
* However, if I is very long, the last digits
* of I get dropped (otherwise a long I with a
* large negative exponent could cause an
- * unnecessary overflow on I alone). In this
+ * unnecessary overflow on I alone). In this
* case, fracExp is incremented one for each
* dropped digit. */
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 string. */
+ CONST char *pExp; /* Temporarily holds location of exponent in
+ * string. */
/*
* Strip off leading blanks and check for a sign.
@@ -135,10 +134,10 @@ strtod(string, endPtr)
}
/*
- * Now suck up the digits in the mantissa. Use two integers to
- * collect 9 digits each (this is faster than using floating-point).
- * If the mantissa has more than 18 digits, ignore the extras, since
- * they can't affect the value anyway.
+ * Now suck up the digits in the mantissa. Use two integers to collect 9
+ * digits each (this is faster than using floating-point). If the mantissa
+ * has more than 18 digits, ignore the extras, since they can't affect the
+ * value anyway.
*/
pExp = p;
@@ -146,7 +145,7 @@ strtod(string, endPtr)
if (decPt < 0) {
decPt = mantSize;
} else {
- mantSize -= 1; /* One of the digits was the point. */
+ mantSize -= 1; /* One of the digits was the point. */
}
if (mantSize > 18) {
fracExp = decPt - 18;
@@ -160,9 +159,9 @@ strtod(string, endPtr)
goto done;
} else {
int frac1, frac2;
+
frac1 = 0;
- for ( ; mantSize > 9; mantSize -= 1)
- {
+ for ( ; mantSize > 9; mantSize -= 1) {
c = *p;
p += 1;
if (c == '.') {
@@ -172,8 +171,7 @@ strtod(string, endPtr)
frac1 = 10*frac1 + (c - '0');
}
frac2 = 0;
- for (; mantSize > 0; mantSize -= 1)
- {
+ for (; mantSize > 0; mantSize -= 1) {
c = *p;
p += 1;
if (c == '.') {
@@ -217,10 +215,9 @@ strtod(string, endPtr)
}
/*
- * Generate a floating-point number that represents the exponent.
- * Do this by processing the exponent one bit at a time to combine
- * many powers of 2 of 10. Then combine the exponent with the
- * fraction.
+ * Generate a floating-point number that represents the exponent. Do this
+ * 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) {
@@ -245,7 +242,7 @@ strtod(string, endPtr)
fraction *= dblExp;
}
-done:
+ done:
if (endPtr != NULL) {
*endPtr = (char *) p;
}
diff --git a/compat/strtol.c b/compat/strtol.c
index b91e7d0..3779597 100644
--- a/compat/strtol.c
+++ b/compat/strtol.c
@@ -6,15 +6,14 @@
* Copyright (c) 1988 The Regents of the University of California.
* Copyright (c) 1994 Sun Microsystems, Inc.
*
- * See the file "license.terms" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ * See the file "license.terms" for information on usage and redistribution of
+ * this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: strtol.c,v 1.5 2004/04/06 22:25:48 dgp Exp $
+ * RCS: @(#) $Id: strtol.c,v 1.6 2007/04/16 13:36:34 dkf Exp $
*/
#include <ctype.h>
#include "tclInt.h"
-
/*
*----------------------------------------------------------------------
@@ -24,11 +23,10 @@
* Convert an ASCII string into an integer.
*
* Results:
- * The return value is the integer equivalent of string. If endPtr
- * is non-NULL, then *endPtr is filled in with the character
- * after the last one that was part of the integer. If string
- * doesn't contain a valid integer value, then zero is returned
- * and *endPtr is set to string.
+ * The return value is the integer equivalent of string. If endPtr is
+ * non-NULL, then *endPtr is filled in with the character after the last
+ * one that was part of the integer. If string doesn't contain a valid
+ * integer value, then zero is returned and *endPtr is set to string.
*
* Side effects:
* None.
@@ -37,20 +35,18 @@
*/
long int
-strtol(string, endPtr, base)
- 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.
- */
- char **endPtr; /* Where to store address of terminating
+strtol(
+ 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. */
+ char **endPtr, /* Where to store address of terminating
* character, or NULL. */
- int base; /* Base for conversion. Must be less
- * than 37. If 0, then the base is chosen
- * from the leading characters of string:
- * "0x" means hex, "0" means octal, anything
- * else means decimal.
- */
+ int base) /* Base for conversion. Must be less than 37.
+ * If 0, then the base is chosen from the
+ * leading characters of string: "0x" means
+ * hex, "0" means octal, anything else means
+ * decimal. */
{
register CONST char *p;
long result;
diff --git a/compat/strtoll.c b/compat/strtoll.c
index 50edd41..ce1c8a1 100644
--- a/compat/strtoll.c
+++ b/compat/strtoll.c
@@ -6,10 +6,10 @@
* Copyright (c) 1988 The Regents of the University of California.
* Copyright (c) 1994 Sun Microsystems, Inc.
*
- * See the file "license.terms" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ * See the file "license.terms" for information on usage and redistribution of
+ * this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: strtoll.c,v 1.8 2005/05/10 18:33:54 kennykb Exp $
+ * RCS: @(#) $Id: strtoll.c,v 1.9 2007/04/16 13:36:34 dkf Exp $
*/
#include "tclInt.h"
@@ -26,11 +26,10 @@
* Convert an ASCII string into an integer.
*
* Results:
- * The return value is the integer equivalent of string. If endPtr
- * is non-NULL, then *endPtr is filled in with the character
- * after the last one that was part of the integer. If string
- * doesn't contain a valid integer value, then zero is returned
- * and *endPtr is set to string.
+ * The return value is the integer equivalent of string. If endPtr is
+ * non-NULL, then *endPtr is filled in with the character after the last
+ * one that was part of the integer. If string doesn't contain a valid
+ * integer value, then zero is returned and *endPtr is set to string.
*
* Side effects:
* None.
@@ -43,20 +42,18 @@ long long
#else
Tcl_WideInt
#endif
-strtoll(string, endPtr, base)
- 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.
- */
- char **endPtr; /* Where to store address of terminating
+strtoll(
+ 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. */
+ char **endPtr, /* Where to store address of terminating
* character, or NULL. */
- int base; /* Base for conversion. Must be less
- * than 37. If 0, then the base is chosen
- * from the leading characters of string:
- * "0x" means hex, "0" means octal, anything
- * else means decimal.
- */
+ int base) /* Base for conversion. Must be less than 37.
+ * If 0, then the base is chosen from the
+ * leading characters of string: "0x" means
+ * hex, "0" means octal, anything else means
+ * decimal. */
{
register CONST char *p;
Tcl_WideInt result = Tcl_LongAsWide(0);
diff --git a/compat/strtoul.c b/compat/strtoul.c
index 92637e1..64f95a6 100644
--- a/compat/strtoul.c
+++ b/compat/strtoul.c
@@ -6,18 +6,18 @@
* Copyright (c) 1988 The Regents of the University of California.
* Copyright (c) 1994 Sun Microsystems, Inc.
*
- * See the file "license.terms" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ * See the file "license.terms" for information on usage and redistribution of
+ * this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: strtoul.c,v 1.6 2004/04/06 22:25:48 dgp Exp $
+ * RCS: @(#) $Id: strtoul.c,v 1.7 2007/04/16 13:36:34 dkf Exp $
*/
#include "tclInt.h"
/*
- * The table below is used to convert from ASCII digits to a
- * numerical equivalent. It maps from '0' through 'z' to integers
- * (100 for non-digit characters).
+ * The table below is used to convert from ASCII digits to a numerical
+ * equivalent. It maps from '0' through 'z' to integers (100 for non-digit
+ * characters).
*/
static char cvtIn[] = {
@@ -39,11 +39,10 @@ static char cvtIn[] = {
* Convert an ASCII string into an integer.
*
* Results:
- * The return value is the integer equivalent of string. If endPtr
- * is non-NULL, then *endPtr is filled in with the character
- * after the last one that was part of the integer. If string
- * doesn't contain a valid integer value, then zero is returned
- * and *endPtr is set to string.
+ * The return value is the integer equivalent of string. If endPtr is
+ * non-NULL, then *endPtr is filled in with the character after the last
+ * one that was part of the integer. If string doesn't contain a valid
+ * integer value, then zero is returned and *endPtr is set to string.
*
* Side effects:
* None.
@@ -52,20 +51,18 @@ static char cvtIn[] = {
*/
unsigned long int
-strtoul(string, endPtr, base)
- 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.
- */
- char **endPtr; /* Where to store address of terminating
+strtoul(
+ 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. */
+ char **endPtr, /* Where to store address of terminating
* character, or NULL. */
- int base; /* Base for conversion. Must be less
- * than 37. If 0, then the base is chosen
- * from the leading characters of string:
- * "0x" means hex, "0" means octal, anything
- * else means decimal.
- */
+ int base) /* Base for conversion. Must be less than 37.
+ * If 0, then the base is chosen from the
+ * leading characters of string: "0x" means
+ * hex, "0" means octal, anything else means
+ * decimal. */
{
register CONST char *p;
register unsigned long int result = 0;
@@ -92,31 +89,29 @@ strtoul(string, endPtr, base)
}
/*
- * If no base was provided, pick one from the leading characters
- * of the string.
+ * If no base was provided, pick one from the leading characters of the
+ * string.
*/
- if (base == 0)
- {
+ if (base == 0) {
if (*p == '0') {
p += 1;
if ((*p == 'x') || (*p == 'X')) {
p += 1;
base = 16;
} else {
-
/*
- * Must set anyDigits here, otherwise "0" produces a
- * "no digits" error.
+ * Must set anyDigits here, otherwise "0" produces a "no
+ * digits" error.
*/
anyDigits = 1;
base = 8;
}
+ } else {
+ base = 10;
}
- else base = 10;
} else if (base == 16) {
-
/*
* Skip a leading "0x" from hex numbers.
*/
@@ -127,12 +122,13 @@ strtoul(string, endPtr, base)
}
/*
- * Sorry this code is so messy, but speed seems important. Do
- * different things for base 8, 10, 16, and other.
+ * Sorry this code is so messy, but speed seems important. Do different
+ * things for base 8, 10, 16, and other.
*/
if (base == 8) {
unsigned long maxres = ULONG_MAX >> 3;
+
for ( ; ; p += 1) {
digit = *p - '0';
if (digit > 7) {
@@ -146,6 +142,7 @@ strtoul(string, endPtr, base)
}
} else if (base == 10) {
unsigned long maxres = ULONG_MAX / 10;
+
for ( ; ; p += 1) {
digit = *p - '0';
if (digit > 9) {
@@ -159,6 +156,7 @@ strtoul(string, endPtr, base)
}
} else if (base == 16) {
unsigned long maxres = ULONG_MAX >> 4;
+
for ( ; ; p += 1) {
digit = *p - '0';
if (digit > ('z' - '0')) {
@@ -174,8 +172,9 @@ strtoul(string, endPtr, base)
result += digit;
anyDigits = 1;
}
- } else if ( base >= 2 && base <= 36 ) {
+ } else if (base >= 2 && base <= 36) {
unsigned long maxres = ULONG_MAX / base;
+
for ( ; ; p += 1) {
digit = *p - '0';
if (digit > ('z' - '0')) {
diff --git a/compat/strtoull.c b/compat/strtoull.c
index 027c593..b31567f 100644
--- a/compat/strtoull.c
+++ b/compat/strtoull.c
@@ -6,19 +6,19 @@
* Copyright (c) 1988 The Regents of the University of California.
* Copyright (c) 1994 Sun Microsystems, Inc.
*
- * See the file "license.terms" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ * See the file "license.terms" for information on usage and redistribution of
+ * this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: strtoull.c,v 1.8 2005/05/10 18:33:54 kennykb Exp $
+ * RCS: @(#) $Id: strtoull.c,v 1.9 2007/04/16 13:36:34 dkf Exp $
*/
#include "tclInt.h"
#include <ctype.h>
/*
- * The table below is used to convert from ASCII digits to a
- * numerical equivalent. It maps from '0' through 'z' to integers
- * (100 for non-digit characters).
+ * The table below is used to convert from ASCII digits to a numerical
+ * equivalent. It maps from '0' through 'z' to integers (100 for non-digit
+ * characters).
*/
static char cvtIn[] = {
@@ -41,11 +41,10 @@ static char cvtIn[] = {
* Convert an ASCII string into an integer.
*
* Results:
- * The return value is the integer equivalent of string. If endPtr
- * is non-NULL, then *endPtr is filled in with the character
- * after the last one that was part of the integer. If string
- * doesn't contain a valid integer value, then zero is returned
- * and *endPtr is set to string.
+ * The return value is the integer equivalent of string. If endPtr is
+ * non-NULL, then *endPtr is filled in with the character after the last
+ * one that was part of the integer. If string doesn't contain a valid
+ * integer value, then zero is returned and *endPtr is set to string.
*
* Side effects:
* None.
@@ -58,20 +57,18 @@ unsigned long long
#else
Tcl_WideUInt
#endif
-strtoull(string, endPtr, base)
- 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.
- */
- char **endPtr; /* Where to store address of terminating
+strtoull(
+ 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. */
+ char **endPtr, /* Where to store address of terminating
* character, or NULL. */
- int base; /* Base for conversion. Must be less
- * than 37. If 0, then the base is chosen
- * from the leading characters of string:
- * "0x" means hex, "0" means octal, anything
- * else means decimal.
- */
+ int base) /* Base for conversion. Must be less than 37.
+ * If 0, then the base is chosen from the
+ * leading characters of string: "0x" means
+ * hex, "0" means octal, anything else means
+ * decimal. */
{
register CONST char *p;
register Tcl_WideUInt result = 0;
@@ -102,8 +99,8 @@ strtoull(string, endPtr, base)
}
/*
- * If no base was provided, pick one from the leading characters
- * of the string.
+ * If no base was provided, pick one from the leading characters of the
+ * string.
*/
if (base == 0) {
@@ -113,10 +110,9 @@ strtoull(string, endPtr, base)
p += 1;
base = 16;
} else {
-
/*
- * Must set anyDigits here, otherwise "0" produces a
- * "no digits" error.
+ * Must set anyDigits here, otherwise "0" produces a "no
+ * digits" error.
*/
anyDigits = 1;
@@ -126,7 +122,6 @@ strtoull(string, endPtr, base)
base = 10;
}
} else if (base == 16) {
-
/*
* Skip a leading "0x" from hex numbers.
*/
@@ -137,8 +132,8 @@ strtoull(string, endPtr, base)
}
/*
- * Sorry this code is so messy, but speed seems important. Do
- * different things for base 8, 10, 16, and other.
+ * Sorry this code is so messy, but speed seems important. Do different
+ * things for base 8, 10, 16, and other.
*/
if (base == 8) {
@@ -241,7 +236,7 @@ strtoull(string, endPtr, base)
* On overflow generate the right output
*/
- overflow:
+ overflow:
errno = ERANGE;
if (endPtr != 0) {
for ( ; ; p += 1) {
diff --git a/compat/tmpnam.c b/compat/tmpnam.c
index 89bfc6a..6faf8de 100644
--- a/compat/tmpnam.c
+++ b/compat/tmpnam.c
@@ -2,14 +2,14 @@
* Copyright (c) 1988 Regents of the University of California.
* All rights reserved.
*
- * Redistribution and use in source and binary forms are permitted
- * provided that this notice is preserved and that due credit is given
- * to the University of California at Berkeley. The name of the University
- * may not be used to endorse or promote products derived from this
- * software without specific written prior permission. This software
- * is provided ``as is'' without express or implied warranty.
+ * Redistribution and use in source and binary forms are permitted provided
+ * that this notice is preserved and that due credit is given to the
+ * University of California at Berkeley. The name of the University may not be
+ * used to endorse or promote products derived from this software without
+ * specific written prior permission. This software is provided ``as is''
+ * without express or implied warranty.
*
- * RCS: @(#) $Id: tmpnam.c,v 1.2 1998/09/14 18:39:45 stanton Exp $
+ * RCS: @(#) $Id: tmpnam.c,v 1.3 2007/04/16 13:36:34 dkf Exp $
*/
#include <sys/param.h>
@@ -18,9 +18,8 @@
#include <stdio.h>
/*
- * Use /tmp instead of /usr/tmp, because L_tmpname is only 14 chars
- * on some machines (like NeXT machines) and /usr/tmp will cause
- * buffer overflows.
+ * Use /tmp instead of /usr/tmp, because L_tmpname is only 14 chars on some
+ * machines (like NeXT machines) and /usr/tmp will cause buffer overflows.
*/
#ifdef P_tmpdir
@@ -29,14 +28,15 @@
#define P_tmpdir "/tmp"
char *
-tmpnam(s)
- char *s;
+tmpnam(
+ char *s)
{
- static char name[50];
- char *mktemp();
+ static char name[50];
+ char *mktemp(char *);
- if (!s)
- s = name;
- (void)sprintf(s, "%s/XXXXXX", P_tmpdir);
- return(mktemp(s));
+ if (!s) {
+ s = name;
+ }
+ (void) sprintf(s, "%s/XXXXXX", P_tmpdir);
+ return mktemp(s);
}
diff --git a/compat/waitpid.c b/compat/waitpid.c
index 365d51e..0e9e6d6 100644
--- a/compat/waitpid.c
+++ b/compat/waitpid.c
@@ -1,18 +1,17 @@
/*
* waitpid.c --
*
- * This procedure emulates the POSIX waitpid kernel call on
- * BSD systems that don't have waitpid but do have wait3.
- * This code is based on a prototype version written by
- * Mark Diekhans and Karl Lehenbauer.
+ * This procedure emulates the POSIX waitpid kernel call on BSD systems
+ * that don't have waitpid but do have wait3. This code is based on a
+ * prototype version written by Mark Diekhans and Karl Lehenbauer.
*
* Copyright (c) 1993 The Regents of the University of California.
* Copyright (c) 1994 Sun Microsystems, Inc.
*
- * See the file "license.terms" for information on usage and redistribution
- * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ * See the file "license.terms" for information on usage and redistribution of
+ * this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: waitpid.c,v 1.4 2004/04/06 22:25:48 dgp Exp $
+ * RCS: @(#) $Id: waitpid.c,v 1.5 2007/04/16 13:36:35 dkf Exp $
*/
#include "tclPort.h"
@@ -22,40 +21,37 @@
#endif
/*
- * A linked list of the following structures is used to keep track
- * of processes for which we received notification from the kernel,
- * but the application hasn't waited for them yet (this can happen
- * because wait may not return the process we really want). We
- * save the information here until the application finally does
- * wait for the process.
+ * A linked list of the following structures is used to keep track of
+ * processes for which we received notification from the kernel, but the
+ * application hasn't waited for them yet (this can happen because wait may
+ * not return the process we really want). We save the information here until
+ * the application finally does wait for the process.
*/
typedef struct WaitInfo {
- pid_t pid; /* Pid of process that exited. */
- WAIT_STATUS_TYPE status; /* Status returned when child exited
- * or suspended. */
- struct WaitInfo *nextPtr; /* Next in list of exited processes. */
+ pid_t pid; /* Pid of process that exited. */
+ WAIT_STATUS_TYPE status; /* Status returned when child exited or
+ * suspended. */
+ struct WaitInfo *nextPtr; /* Next in list of exited processes. */
} WaitInfo;
-static WaitInfo *deadList = NULL; /* First in list of all dead
- * processes. */
+static WaitInfo *deadList = NULL;
+ /* First in list of all dead processes. */
/*
*----------------------------------------------------------------------
*
* waitpid --
*
- * This procedure emulates the functionality of the POSIX
- * waitpid kernel call, using the BSD wait3 kernel call.
- * Note: it doesn't emulate absolutely all of the waitpid
- * functionality, in that it doesn't support pid's of 0
- * or < -1.
+ * This procedure emulates the functionality of the POSIX waitpid kernel
+ * call, using the BSD wait3 kernel call. Note: it doesn't emulate
+ * absolutely all of the waitpid functionality, in that it doesn't
+ * support pid's of 0 or < -1.
*
* Results:
- * -1 is returned if there is an error in the wait kernel call.
- * Otherwise the pid of an exited or suspended process is
- * returned and *statusPtr is set to the status value of the
- * process.
+ * -1 is returned if there is an error in the wait kernel call. Otherwise
+ * the pid of an exited or suspended process is returned and *statusPtr
+ * is set to the status value of the process.
*
* Side effects:
* None.
@@ -68,12 +64,12 @@ static WaitInfo *deadList = NULL; /* First in list of all dead
#endif
pid_t
-waitpid(pid, statusPtr, options)
- pid_t pid; /* The pid to wait on. Must be -1 or
- * greater than zero. */
- int *statusPtr; /* Where to store wait status for the
+waitpid(
+ pid_t pid, /* The pid to wait on. Must be -1 or greater
+ * than zero. */
+ int *statusPtr, /* Where to store wait status for the
* process. */
- int options; /* OR'ed combination of WNOHANG and
+ int options) /* OR'ed combination of WNOHANG and
* WUNTRACED. */
{
register WaitInfo *waitPtr, *prevPtr;
@@ -86,9 +82,9 @@ waitpid(pid, statusPtr, options)
}
/*
- * See if there's a suitable process that has already stopped or
- * exited. If so, remove it from the list of exited processes and
- * return its information.
+ * See if there's a suitable process that has already stopped or exited.
+ * If so, remove it from the list of exited processes and return its
+ * information.
*/
for (waitPtr = deadList, prevPtr = NULL; waitPtr != NULL;
@@ -111,12 +107,12 @@ waitpid(pid, statusPtr, options)
}
/*
- * Wait for any process to stop or exit. If it's an acceptable one
- * then return it to the caller; otherwise store information about it
- * in the list of exited processes and try again. On systems that
- * have only wait but not wait3, there are several situations we can't
- * handle, but we do the best we can (e.g. can still handle some
- * combinations of options by invoking wait instead of wait3).
+ * Wait for any process to stop or exit. If it's an acceptable one then
+ * return it to the caller; otherwise store information about it in the
+ * list of exited processes and try again. On systems that have only wait
+ * but not wait3, there are several situations we can't handle, but we do
+ * the best we can (e.g. can still handle some combinations of options by
+ * invoking wait instead of wait3).
*/
while (1) {
@@ -149,13 +145,13 @@ waitpid(pid, statusPtr, options)
return result;
/*
- * Can't return this info to caller. Save it in the list of
- * stopped or exited processes. Tricky point: first check for
- * an existing entry for the process and overwrite it if it
- * exists (e.g. a previously stopped process might now be dead).
+ * Can't return this info to caller. Save it in the list of stopped or
+ * exited processes. Tricky point: first check for an existing entry
+ * for the process and overwrite it if it exists (e.g. a previously
+ * stopped process might now be dead).
*/
- saveInfo:
+ saveInfo:
for (waitPtr = deadList; waitPtr != NULL; waitPtr = waitPtr->nextPtr) {
if (waitPtr->pid == result) {
waitPtr->status = status;
@@ -168,6 +164,7 @@ waitpid(pid, statusPtr, options)
waitPtr->nextPtr = deadList;
deadList = waitPtr;
- waitAgain: continue;
+ waitAgain:
+ continue;
}
}