*/
/* $Id$ */
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
-void __bad_assertion(const char *mess) {
+void __bad_assertion(const char* mess)
+{
fputs(mess, stderr);
abort();
-#include <ctype.h>
+#include <ctype.h>
-int tolower(int c) {
- return isupper(c) ? c - 'A' + 'a' : c ;
+int tolower(int c)
+{
+ return isupper(c) ? c - 'A' + 'a' : c;
}
-#include <ctype.h>
+#include <ctype.h>
-int toupper(int c) {
- return islower(c) ? c - 'a' + 'A' : c ;
+int toupper(int c)
+{
+ return islower(c) ? c - 'a' + 'A' : c;
}
*/
/* $Id$ */
-#include <errno.h>
+#include <errno.h>
-const char *_sys_errlist[] = {
- "Error 0",
- "Not owner",
- "No such file or directory",
- "No such process",
- "Interrupted system call",
- "I/O error",
- "No such device or address",
- "Arg list too long",
- "Exec format error",
- "Bad file number",
- "No children",
- "No more processes",
- "Not enough core",
- "Permission denied",
- "Bad address",
- "Block device required",
- "Mount device busy",
- "File exists",
- "Cross-device link",
- "No such device",
- "Not a directory",
- "Is a directory",
- "Invalid argument",
- "File table overflow",
- "Too many open files",
- "Not a typewriter",
- "Text file busy",
- "File too large",
- "No space left on device",
- "Illegal seek",
- "Read-only file system",
- "Too many links",
- "Broken pipe",
- "Math argument",
- "Result too large"
+const char* _sys_errlist[] = {
+ "Error 0",
+ "Not owner",
+ "No such file or directory",
+ "No such process",
+ "Interrupted system call",
+ "I/O error",
+ "No such device or address",
+ "Arg list too long",
+ "Exec format error",
+ "Bad file number",
+ "No children",
+ "No more processes",
+ "Not enough core",
+ "Permission denied",
+ "Bad address",
+ "Block device required",
+ "Mount device busy",
+ "File exists",
+ "Cross-device link",
+ "No such device",
+ "Not a directory",
+ "Is a directory",
+ "Invalid argument",
+ "File table overflow",
+ "Too many open files",
+ "Not a typewriter",
+ "Text file busy",
+ "File too large",
+ "No space left on device",
+ "Illegal seek",
+ "Read-only file system",
+ "Too many links",
+ "Broken pipe",
+ "Math argument",
+ "Result too large"
};
const int _sys_nerr = sizeof(_sys_errlist) / sizeof(_sys_errlist[0]);
*/
/* $Id$ */
-#include <limits.h>
-#include <locale.h>
+#include <limits.h>
+#include <locale.h>
extern struct lconv _lc;
-struct lconv *
+struct lconv*
localeconv(void)
{
- register struct lconv *lcp = &_lc;
+ register struct lconv* lcp = &_lc;
lcp->decimal_point = ".";
lcp->thousands_sep = "";
*/
/* $Id$ */
-#include <locale.h>
-#include <string.h>
+#include <locale.h>
+#include <string.h>
struct lconv _lc;
-char *
-setlocale(int category, const char *locale)
+char* setlocale(int category, const char* locale)
{
- if (!locale) return "C";
- if (*locale && strcmp(locale, "C")) return (char *)NULL;
-
- switch(category) {
- case LC_ALL:
- case LC_CTYPE:
- case LC_COLLATE:
- case LC_TIME:
- case LC_NUMERIC:
- case LC_MONETARY:
- return *locale ? (char *)locale : "C";
- default:
- return (char *)NULL;
+ if (!locale)
+ return "C";
+ if (*locale && strcmp(locale, "C"))
+ return (char*)NULL;
+
+ switch (category)
+ {
+ case LC_ALL:
+ case LC_CTYPE:
+ case LC_COLLATE:
+ case LC_TIME:
+ case LC_NUMERIC:
+ case LC_MONETARY:
+ return *locale ? (char*)locale : "C";
+ default:
+ return (char*)NULL;
}
}
void* calloc(size_t nmemb, size_t size)
{
- size_t bytes = nmemb * size;
- void* ptr;
-
- /* Test for overflow.
+ size_t bytes = nmemb * size;
+ void* ptr;
+
+ /* Test for overflow.
* See http://stackoverflow.com/questions/1815367/multiplication-of-large-numbers-how-to-catch-overflow
*/
- if ((nmemb == 0) || (size == 0) || (nmemb > (SIZE_MAX / size)))
- return NULL;
-
- ptr = malloc(bytes);
- if (!ptr)
- return NULL;
+ if ((nmemb == 0) || (size == 0) || (nmemb > (SIZE_MAX / size)))
+ return NULL;
+
+ ptr = malloc(bytes);
+ if (!ptr)
+ return NULL;
- memset(ptr, 0, bytes);
- return ptr;
+ memset(ptr, 0, bytes);
+ return ptr;
}
#include <unistd.h>
#include "malloc.h"
-block_t __mem_root = {&__mem_root, 0};
+block_t __mem_root = { &__mem_root, 0 };
block_t* __mem_freelist = &__mem_root;
/* Pulls more memory from the system. */
* The size field is already set. */
prev->next = p->next;
__mem_freelist = prev;
- return (void*) (p+1);
+ return (void*)(p + 1);
}
else if (p->size > nblocks)
{
p += p->size; /* p now points at our new block */
p->size = nblocks;
__mem_freelist = prev;
- return (void*) (p+1);
+ return (void*)(p + 1);
}
if (p == __mem_freelist)
}
}
-void free(void *ptr)
+void free(void* ptr)
{
block_t* h = BLOCKOF(ptr);
block_t* p;
p = p->next;
}
-
+
/* If we can, merge the next block onto the end of h. */
if ((h + h->size) == p->next)
/* ...and update the ring pointer. */
__mem_freelist = p;
}
-
#include <string.h>
#include "malloc.h"
-void* realloc(void *ptr, size_t size)
+void* realloc(void* ptr, size_t size)
{
block_t* h;
size_t nblocks;
/* Overflow check. */
if (nblocks < size)
return NULL;
-
+
/* Shrinking the block? Don't bother doing anything (it's never worth it). */
if (nblocks <= h->size)
return ptr;
*/
/* $Id$ */
-#include <math.h>
-#include <errno.h>
-#include "localmath.h"
+#include <math.h>
+#include <errno.h>
+#include "localmath.h"
static double
asin_acos(double x, int cosfl)
{
int negative = x < 0;
- int i;
- double g;
+ int i;
+ double g;
static double p[] = {
-0.27368494524164255994e+2,
- 0.57208227877891731407e+2,
+ 0.57208227877891731407e+2,
-0.39688862997540877339e+2,
- 0.10152522233806463645e+2,
+ 0.10152522233806463645e+2,
-0.69674573447350646411e+0
};
static double q[] = {
-0.16421096714498560795e+3,
- 0.41714430248260412556e+3,
+ 0.41714430248260412556e+3,
-0.38186303361750149284e+3,
- 0.15095270841030604719e+3,
+ 0.15095270841030604719e+3,
-0.23823859153670238830e+2,
- 1.0
+ 1.0
};
- if (__IsNan(x)) {
+ if (__IsNan(x))
+ {
errno = EDOM;
return x;
}
- if (negative) {
+ if (negative)
+ {
x = -x;
}
- if (x > 0.5) {
+ if (x > 0.5)
+ {
i = 1;
- if (x > 1) {
+ if (x > 1)
+ {
errno = EDOM;
return 0;
}
g = 0.5 - 0.5 * x;
- x = - sqrt(g);
+ x = -sqrt(g);
x += x;
}
- else {
+ else
+ {
/* ??? avoid underflow ??? */
i = 0;
g = x * x;
}
x += x * g * POLYNOM4(g, p) / POLYNOM5(g, q);
- if (cosfl) {
- if (! negative) x = -x;
+ if (cosfl)
+ {
+ if (!negative)
+ x = -x;
}
- if ((cosfl == 0) == (i == 1)) {
+ if ((cosfl == 0) == (i == 1))
+ {
x = (x + M_PI_4) + M_PI_4;
}
- else if (cosfl && negative && i == 1) {
+ else if (cosfl && negative && i == 1)
+ {
x = (x + M_PI_2) + M_PI_2;
}
- if (! cosfl && negative) x = -x;
+ if (!cosfl && negative)
+ x = -x;
return x;
}
*/
/* $Id$ */
-#include <float.h>
-#include <math.h>
-#include <errno.h>
-#include "localmath.h"
+#include <float.h>
+#include <math.h>
+#include <errno.h>
+#include "localmath.h"
double
atan(double x)
-0.83758299368150059274e+0
};
static double q[] = {
- 0.41066306682575781263e+2,
- 0.86157349597130242515e+2,
- 0.59578436142597344465e+2,
- 0.15024001160028576121e+2,
- 1.0
+ 0.41066306682575781263e+2,
+ 0.86157349597130242515e+2,
+ 0.59578436142597344465e+2,
+ 0.15024001160028576121e+2,
+ 1.0
};
static double a[] = {
0.0,
- 0.52359877559829887307710723554658381, /* pi/6 */
+ 0.52359877559829887307710723554658381, /* pi/6 */
M_PI_2,
- 1.04719755119659774615421446109316763 /* pi/3 */
+ 1.04719755119659774615421446109316763 /* pi/3 */
};
- int neg = x < 0;
- int n;
- double g;
+ int neg = x < 0;
+ int n;
+ double g;
- if (__IsNan(x)) {
+ if (__IsNan(x))
+ {
errno = EDOM;
return x;
}
- if (neg) {
+ if (neg)
+ {
x = -x;
}
- if (x > 1.0) {
- x = 1.0/x;
+ if (x > 1.0)
+ {
+ x = 1.0 / x;
n = 2;
}
- else n = 0;
+ else
+ n = 0;
- if (x > 0.26794919243112270647) { /* 2-sqtr(3) */
+ if (x > 0.26794919243112270647)
+ { /* 2-sqtr(3) */
n = n + 1;
- x = (((0.73205080756887729353*x-0.5)-0.5)+x)/
- (1.73205080756887729353+x);
+ x = (((0.73205080756887729353 * x - 0.5) - 0.5) + x) / (1.73205080756887729353 + x);
}
/* ??? avoid underflow ??? */
g = x * x;
x += x * g * POLYNOM3(g, p) / POLYNOM4(g, q);
- if (n > 1) x = -x;
+ if (n > 1)
+ x = -x;
x += a[n];
return neg ? -x : x;
}
*/
/* $Id$ */
-#include <math.h>
-#include <errno.h>
-#include "localmath.h"
+#include <math.h>
+#include <errno.h>
+#include "localmath.h"
double
atan2(double y, double x)
{
double absx, absy, val;
- if (x == 0 && y == 0) {
+ if (x == 0 && y == 0)
+ {
errno = EDOM;
return 0;
}
absy = y < 0 ? -y : y;
absx = x < 0 ? -x : x;
- if (absy - absx == absy) {
+ if (absy - absx == absy)
+ {
/* x negligible compared to y */
return y < 0 ? -M_PI_2 : M_PI_2;
}
- if (absx - absy == absx) {
+ if (absx - absy == absx)
+ {
/* y negligible compared to x */
val = 0.0;
}
- else val = atan(y/x);
- if (x > 0) {
+ else
+ val = atan(y / x);
+ if (x > 0)
+ {
/* first or fourth quadrant; already correct */
return val;
}
- if (y < 0) {
+ if (y < 0)
+ {
/* third quadrant */
return val - M_PI;
}
*/
/* $Id$ */
-#include <math.h>
+#include <math.h>
double
ceil(double x)
{
double val;
- return modf(x, &val) > 0 ? val + 1.0 : val ;
+ return modf(x, &val) > 0 ? val + 1.0 : val;
/* this also works if modf always returns a positive
fractional part
*/
*/
/* $Id$ */
-#include <math.h>
-#include <float.h>
-#include <errno.h>
-#include "localmath.h"
-
+#include <math.h>
+#include <float.h>
+#include <errno.h>
+#include "localmath.h"
double
exp(double x)
0.63121894374398503557e-3,
0.75104028399870046114e-6
};
- double xn, g;
- int n;
- int negative = x < 0;
+ double xn, g;
+ int n;
+ int negative = x < 0;
- if (__IsNan(x)) {
+ if (__IsNan(x))
+ {
errno = EDOM;
return x;
}
- if (x < M_LN_MIN_D) {
+ if (x < M_LN_MIN_D)
+ {
errno = ERANGE;
return 0.0;
}
- if (x > M_LN_MAX_D) {
+ if (x > M_LN_MAX_D)
+ {
errno = ERANGE;
return HUGE_VAL;
}
- if (negative) x = -x;
-
+ if (negative)
+ x = -x;
+
/* ??? avoid underflow ??? */
- n = x * M_LOG2E + 0.5; /* 1/ln(2) = log2(e), 0.5 added for rounding */
+ n = x * M_LOG2E + 0.5; /* 1/ln(2) = log2(e), 0.5 added for rounding */
xn = n;
{
- double x1 = (long) x;
- double x2 = x - x1;
+ double x1 = (long)x;
+ double x2 = x - x1;
- g = ((x1-xn*0.693359375)+x2) - xn*(-2.1219444005469058277e-4);
+ g = ((x1 - xn * 0.693359375) + x2) - xn * (-2.1219444005469058277e-4);
}
- if (negative) {
+ if (negative)
+ {
g = -g;
n = -n;
}
xn = g * g;
x = g * POLYNOM2(xn, p);
n += 1;
- return (ldexp(0.5 + x/(POLYNOM3(xn, q) - x), n));
+ return (ldexp(0.5 + x / (POLYNOM3(xn, q) - x), n));
}
double
fabs(double x)
{
- return x < 0 ? -x : x;
+ return x < 0 ? -x : x;
}
*/
/* $Id$ */
-#include <math.h>
+#include <math.h>
double
floor(double x)
{
double val;
- return modf(x, &val) < 0 ? val - 1.0 : val ;
+ return modf(x, &val) < 0 ? val - 1.0 : val;
/* this also works if modf always returns a positive
fractional part
*/
#include <math.h>
#include <errno.h>
-double
-(fmod)(double x, double y)
-{ /* compute fmod(x, y) */
+double(fmod)(double x, double y)
+{ /* compute fmod(x, y) */
double t;
int n, neg;
int ychar, xchar;
- if (y == 0.0) {
+ if (y == 0.0)
+ {
errno = EDOM;
return 0.0;
- }
- /* fmod(finite, finite) */
- if (y < 0.0) y = -y;
- if (x < 0.0) x = -x, neg = 1;
- else neg = 0;
+ }
+ /* fmod(finite, finite) */
+ if (y < 0.0)
+ y = -y;
+ if (x < 0.0)
+ x = -x, neg = 1;
+ else
+ neg = 0;
t = frexp(y, &ychar);
- /* substract |y| until |x| < |y| */
+ /* substract |y| until |x| < |y| */
t = frexp(x, &xchar);
- for (n = xchar - ychar; 0 <= n; --n) {
- /* try to substract |y|*2^n */
- t = ldexp(y, n);
- if (t <= x) x -= t;
+ for (n = xchar - ychar; 0 <= n; --n)
+ {
+ /* try to substract |y|*2^n */
+ t = ldexp(y, n);
+ if (t <= x)
+ x -= t;
}
return (neg ? -x : x);
}
/* $Id$ */
double
-hypot(double x,double y)
+hypot(double x, double y)
{
/* Computes sqrt(x*x+y*y), avoiding overflow */
- if (x < 0) x = -x;
- if (y < 0) y = -y;
- if (x > y) {
+ if (x < 0)
+ x = -x;
+ if (y < 0)
+ y = -y;
+ if (x > y)
+ {
double t = y;
y = x;
x = t;
}
/* sqrt(x*x+y*y) = sqrt(y*y*(x*x/(y*y)+1.0)) = y*sqrt(x*x/(y*y)+1.0) */
- if (y == 0.0) return 0.0;
+ if (y == 0.0)
+ return 0.0;
x /= y;
- return y*sqrt(x*x+1.0);
+ return y * sqrt(x * x + 1.0);
}
-struct complex {
- double r,i;
+struct complex
+{
+ double r, i;
};
double
#else
float f = d;
- if ((*((long *) &f) & 0x7f800000) == 0x7f800000 &&
- (*((long *) &f) & 0x007fffff) != 0) return 1;
+ if ((*((long*)&f) & 0x7f800000) == 0x7f800000 && (*((long*)&f) & 0x007fffff) != 0)
+ return 1;
#endif
return 0;
}
*/
/* $Id$ */
-#include <math.h>
-#include <float.h>
-#include <errno.h>
+#include <math.h>
+#include <float.h>
+#include <errno.h>
double
ldexp(double fl, int exp)
int sign = 1;
int currexp;
- if (__IsNan(fl)) {
+ if (__IsNan(fl))
+ {
errno = EDOM;
return fl;
}
- if (fl == 0.0) return 0.0;
- if (fl<0) {
+ if (fl == 0.0)
+ return 0.0;
+ if (fl < 0)
+ {
fl = -fl;
sign = -1;
}
- if (fl > DBL_MAX) { /* for infinity */
+ if (fl > DBL_MAX)
+ { /* for infinity */
errno = ERANGE;
return sign * fl;
}
- fl = frexp(fl,&currexp);
+ fl = frexp(fl, &currexp);
exp += currexp;
- if (exp > 0) {
- if (exp > DBL_MAX_EXP) {
+ if (exp > 0)
+ {
+ if (exp > DBL_MAX_EXP)
+ {
errno = ERANGE;
return sign * HUGE_VAL;
}
- while (exp>30) {
- fl *= (double) (1L << 30);
+ while (exp > 30)
+ {
+ fl *= (double)(1L << 30);
exp -= 30;
}
- fl *= (double) (1L << exp);
+ fl *= (double)(1L << exp);
}
- else {
+ else
+ {
/* number need not be normalized */
- if (exp < DBL_MIN_EXP - DBL_MANT_DIG) {
+ if (exp < DBL_MIN_EXP - DBL_MANT_DIG)
+ {
return 0.0;
}
- while (exp<-30) {
- fl /= (double) (1L << 30);
+ while (exp < -30)
+ {
+ fl /= (double)(1L << 30);
exp += 30;
}
- fl /= (double) (1L << -exp);
+ fl /= (double)(1L << -exp);
}
return sign * fl;
}
*/
/* $Id$ */
-#include <math.h>
-#include <float.h>
-#include <errno.h>
-#include "localmath.h"
+#include <math.h>
+#include <float.h>
+#include <errno.h>
+#include "localmath.h"
double
log(double x)
*/
static double a[] = {
-0.64124943423745581147e2,
- 0.16383943563021534222e2,
+ 0.16383943563021534222e2,
-0.78956112887491257267e0
};
static double b[] = {
-0.76949932108494879777e3,
- 0.31203222091924532844e3,
+ 0.31203222091924532844e3,
-0.35667977739034646171e2,
- 1.0
+ 1.0
};
- double znum, zden, z, w;
- int exponent;
+ double znum, zden, z, w;
+ int exponent;
- if (__IsNan(x)) {
+ if (__IsNan(x))
+ {
errno = EDOM;
return x;
}
- if (x < 0) {
+ if (x < 0)
+ {
errno = EDOM;
return -HUGE_VAL;
}
- else if (x == 0) {
+ else if (x == 0)
+ {
errno = ERANGE;
return -HUGE_VAL;
}
- if (x <= DBL_MAX) {
+ if (x <= DBL_MAX)
+ {
}
- else return x; /* for infinity and Nan */
+ else
+ return x; /* for infinity and Nan */
x = frexp(x, &exponent);
- if (x > M_1_SQRT2) {
+ if (x > M_1_SQRT2)
+ {
znum = (x - 0.5) - 0.5;
zden = x * 0.5 + 0.5;
}
- else {
+ else
+ {
znum = x - 0.5;
zden = znum * 0.5 + 0.5;
exponent--;
}
- z = znum/zden; w = z * z;
- x = z + z * w * (POLYNOM2(w,a)/POLYNOM3(w,b));
+ z = znum / zden;
+ w = z * z;
+ x = z + z * w * (POLYNOM2(w, a) / POLYNOM3(w, b));
z = exponent;
x += z * (-2.121944400546905827679e-4);
return x + z * 0.693359375;
*/
/* $Id$ */
-#include <math.h>
-#include <errno.h>
-#include "localmath.h"
+#include <math.h>
+#include <errno.h>
+#include "localmath.h"
double
log10(double x)
{
- if (__IsNan(x)) {
+ if (__IsNan(x))
+ {
errno = EDOM;
return x;
}
- if (x < 0) {
+ if (x < 0)
+ {
errno = EDOM;
return -HUGE_VAL;
}
- else if (x == 0) {
+ else if (x == 0)
+ {
errno = ERANGE;
return -HUGE_VAL;
}
*/
/* $Id$ */
-#include <math.h>
-#include <float.h>
-#include <errno.h>
-#include <limits.h>
+#include <math.h>
+#include <float.h>
+#include <errno.h>
+#include <limits.h>
double
pow(double x, double y)
{
- double y_intpart, y_fractpart, fp;
- int negexp, negx;
- int ex, newexp;
+ double y_intpart, y_fractpart, fp;
+ int negexp, negx;
+ int ex, newexp;
unsigned long yi;
- if (x == 1.0) return x;
+ if (x == 1.0)
+ return x;
- if (x == 0 && y <= 0) {
+ if (x == 0 && y <= 0)
+ {
errno = EDOM;
return 0;
}
- if (y == 0) return 1.0;
+ if (y == 0)
+ return 1.0;
- if (y < 0) {
+ if (y < 0)
+ {
y = -y;
negexp = 1;
}
- else negexp = 0;
+ else
+ negexp = 0;
y_fractpart = modf(y, &y_intpart);
- if (y_fractpart != 0) {
- if (x < 0) {
+ if (y_fractpart != 0)
+ {
+ if (x < 0)
+ {
errno = EDOM;
return 0;
}
}
negx = 0;
- if (x < 0) {
+ if (x < 0)
+ {
x = -x;
negx = 1;
}
- if (y_intpart > ULONG_MAX) {
- if (negx && modf(y_intpart/2.0, &y_fractpart) == 0) {
+ if (y_intpart > ULONG_MAX)
+ {
+ if (negx && modf(y_intpart / 2.0, &y_fractpart) == 0)
+ {
negx = 0;
}
x = log(x);
/* Beware of overflow in the multiplication */
- if (x > 1.0 && y > DBL_MAX/x) {
+ if (x > 1.0 && y > DBL_MAX / x)
+ {
errno = ERANGE;
return HUGE_VAL;
}
- if (negexp) y = -y;
+ if (negexp)
+ y = -y;
- if (negx) return -exp(x*y);
+ if (negx)
+ return -exp(x * y);
return exp(x * y);
}
- if (y_fractpart != 0) {
+ if (y_fractpart != 0)
+ {
fp = exp(y_fractpart * log(x));
}
- else fp = 1.0;
+ else
+ fp = 1.0;
yi = y_intpart;
- if (! (yi & 1)) negx = 0;
+ if (!(yi & 1))
+ negx = 0;
x = frexp(x, &ex);
newexp = 0;
- for (;;) {
- if (yi & 1) {
+ for (;;)
+ {
+ if (yi & 1)
+ {
fp *= x;
newexp += ex;
}
yi >>= 1;
- if (yi == 0) break;
+ if (yi == 0)
+ break;
x *= x;
ex <<= 1;
- if (x < 0.5) {
+ if (x < 0.5)
+ {
x += x;
ex -= 1;
}
}
- if (negexp) {
- fp = 1.0/fp;
+ if (negexp)
+ {
+ fp = 1.0 / fp;
newexp = -newexp;
}
- if (negx) {
+ if (negx)
+ {
return -ldexp(fp, newexp);
}
return ldexp(fp, newexp);
*/
/* $Id$ */
-#include <math.h>
-#include <float.h>
-#include <errno.h>
-#include "localmath.h"
+#include <math.h>
+#include <float.h>
+#include <errno.h>
+#include "localmath.h"
static double
sinus(double x, int cos_flag)
static double r[] = {
-0.16666666666666665052e+0,
- 0.83333333333331650314e-2,
+ 0.83333333333331650314e-2,
-0.19841269841201840457e-3,
- 0.27557319210152756119e-5,
+ 0.27557319210152756119e-5,
-0.25052106798274584544e-7,
- 0.16058936490371589114e-9,
+ 0.16058936490371589114e-9,
-0.76429178068910467734e-12,
- 0.27204790957888846175e-14
+ 0.27204790957888846175e-14
};
- double y;
- int neg = 1;
+ double y;
+ int neg = 1;
- if (__IsNan(x)) {
+ if (__IsNan(x))
+ {
errno = EDOM;
return x;
}
- if (x < 0) {
+ if (x < 0)
+ {
x = -x;
neg = -1;
}
- if (cos_flag) {
+ if (cos_flag)
+ {
neg = 1;
y = M_PI_2 + x;
}
- else y = x;
+ else
+ y = x;
/* ??? avoid loss of significance, if y is too large, error ??? */
y = y * M_1_PI + 0.5;
- if (y >= DBL_MAX/M_PI) return 0.0;
+ if (y >= DBL_MAX / M_PI)
+ return 0.0;
- /* Use extended precision to calculate reduced argument.
+/* Use extended precision to calculate reduced argument.
Here we used 12 bits of the mantissa for a1.
Also split x in integer part x1 and fraction part x2.
*/
double x1, x2;
modf(y, &y);
- if (modf(0.5*y, &x1)) neg = -neg;
- if (cos_flag) y -= 0.5;
+ if (modf(0.5 * y, &x1))
+ neg = -neg;
+ if (cos_flag)
+ y -= 0.5;
x2 = modf(x, &x1);
x = x1 - y * A1;
x += x2;
#undef A1
#undef A2
}
-
- if (x < 0) {
+
+ if (x < 0)
+ {
neg = -neg;
x = -x;
}
y = x * x;
x += x * y * POLYNOM7(y, r);
- return neg==-1 ? -x : x;
+ return neg == -1 ? -x : x;
}
double
double
cos(double x)
{
- if (x < 0) x = -x;
+ if (x < 0)
+ x = -x;
return sinus(x, 1);
}
*/
/* $Id$ */
-#include <math.h>
-#include <float.h>
-#include <errno.h>
-#include "localmath.h"
+#include <math.h>
+#include <float.h>
+#include <errno.h>
+#include "localmath.h"
static double
sinh_cosh(double x, int cosh_flag)
};
static double q[] = {
-0.21108770058106271242e+7,
- 0.36162723109421836460e+5,
+ 0.36162723109421836460e+5,
-0.27773523119650701167e+3,
- 1.0
+ 1.0
};
- int negative = x < 0;
- double y = negative ? -x : x;
+ int negative = x < 0;
+ double y = negative ? -x : x;
- if (__IsNan(x)) {
+ if (__IsNan(x))
+ {
errno = EDOM;
return x;
}
- if (! cosh_flag && y <= 1.0) {
+ if (!cosh_flag && y <= 1.0)
+ {
/* ??? check for underflow ??? */
y = y * y;
- return x + x * y * POLYNOM3(y, p)/POLYNOM3(y,q);
+ return x + x * y * POLYNOM3(y, p) / POLYNOM3(y, q);
}
- if (y >= M_LN_MAX_D) {
- /* exp(y) would cause overflow */
-#define LNV 0.69316101074218750000e+0
-#define VD2M1 0.52820835025874852469e-4
- double w = y - LNV;
-
- if (w < M_LN_MAX_D+M_LN2-LNV) {
+ if (y >= M_LN_MAX_D)
+ {
+/* exp(y) would cause overflow */
+#define LNV 0.69316101074218750000e+0
+#define VD2M1 0.52820835025874852469e-4
+ double w = y - LNV;
+
+ if (w < M_LN_MAX_D + M_LN2 - LNV)
+ {
x = exp(w);
x += VD2M1 * x;
}
- else {
+ else
+ {
errno = ERANGE;
x = HUGE_VAL;
}
}
- else {
- double z = exp(y);
-
- x = 0.5 * (z + (cosh_flag ? 1.0 : -1.0)/z);
+ else
+ {
+ double z = exp(y);
+
+ x = 0.5 * (z + (cosh_flag ? 1.0 : -1.0) / z);
}
return negative ? -x : x;
}
double
cosh(double x)
{
- if (x < 0) x = -x;
+ if (x < 0)
+ x = -x;
return sinh_cosh(x, 1);
}
*/
/* $Id$ */
-#include <math.h>
-#include <float.h>
-#include <errno.h>
+#include <math.h>
+#include <float.h>
+#include <errno.h>
-#define NITER 5
+#define NITER 5
double
sqrt(double x)
int exponent;
double val;
- if (__IsNan(x)) {
+ if (__IsNan(x))
+ {
errno = EDOM;
return x;
}
- if (x <= 0) {
- if (x < 0) errno = EDOM;
+ if (x <= 0)
+ {
+ if (x < 0)
+ errno = EDOM;
return 0;
}
- if (x > DBL_MAX) return x; /* for infinity */
+ if (x > DBL_MAX)
+ return x; /* for infinity */
val = frexp(x, &exponent);
- if (exponent & 1) {
+ if (exponent & 1)
+ {
exponent--;
val *= 2;
}
- val = ldexp(val + 1.0, exponent/2 - 1);
+ val = ldexp(val + 1.0, exponent / 2 - 1);
/* was: val = (val + 1.0)/2.0; val = ldexp(val, exponent/2); */
- for (exponent = NITER - 1; exponent >= 0; exponent--) {
+ for (exponent = NITER - 1; exponent >= 0; exponent--)
+ {
val = (val + x / val) / 2.0;
}
return val;
*/
/* $Id$ */
-#include <math.h>
-#include <float.h>
-#include <errno.h>
-#include "localmath.h"
+#include <math.h>
+#include <float.h>
+#include <errno.h>
+#include "localmath.h"
double
tan(double x)
int negative = x < 0;
int invert = 0;
- double y;
- static double p[] = {
- 1.0,
+ double y;
+ static double p[] = {
+ 1.0,
-0.13338350006421960681e+0,
- 0.34248878235890589960e-2,
+ 0.34248878235890589960e-2,
-0.17861707342254426711e-4
};
- static double q[] = {
- 1.0,
+ static double q[] = {
+ 1.0,
-0.46671683339755294240e+0,
- 0.25663832289440112864e-1,
+ 0.25663832289440112864e-1,
-0.31181531907010027307e-3,
- 0.49819433993786512270e-6
+ 0.49819433993786512270e-6
};
- if (__IsNan(x)) {
+ if (__IsNan(x))
+ {
errno = EDOM;
return x;
}
- if (negative) x = -x;
-
+ if (negative)
+ x = -x;
+
/* ??? avoid loss of significance, error if x is too large ??? */
y = x * M_2_PI + 0.5;
- if (y >= DBL_MAX/M_PI_2) return 0.0;
+ if (y >= DBL_MAX / M_PI_2)
+ return 0.0;
- /* Use extended precision to calculate reduced argument.
+/* Use extended precision to calculate reduced argument.
Here we used 12 bits of the mantissa for a1.
Also split x in integer part x1 and fraction part x2.
*/
- #define A1 1.57080078125
- #define A2 -4.454455103380768678308e-6
+#define A1 1.57080078125
+#define A2 -4.454455103380768678308e-6
{
double x1, x2;
modf(y, &y);
- if (modf(0.5*y, &x1)) invert = 1;
+ if (modf(0.5 * y, &x1))
+ invert = 1;
x2 = modf(x, &x1);
x = x1 - y * A1;
x += x2;
x -= y * A2;
- #undef A1
- #undef A2
+#undef A1
+#undef A2
}
/* ??? avoid underflow ??? */
y = x * x;
- x += x * y * POLYNOM2(y, p+1);
+ x += x * y * POLYNOM2(y, p + 1);
y = POLYNOM4(y, q);
- if (negative) x = -x;
- return invert ? -y/x : x/y;
+ if (negative)
+ x = -x;
+ return invert ? -y / x : x / y;
}
*/
/* $Id$ */
-#include <float.h>
-#include <math.h>
-#include <errno.h>
-#include "localmath.h"
+#include <float.h>
+#include <math.h>
+#include <errno.h>
+#include "localmath.h"
double
tanh(double x)
-0.96437492777225469787e+0
};
static double q[] = {
- 0.48402357071988688686e+4,
- 0.22337720718962312926e+4,
- 0.11274474380534949335e+3,
- 1.0
+ 0.48402357071988688686e+4,
+ 0.22337720718962312926e+4,
+ 0.11274474380534949335e+3,
+ 1.0
};
- int negative = x < 0;
+ int negative = x < 0;
- if (__IsNan(x)) {
+ if (__IsNan(x))
+ {
errno = EDOM;
return x;
}
- if (negative) x = -x;
+ if (negative)
+ x = -x;
- if (x >= 0.5*M_LN_MAX_D) {
+ if (x >= 0.5 * M_LN_MAX_D)
+ {
x = 1.0;
}
-#define LN3D2 0.54930614433405484570e+0 /* ln(3)/2 */
- else if (x > LN3D2) {
- x = 0.5 - 1.0/(exp(x+x)+1.0);
+#define LN3D2 0.54930614433405484570e+0 /* ln(3)/2 */
+ else if (x > LN3D2)
+ {
+ x = 0.5 - 1.0 / (exp(x + x) + 1.0);
x += x;
}
- else {
+ else
+ {
/* ??? avoid underflow ??? */
- double g = x*x;
- x += x * g * POLYNOM2(g, p)/POLYNOM3(g, q);
+ double g = x * x;
+ x += x * g * POLYNOM2(g, p) / POLYNOM3(g, q);
}
return negative ? -x : x;
}
last edit: 11-Nov-1988 D A Gwyn
*/
-#include <errno.h>
-#include <stdlib.h>
-#include <sys/errno.h>
-#include <sys/types.h>
-#include <dirent.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <sys/errno.h>
+#include <sys/types.h>
+#include <dirent.h>
-typedef void *pointer; /* (void *) if you have it */
+typedef void* pointer; /* (void *) if you have it */
#ifndef NULL
-#define NULL 0
+#define NULL 0
#endif
int _close(int d);
-int
-closedir(register DIR *dirp) /* stream from opendir */
+int closedir(register DIR* dirp) /* stream from opendir */
{
- register int fd;
+ register int fd;
- if ( dirp == NULL || dirp->dd_buf == NULL )
- {
+ if (dirp == NULL || dirp->dd_buf == NULL)
+ {
errno = EFAULT;
- return -1; /* invalid pointer */
- }
+ return -1; /* invalid pointer */
+ }
- fd = dirp->dd_fd; /* bug fix thanks to R. Salz */
- free( (pointer)dirp->dd_buf );
- free( (pointer)dirp );
- return _close( fd );
+ fd = dirp->dd_fd; /* bug fix thanks to R. Salz */
+ free((pointer)dirp->dd_buf);
+ free((pointer)dirp);
+ return _close(fd);
}
to always work, you shouldn't be using this source file at all.
*/
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/errno.h>
-#include <sys/types.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/errno.h>
+#include <sys/types.h>
#ifdef BSD_SYSV
-#include <sys/_dir.h> /* BSD flavor, not System V */
+#include <sys/_dir.h> /* BSD flavor, not System V */
#else
-#if defined(UFS)
-#define DIRSIZ 14 /* 14 char filename in Version 7 */
+#if defined(UFS)
+#define DIRSIZ 14 /* 14 char filename in Version 7 */
#endif
-#define MAXNAMLEN 255
-struct direct {
- off_t d_off; /* offset of next disk directory entry */
- u_long d_fileno; /* file number of entry */
- u_short d_reclen; /* length of this record */
- u_short d_namlen; /* length of string in d_name */
- char d_name[MAXNAMLEN + 1]; /* name (up to MAXNAMLEN + 1) */
+#define MAXNAMLEN 255
+struct direct
+{
+ off_t d_off; /* offset of next disk directory entry */
+ u_long d_fileno; /* file number of entry */
+ u_short d_reclen; /* length of this record */
+ u_short d_namlen; /* length of string in d_name */
+ char d_name[MAXNAMLEN + 1]; /* name (up to MAXNAMLEN + 1) */
};
-#undef MAXNAMLEN /* avoid conflict with SVR3 */
+#undef MAXNAMLEN /* avoid conflict with SVR3 */
-#define d_ino d_fileno /* compatability */
+#define d_ino d_fileno /* compatability */
-#ifdef d_ino /* 4.3BSD/NFS using d_fileno */
-#undef d_ino /* (not absolutely necessary) */
+#ifdef d_ino /* 4.3BSD/NFS using d_fileno */
+#undef d_ino /* (not absolutely necessary) */
#else
-#define d_fileno d_ino /* (struct direct) member */
+#define d_fileno d_ino /* (struct direct) member */
#endif
#endif
-#include <sys/dirent.h>
-#include <sys/stat.h>
+#include <sys/dirent.h>
+#include <sys/stat.h>
#ifdef UNK
#ifndef UFS
-#error UNK applies only to UFS
+#error UNK applies only to UFS
/* One could do something similar for getdirentries(), but I didn't bother. */
#endif
-#include <signal.h>
+#include <signal.h>
#endif
-#if defined(UFS) + defined(BFS) + defined(NFS) != 1 /* sanity check */
-#error exactly one of UFS, BFS, or NFS must be defined
+#if defined(UFS) + defined(BFS) + defined(NFS) != 1 /* sanity check */
+#error exactly one of UFS, BFS, or NFS must be defined
#endif
#ifdef UFS
-#define RecLen( dp ) (sizeof(struct direct)) /* fixed-length entries */
-#else /* BFS || NFS */
-#define RecLen( dp ) ((dp)->d_reclen) /* variable-length entries */
+#define RecLen(dp) (sizeof(struct direct)) /* fixed-length entries */
+#else /* BFS || NFS */
+#define RecLen(dp) ((dp)->d_reclen) /* variable-length entries */
#endif
#ifdef NFS
#ifdef BSD_SYSV
-#define getdirentries _getdirentries /* package hides this system call */
+#define getdirentries _getdirentries /* package hides this system call */
#endif
-extern int getdirentries(int fd, char *buf, int nbytes, long *basep);
-static long dummy; /* getdirentries() needs basep */
-#define GetBlock( fd, buf, n ) getdirentries( fd, buf, (unsigned)n, &dummy )
-#else /* UFS || BFS */
+extern int getdirentries(int fd, char* buf, int nbytes, long* basep);
+static long dummy; /* getdirentries() needs basep */
+#define GetBlock(fd, buf, n) getdirentries(fd, buf, (unsigned)n, &dummy)
+#else /* UFS || BFS */
#ifdef BSD_SYSV
-#define read _read /* avoid emulation overhead */
+#define read _read /* avoid emulation overhead */
#endif
-extern int read();
-#define GetBlock( fd, buf, n ) read( fd, buf, (unsigned)n )
+extern int read();
+#define GetBlock(fd, buf, n) read(fd, buf, (unsigned)n)
#endif
#ifdef UNK
-extern int _getdents(); /* actual system call */
+extern int _getdents(); /* actual system call */
#endif
-extern int _fstat(int fd, struct stat *buf);
-extern off_t _lseek(int d, int offset, int whence);
+extern int _fstat(int fd, struct stat* buf);
+extern off_t _lseek(int d, int offset, int whence);
#ifndef DIRBLKSIZ
-#define DIRBLKSIZ 4096 /* directory file read buffer size */
+#define DIRBLKSIZ 4096 /* directory file read buffer size */
#endif
#ifndef NULL
-#define NULL 0
+#define NULL 0
#endif
#ifndef SEEK_CUR
-#define SEEK_CUR 1
+#define SEEK_CUR 1
#endif
-#ifndef S_ISDIR /* macro to test for directory file */
-#define S_ISDIR( mode ) (((mode) & S_IFMT) == S_IFDIR)
+#ifndef S_ISDIR /* macro to test for directory file */
+#define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR)
#endif
#ifdef UFS
*/
static int
-NameLen( char name[] ) /* return # chars in embedded name */
- /* -> name embedded in struct direct */
+NameLen(char name[]) /* return # chars in embedded name */
+/* -> name embedded in struct direct */
{
- register char *s; /* -> name[.] */
- register char *stop = &name[DIRSIZ]; /* -> past end of name field */
+ register char* s; /* -> name[.] */
+ register char* stop = &name[DIRSIZ]; /* -> past end of name field */
- for ( s = &name[1]; /* (empty names are impossible) */
- *s != '\0' /* not NUL terminator */
- && ++s < stop; /* < DIRSIZ characters scanned */
+ for (s = &name[1]; /* (empty names are impossible) */
+ *s != '\0' /* not NUL terminator */
+ && ++s < stop; /* < DIRSIZ characters scanned */
)
;
- return s - name; /* # valid characters in name */
+ return s - name; /* # valid characters in name */
}
-#else /* BFS || NFS */
+#else /* BFS || NFS */
-#define NameLen( name ) strlen( name ) /* names are always NUL-terminated */
+#define NameLen(name) strlen(name) /* names are always NUL-terminated */
#endif
#ifdef UNK
-static enum { maybe, no, yes } state = maybe;
- /* does _getdents() work? */
+static enum { maybe,
+ no,
+ yes } state
+ = maybe;
+/* does _getdents() work? */
/*ARGSUSED*/
static void
-sig_catch(int sig) /* sig must be SIGSYS */
+sig_catch(int sig) /* sig must be SIGSYS */
{
- state = no; /* attempted _getdents() faulted */
+ state = no; /* attempted _getdents() faulted */
}
#endif
-int
-getdents(int fildes, char *buf, unsigned nbyte) /* returns # bytes read;
+int getdents(int fildes, char* buf, unsigned nbyte) /* returns # bytes read;
0 on EOF, -1 on error */
/* fildes == directory file descriptor */
/* *buf == where to put the (struct dirent)s */
/* nbyte == size of buf[] */
{
- int serrno; /* entry errno */
- off_t offset; /* initial directory file offset */
- struct stat statb; /* fstat() info */
- union {
- char dblk[DIRBLKSIZ];
- /* directory file block buffer */
- struct direct dummy; /* just for alignment */
- } u; /* (avoids having to malloc()) */
- register struct direct *dp; /* -> u.dblk[.] */
- register struct dirent *bp; /* -> buf[.] */
+ int serrno; /* entry errno */
+ off_t offset; /* initial directory file offset */
+ struct stat statb; /* fstat() info */
+ union {
+ char dblk[DIRBLKSIZ];
+ /* directory file block buffer */
+ struct direct dummy; /* just for alignment */
+ } u; /* (avoids having to malloc()) */
+ register struct direct* dp; /* -> u.dblk[.] */
+ register struct dirent* bp; /* -> buf[.] */
#ifdef UNK
- switch ( state )
- {
- void (*shdlr)(); /* entry SIGSYS handler */
- register int retval; /* return from _getdents() if any */
+ switch (state)
+ {
+ void (*shdlr)(); /* entry SIGSYS handler */
+ register int retval; /* return from _getdents() if any */
- case yes: /* _getdents() is known to work */
- return _getdents( fildes, buf, nbyte );
+ case yes: /* _getdents() is known to work */
+ return _getdents(fildes, buf, nbyte);
- case maybe: /* first time only */
- shdlr = signal( SIGSYS, sig_catch );
- retval = _getdents( fildes, buf, nbyte ); /* try it */
- (void)signal( SIGSYS, shdlr );
+ case maybe: /* first time only */
+ shdlr = signal(SIGSYS, sig_catch);
+ retval = _getdents(fildes, buf, nbyte); /* try it */
+ (void)signal(SIGSYS, shdlr);
- if ( state == maybe ) /* SIGSYS did not occur */
+ if (state == maybe) /* SIGSYS did not occur */
{
- state = yes; /* so _getdents() must have worked */
- return retval;
+ state = yes; /* so _getdents() must have worked */
+ return retval;
}
- /* else fall through into emulation */
+ /* else fall through into emulation */
-/* case no:*/ /* fall through into emulation */
- }
+ /* case no:*/ /* fall through into emulation */
+ }
#endif
- if ( buf == NULL
+ if (buf == NULL
#ifdef ATT_SPEC
- || (unsigned long)buf % sizeof(long) != 0 /* ugh */
+ || (unsigned long)buf % sizeof(long) != 0 /* ugh */
#endif
- ) {
- errno = EFAULT; /* invalid pointer */
+ )
+ {
+ errno = EFAULT; /* invalid pointer */
return -1;
- }
+ }
- if ( _fstat( fildes, &statb ) != 0 )
- return -1; /* errno set by fstat() */
+ if (_fstat(fildes, &statb) != 0)
+ return -1; /* errno set by fstat() */
- if ( !S_ISDIR( statb.st_mode ) )
- {
- errno = ENOTDIR; /* not a directory */
+ if (!S_ISDIR(statb.st_mode))
+ {
+ errno = ENOTDIR; /* not a directory */
return -1;
- }
+ }
- if ( (offset = _lseek( fildes, (off_t)0, SEEK_CUR )) < 0 )
- return -1; /* errno set by lseek() */
+ if ((offset = _lseek(fildes, (off_t)0, SEEK_CUR)) < 0)
+ return -1; /* errno set by lseek() */
-#ifdef BFS /* no telling what remote hosts do */
- if ( (unsigned long)offset % DIRBLKSIZ != 0 )
- {
- errno = ENOENT; /* file pointer probably misaligned */
+#ifdef BFS /* no telling what remote hosts do */
+ if ((unsigned long)offset % DIRBLKSIZ != 0)
+ {
+ errno = ENOENT; /* file pointer probably misaligned */
return -1;
- }
+ }
#endif
- serrno = errno; /* save entry errno */
+ serrno = errno; /* save entry errno */
- for ( bp = (struct dirent *)buf; bp == (struct dirent *)buf; )
- { /* convert next directory block */
- int size;
+ for (bp = (struct dirent*)buf; bp == (struct dirent*)buf;)
+ { /* convert next directory block */
+ int size;
- do size = GetBlock( fildes, u.dblk, DIRBLKSIZ );
- while ( size == -1 && errno == EINTR );
+ do
+ size = GetBlock(fildes, u.dblk, DIRBLKSIZ);
+ while (size == -1 && errno == EINTR);
- if ( size <= 0 )
- return size; /* EOF or error (EBADF) */
+ if (size <= 0)
+ return size; /* EOF or error (EBADF) */
- for ( dp = (struct direct *)u.dblk;
- (char *)dp < &u.dblk[size];
- dp = (struct direct *)((char *)dp + RecLen( dp ))
- ) {
+ for (dp = (struct direct*)u.dblk;
+ (char*)dp < &u.dblk[size];
+ dp = (struct direct*)((char*)dp + RecLen(dp)))
+ {
#ifndef UFS
- if ( dp->d_reclen <= 0 )
- {
- errno = EIO; /* corrupted directory */
+ if (dp->d_reclen <= 0)
+ {
+ errno = EIO; /* corrupted directory */
return -1;
- }
+ }
#endif
- if ( dp->d_fileno != 0 )
- { /* non-empty; copy to user buffer */
- register int reclen =
- DIRENTSIZ( NameLen( dp->d_name ) );
+ if (dp->d_fileno != 0)
+ { /* non-empty; copy to user buffer */
+ register int reclen = DIRENTSIZ(NameLen(dp->d_name));
- if ( (char *)bp + reclen > &buf[nbyte] )
- {
+ if ((char*)bp + reclen > &buf[nbyte])
+ {
errno = EINVAL;
- return -1; /* buf too small */
- }
+ return -1; /* buf too small */
+ }
bp->d_ino = dp->d_fileno;
- bp->d_off = offset + ((char *)dp - u.dblk);
+ bp->d_off = offset + ((char*)dp - u.dblk);
bp->d_reclen = reclen;
- (void)strncpy( bp->d_name, dp->d_name,
- reclen - DIRENTBASESIZ
- ); /* adds NUL padding */
+ (void)strncpy(bp->d_name, dp->d_name,
+ reclen - DIRENTBASESIZ); /* adds NUL padding */
- bp = (struct dirent *)((char *)bp + reclen);
- }
+ bp = (struct dirent*)((char*)bp + reclen);
}
+ }
-#ifndef BFS /* 4.2BSD screwed up; fixed in 4.3BSD */
- if ( (char *)dp > &u.dblk[size] )
- {
- errno = EIO; /* corrupted directory */
+#ifndef BFS /* 4.2BSD screwed up; fixed in 4.3BSD */
+ if ((char*)dp > &u.dblk[size])
+ {
+ errno = EIO; /* corrupted directory */
return -1;
- }
-#endif
}
+#endif
+ }
- errno = serrno; /* restore entry errno */
- return (char *)bp - buf; /* return # bytes read */
+ errno = serrno; /* restore entry errno */
+ return (char*)bp - buf; /* return # bytes read */
}
*/
/* $Id$ */
-#include <stdlib.h>
-#include <string.h>
-#include <grp.h>
+#include <stdlib.h>
+#include <string.h>
+#include <grp.h>
-#define O_RDONLY 0
+#define O_RDONLY 0
-int open(const char *path, int flags);
+int open(const char* path, int flags);
-#if defined(__BSD4_2)
-typedef int off_t; /* see lseek(2) */
+#if defined(__BSD4_2)
+typedef int off_t; /* see lseek(2) */
#else
typedef long off_t;
#endif
off_t _lseek(int d, off_t offset, int whence);
-int _read(int d, char *buf, int nbytes);
+int _read(int d, char* buf, int nbytes);
int _close(int d);
-#define RBUFSIZE 1024
+#define RBUFSIZE 1024
static char _gr_file[] = "/etc/group";
static char _grbuf[256];
static char _buffer[RBUFSIZE];
-static char *_pnt;
-static char *_buf;
-static int _gfd = -1;
-static int _bufcnt;
+static char* _pnt;
+static char* _buf;
+static int _gfd = -1;
+static int _bufcnt;
static struct group grp;
-int
-setgrent(void)
+int setgrent(void)
{
- if (_gfd >= 0)
- _lseek(_gfd, 0L, 0);
- else
- _gfd = open(_gr_file, O_RDONLY);
+ if (_gfd >= 0)
+ _lseek(_gfd, 0L, 0);
+ else
+ _gfd = open(_gr_file, O_RDONLY);
- _bufcnt = 0;
- return _gfd;
+ _bufcnt = 0;
+ return _gfd;
}
-void
-endgrent(void)
+void endgrent(void)
{
- if (_gfd >= 0)
- _close(_gfd);
+ if (_gfd >= 0)
+ _close(_gfd);
- _gfd = -1;
- _bufcnt = 0;
+ _gfd = -1;
+ _bufcnt = 0;
}
-
static int
-getline(void)
+getline(void)
{
- if (_gfd < 0 && setgrent() < 0)
- return 0;
-
- _buf = _grbuf;
- do {
- if (--_bufcnt <= 0){
- if ((_bufcnt = _read(_gfd, _buffer, RBUFSIZE)) <= 0)
- return 0;
- else
- _pnt = _buffer;
+ if (_gfd < 0 && setgrent() < 0)
+ return 0;
+
+ _buf = _grbuf;
+ do
+ {
+ if (--_bufcnt <= 0)
+ {
+ if ((_bufcnt = _read(_gfd, _buffer, RBUFSIZE)) <= 0)
+ return 0;
+ else
+ _pnt = _buffer;
}
- *_buf++ = *_pnt++;
- } while (*_pnt != '\n');
- _pnt++;
- _bufcnt--;
- *_buf = 0;
- _buf = _grbuf;
- return 1;
+ *_buf++ = *_pnt++;
+ } while (*_pnt != '\n');
+ _pnt++;
+ _bufcnt--;
+ *_buf = 0;
+ _buf = _grbuf;
+ return 1;
}
static void
-skip_period(void)
+skip_period(void)
{
- while (*_buf && *_buf != ':')
- _buf++;
- *_buf++ = '\0';
+ while (*_buf && *_buf != ':')
+ _buf++;
+ *_buf++ = '\0';
}
-struct group *
-getgrent(void)
+struct group*
+getgrent(void)
{
- if (getline() == 0)
- return 0;
-
- grp.gr_name = _buf;
- skip_period();
- grp.gr_passwd = _buf;
- skip_period();
- grp.gr_gid = atoi(_buf);
- skip_period();
- return &grp;
+ if (getline() == 0)
+ return 0;
+
+ grp.gr_name = _buf;
+ skip_period();
+ grp.gr_passwd = _buf;
+ skip_period();
+ grp.gr_gid = atoi(_buf);
+ skip_period();
+ return &grp;
}
-struct group *
-getgrnam(const char *name)
+struct group*
+getgrnam(const char* name)
{
- struct group *g;
-
- setgrent();
- while ((g = getgrent()) != 0)
- if (!strcmp(g -> gr_name, name))
- break;
- endgrent();
- if (g != 0)
- return g;
- else
- return 0;
+ struct group* g;
+
+ setgrent();
+ while ((g = getgrent()) != 0)
+ if (!strcmp(g->gr_name, name))
+ break;
+ endgrent();
+ if (g != 0)
+ return g;
+ else
+ return 0;
}
-struct group *
+struct group*
getgrgid(int gid)
{
- struct group *g;
-
- setgrent();
- while ((g = getgrent()) != 0)
- if (g -> gr_gid == gid)
- break;
- endgrent();
- if (g != 0)
- return g;
- else
- return 0;
+ struct group* g;
+
+ setgrent();
+ while ((g = getgrent()) != 0)
+ if (g->gr_gid == gid)
+ break;
+ endgrent();
+ if (g != 0)
+ return g;
+ else
+ return 0;
}
*/
/* $Id$ */
-#include <stdio.h>
-#include <string.h>
+#include <stdio.h>
+#include <string.h>
-#define ERR(s, c) if(opterr){\
- fputs(argv[0], stderr);\
- fputs(s, stderr);\
- fputc(c, stderr);\
- fputc('\n', stderr);}
+#define ERR(s, c) \
+ if (opterr) \
+ { \
+ fputs(argv[0], stderr); \
+ fputs(s, stderr); \
+ fputc(c, stderr); \
+ fputc('\n', stderr); \
+ }
-int opterr = 1;
-int optind = 1;
-int optopt;
-char *optarg;
+int opterr = 1;
+int optind = 1;
+int optopt;
+char* optarg;
-int
-getopt(int argc, char **argv, char *opts)
+int getopt(int argc, char** argv, char* opts)
{
static int sp = 1;
register c;
- register char *cp;
+ register char* cp;
if (sp == 1)
- if (optind >= argc ||
- argv[optind][0] != '-' || argv[optind][1] == '\0')
+ if (optind >= argc || argv[optind][0] != '-' || argv[optind][1] == '\0')
return EOF;
- else if (!strcmp(argv[optind], "--")) {
+ else if (!strcmp(argv[optind], "--"))
+ {
optind++;
return EOF;
}
optopt = c = argv[optind][sp];
- if (c == ':' || (cp=strchr(opts, c)) == NULL) {
- ERR (": illegal option -- ", c);
- if (argv[optind][++sp] == '\0') {
+ if (c == ':' || (cp = strchr(opts, c)) == NULL)
+ {
+ ERR(": illegal option -- ", c);
+ if (argv[optind][++sp] == '\0')
+ {
optind++;
sp = 1;
}
return '?';
}
- if (*++cp == ':') {
- if (argv[optind][sp+1] != '\0')
- optarg = &argv[optind++][sp+1];
- else if (++optind >= argc) {
- ERR (": option requires an argument -- ", c);
+ if (*++cp == ':')
+ {
+ if (argv[optind][sp + 1] != '\0')
+ optarg = &argv[optind++][sp + 1];
+ else if (++optind >= argc)
+ {
+ ERR(": option requires an argument -- ", c);
sp = 1;
return '?';
- } else
+ }
+ else
optarg = argv[optind++];
sp = 1;
- } else {
- if (argv[optind][++sp] == '\0') {
+ }
+ else
+ {
+ if (argv[optind][++sp] == '\0')
+ {
sp = 1;
optind++;
}
*/
/* $Id$ */
-#include <stdlib.h>
-#include <signal.h>
-#include <string.h>
-#include <sgtty.h>
-#include <fcntl.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <string.h>
+#include <sgtty.h>
+#include <fcntl.h>
-int _open(const char *path, int flags);
-int _write(int d, const char *buf, int nbytes);
-int _read(int d, char *buf, int nbytes);
+int _open(const char* path, int flags);
+int _write(int d, const char* buf, int nbytes);
+int _read(int d, char* buf, int nbytes);
int _close(int d);
-int _stty(int, struct sgttyb *);
-int _gtty(int, struct sgttyb *);
+int _stty(int, struct sgttyb*);
+int _gtty(int, struct sgttyb*);
-char *
-getpass(const char *prompt)
+char* getpass(const char* prompt)
{
int i = 0;
struct sgttyb tty, ttysave;
int fd;
void (*savesig)(int);
- if ((fd = _open("/dev/tty", O_RDONLY)) < 0) fd = 0;
+ if ((fd = _open("/dev/tty", O_RDONLY)) < 0)
+ fd = 0;
savesig = signal(SIGINT, SIG_IGN);
_write(2, prompt, strlen(prompt));
_gtty(fd, &tty);
pwdbuf[i - 1] = '\0';
_stty(fd, &ttysave);
_write(2, "\n", 1);
- if (fd != 0) _close(fd);
+ if (fd != 0)
+ _close(fd);
signal(SIGINT, savesig);
- return(pwdbuf);
+ return (pwdbuf);
}
*/
/* $Id$ */
-#include <stdio.h>
+#include <stdio.h>
-int getw(register FILE *stream)
+int getw(register FILE* stream)
{
register int cnt = sizeof(int);
int w;
- register char *p = (char *) &w;
+ register char* p = (char*)&w;
- while (cnt--) {
+ while (cnt--)
+ {
*p++ = getc(stream);
}
- if (feof(stream) || ferror(stream)) return EOF;
+ if (feof(stream) || ferror(stream))
+ return EOF;
return w;
}
/* no _-protected system-calls? */
unsigned int getpid(void);
-int access(char *, int);
+int access(char*, int);
-char *mktemp(char *template)
+char* mktemp(char* template)
{
- register int pid, k;
- register char *p;
+ register int pid, k;
+ register char* p;
- pid = getpid(); /* get process id as semi-unique number */
- p = template;
- while (*p) p++; /* find end of string */
+ pid = getpid(); /* get process id as semi-unique number */
+ p = template;
+ while (*p)
+ p++; /* find end of string */
- /* Replace XXXXXX at end of template with pid. */
- while (*--p == 'X') {
- *p = '0' + (pid % 10);
- pid /= 10;
- }
- p++;
- for (k = 'a'; k <= 'z'; k++) {
- *p = k;
- if (access(template, 0) < 0) {
- return template;
+ /* Replace XXXXXX at end of template with pid. */
+ while (*--p == 'X')
+ {
+ *p = '0' + (pid % 10);
+ pid /= 10;
}
- }
- return("/");
+ p++;
+ for (k = 'a'; k <= 'z'; k++)
+ {
+ *p = k;
+ if (access(template, 0) < 0)
+ {
+ return template;
+ }
+ }
+ return ("/");
}
last edit: 16-Jun-1987 D A Gwyn
*/
-#include <errno.h>
-#include <stdlib.h>
-#include <sys/errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <dirent.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <sys/errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>
-typedef void *pointer; /* (void *) if you have it */
+typedef void* pointer; /* (void *) if you have it */
-extern int _open(const char *path, int flags, int mode);
+extern int _open(const char* path, int flags, int mode);
extern int _close(int d);
-extern int _fstat(int fd, struct stat *buf);
+extern int _fstat(int fd, struct stat* buf);
#ifndef NULL
-#define NULL 0
+#define NULL 0
#endif
#ifndef O_RDONLY
-#define O_RDONLY 0
+#define O_RDONLY 0
#endif
-#ifndef S_ISDIR /* macro to test for directory file */
-#define S_ISDIR( mode ) (((mode) & S_IFMT) == S_IFDIR)
+#ifndef S_ISDIR /* macro to test for directory file */
+#define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR)
#endif
-DIR *
-opendir(const char *dirname) /* name of directory */
+DIR* opendir(const char* dirname) /* name of directory */
{
- register DIR *dirp; /* -> malloc'ed storage */
- register int fd; /* file descriptor for read */
- struct stat sbuf; /* result of fstat() */
+ register DIR* dirp; /* -> malloc'ed storage */
+ register int fd; /* file descriptor for read */
+ struct stat sbuf; /* result of fstat() */
- if ( (fd = _open( dirname, O_RDONLY, 0 )) < 0 )
- return NULL; /* errno set by open() */
+ if ((fd = _open(dirname, O_RDONLY, 0)) < 0)
+ return NULL; /* errno set by open() */
- if ( _fstat( fd, &sbuf ) != 0 || !S_ISDIR( sbuf.st_mode ) )
- {
- (void)_close( fd );
+ if (_fstat(fd, &sbuf) != 0 || !S_ISDIR(sbuf.st_mode))
+ {
+ (void)_close(fd);
errno = ENOTDIR;
- return NULL; /* not a directory */
- }
+ return NULL; /* not a directory */
+ }
- if ( (dirp = (DIR *)malloc( sizeof(DIR) )) == NULL
- || (dirp->dd_buf = (char *)malloc( (unsigned)DIRBUF )) == NULL
- ) {
- register int serrno = errno;
- /* errno set to ENOMEM by sbrk() */
+ if ((dirp = (DIR*)malloc(sizeof(DIR))) == NULL
+ || (dirp->dd_buf = (char*)malloc((unsigned)DIRBUF)) == NULL)
+ {
+ register int serrno = errno;
+ /* errno set to ENOMEM by sbrk() */
- if ( dirp != NULL )
- free( (pointer)dirp );
+ if (dirp != NULL)
+ free((pointer)dirp);
- (void)_close( fd );
+ (void)_close(fd);
errno = serrno;
- return NULL; /* not enough memory */
- }
+ return NULL; /* not enough memory */
+ }
dirp->dd_fd = fd;
- dirp->dd_loc = dirp->dd_size = 0; /* refill needed */
+ dirp->dd_loc = dirp->dd_size = 0; /* refill needed */
return dirp;
}
*/
/* $Id$ */
-#include <errno.h>
-#include <stdio.h>
-#include <signal.h>
-#if defined(__BSD4_2)
+#include <errno.h>
+#include <stdio.h>
+#include <signal.h>
+#if defined(__BSD4_2)
union wait {
- int w_status;
+ int w_status;
};
typedef union wait wait_arg;
#else
typedef int wait_arg;
-#endif /* __BSD4_2 */
-#include "../stdio/loc_incl.h"
+#endif /* __BSD4_2 */
+#include "../stdio/loc_incl.h"
int _close(int d);
#if defined(__USG)
static
#endif
-int _dup2(int oldd, int newd); /* not present in System 5 */
-int _execl(const char *name, ... );
+ int
+ _dup2(int oldd, int newd); /* not present in System 5 */
+int _execl(const char* name, ...);
int _fork(void);
int _pipe(int fildes[2]);
-int _wait(wait_arg *status);
+int _wait(wait_arg* status);
void _exit(int status);
static int pids[FOPEN_MAX];
-FILE *
-popen(const char *command, const char *type)
+FILE* popen(const char* command, const char* type)
{
int piped[2];
int Xtype = *type == 'r' ? 0 : *type == 'w' ? 1 : 2;
int pid;
- if (Xtype == 2 ||
- _pipe(piped) < 0 ||
- (pid = _fork()) < 0) return 0;
-
- if (pid == 0) {
+ if (Xtype == 2 || _pipe(piped) < 0 || (pid = _fork()) < 0)
+ return 0;
+
+ if (pid == 0)
+ {
/* child */
- register int *p;
+ register int* p;
- for (p = pids; p < &pids[ FOPEN_MAX]; p++) {
- if (*p) _close(p - pids);
+ for (p = pids; p < &pids[FOPEN_MAX]; p++)
+ {
+ if (*p)
+ _close(p - pids);
}
_close(piped[Xtype]);
_dup2(piped[!Xtype], !Xtype);
_close(piped[!Xtype]);
- _execl("/bin/sh", "sh", "-c", command, (char *) 0);
- _exit(127); /* like system() ??? */
+ _execl("/bin/sh", "sh", "-c", command, (char*)0);
+ _exit(127); /* like system() ??? */
}
pids[piped[Xtype]] = pid;
return fdopen(piped[Xtype], type);
}
-#if defined(__BSD4_2)
-#define ret_val status.w_status
+#if defined(__BSD4_2)
+#define ret_val status.w_status
#else
-#define ret_val status
+#define ret_val status
#endif
-int
-pclose(FILE *stream)
+int pclose(FILE* stream)
{
int fd = fileno(stream);
wait_arg status;
void (*quitsave)(int) = signal(SIGQUIT, SIG_IGN);
fclose(stream);
- while ((wret = _wait(&status)) != -1) {
- if (wret == pids[fd]) break;
+ while ((wret = _wait(&status)) != -1)
+ {
+ if (wret == pids[fd])
+ break;
}
- if (wret == -1) ret_val = -1;
+ if (wret == -1)
+ ret_val = -1;
signal(SIGINT, intsave);
signal(SIGQUIT, quitsave);
pids[fd] = 0;
return ret_val;
}
-#if defined(__USG)
+#if defined(__USG)
int _dup(int fildes);
static int
int fdbuf[FOPEN_MAX];
/* ignore the error on the close() */
- tmp = errno; (void) _close(newd); errno = tmp;
- while ((fd = _dup(oldd)) != newd) {
- if (fd == -1) break;
+ tmp = errno;
+ (void)_close(newd);
+ errno = tmp;
+ while ((fd = _dup(oldd)) != newd)
+ {
+ if (fd == -1)
+ break;
fdbuf[i++] = fd;
}
tmp = errno;
- while (--i >= 0) {
+ while (--i >= 0)
+ {
_close(fdbuf[i]);
}
errno = tmp;
return -(fd == -1);
}
-#endif /* __USG */
+#endif /* __USG */
*/
/* $Id$ */
-#include <stdio.h>
+#include <stdio.h>
-int
-putw(int w, register FILE *stream)
+int putw(int w, register FILE* stream)
{
register int cnt = sizeof(int);
- register char *p = (char *) &w;
+ register char* p = (char*)&w;
- while (cnt--) {
+ while (cnt--)
+ {
putc(*p++, stream);
}
- if (ferror(stream)) return EOF;
+ if (ferror(stream))
+ return EOF;
return w;
}
last edit: 25-Apr-1987 D A Gwyn
*/
-#include <errno.h>
-#include <sys/errno.h>
-#include <sys/types.h>
-#include <dirent.h>
+#include <errno.h>
+#include <sys/errno.h>
+#include <sys/types.h>
+#include <dirent.h>
/* SVR3 system call, or emulation for getdents() */
-extern int getdents(int fildes, char *buf, unsigned nbyte);
+extern int getdents(int fildes, char* buf, unsigned nbyte);
#ifndef NULL
-#define NULL 0
+#define NULL 0
#endif
-struct dirent *
-readdir(register DIR *dirp)
+struct dirent*
+readdir(register DIR* dirp)
{
- register struct dirent *dp; /* -> directory data */
+ register struct dirent* dp; /* -> directory data */
- if ( dirp == NULL || dirp->dd_buf == NULL )
- {
+ if (dirp == NULL || dirp->dd_buf == NULL)
+ {
errno = EFAULT;
- return NULL; /* invalid pointer */
- }
+ return NULL; /* invalid pointer */
+ }
- do {
- if ( dirp->dd_loc >= dirp->dd_size ) /* empty or obsolete */
+ do
+ {
+ if (dirp->dd_loc >= dirp->dd_size) /* empty or obsolete */
dirp->dd_loc = dirp->dd_size = 0;
- if ( dirp->dd_size == 0 /* need to refill buffer */
- && (dirp->dd_size =
- getdents( dirp->dd_fd, dirp->dd_buf, (unsigned)DIRBUF )
- ) <= 0
- )
- return NULL; /* EOF or error */
+ if (dirp->dd_size == 0 /* need to refill buffer */
+ && (dirp->dd_size = getdents(dirp->dd_fd, dirp->dd_buf, (unsigned)DIRBUF)) <= 0)
+ return NULL; /* EOF or error */
- dp = (struct dirent *)&dirp->dd_buf[dirp->dd_loc];
+ dp = (struct dirent*)&dirp->dd_buf[dirp->dd_loc];
dirp->dd_loc += dp->d_reclen;
- }
- while ( dp->d_ino == 0L ); /* don't rely on getdents() */
+ } while (dp->d_ino == 0L); /* don't rely on getdents() */
return dp;
}
rewinddir() to forget about buffered data.
*/
-#include <errno.h>
-#include <sys/errno.h>
-#include <sys/types.h>
-#include <dirent.h>
+#include <errno.h>
+#include <sys/errno.h>
+#include <sys/types.h>
+#include <dirent.h>
-extern off_t _lseek(int d, int offset, int whence);
+extern off_t _lseek(int d, int offset, int whence);
#ifndef NULL
-#define NULL 0
+#define NULL 0
#endif
#ifndef SEEK_SET
-#define SEEK_SET 0
+#define SEEK_SET 0
#endif
-void
-rewinddir(register DIR *dirp)
+void rewinddir(register DIR* dirp)
{
- if ( dirp == NULL || dirp->dd_buf == NULL )
- {
+ if (dirp == NULL || dirp->dd_buf == NULL)
+ {
errno = EFAULT;
- return; /* invalid pointer */
- }
+ return; /* invalid pointer */
+ }
- dirp->dd_loc = dirp->dd_size = 0; /* invalidate buffer */
- (void)_lseek( dirp->dd_fd, (off_t)0, SEEK_SET ); /* may set errno */
+ dirp->dd_loc = dirp->dd_size = 0; /* invalidate buffer */
+ (void)_lseek(dirp->dd_fd, (off_t)0, SEEK_SET); /* may set errno */
}
practically impossible to do right. Avoid using them!
*/
-#include <errno.h>
-#include <sys/errno.h>
-#include <sys/types.h>
-#include <dirent.h>
+#include <errno.h>
+#include <sys/errno.h>
+#include <sys/types.h>
+#include <dirent.h>
extern off_t _lseek(int d, int offset, int whence);
#ifndef NULL
-#define NULL 0
+#define NULL 0
#endif
#ifndef SEEK_SET
-#define SEEK_SET 0
+#define SEEK_SET 0
#endif
-typedef int bool; /* Boolean data type */
-#define false 0
-#define true 1
+typedef int bool; /* Boolean data type */
+#define false 0
+#define true 1
-void
-seekdir(register DIR *dirp, register off_t loc)
+void seekdir(register DIR* dirp, register off_t loc)
/* loc == position from telldir() */
{
- register bool rewind; /* "start over when stymied" flag */
+ register bool rewind; /* "start over when stymied" flag */
- if ( dirp == NULL || dirp->dd_buf == NULL )
- {
+ if (dirp == NULL || dirp->dd_buf == NULL)
+ {
errno = EFAULT;
- return; /* invalid pointer */
- }
+ return; /* invalid pointer */
+ }
/* A (struct dirent)'s d_off is an invented quantity on 4.nBSD
NFS-supporting systems, so it is not safe to lseek() to it. */
or even to use binary search on the directory blocks. I
doubt that the extra code for that would be worthwhile. */
- if ( dirp->dd_loc >= dirp->dd_size /* invalid index */
- || ((struct dirent *)&dirp->dd_buf[dirp->dd_loc])->d_off > loc
- /* too far along in buffer */
- )
- dirp->dd_loc = 0; /* reset to beginning of buffer */
+ if (dirp->dd_loc >= dirp->dd_size /* invalid index */
+ || ((struct dirent*)&dirp->dd_buf[dirp->dd_loc])->d_off > loc
+ /* too far along in buffer */
+ )
+ dirp->dd_loc = 0; /* reset to beginning of buffer */
/* else save time by starting at current dirp->dd_loc */
- for ( rewind = true; ; )
- {
- register struct dirent *dp;
+ for (rewind = true;;)
+ {
+ register struct dirent* dp;
/* See whether the matching entry is in the current buffer. */
- if ( (dirp->dd_loc < dirp->dd_size /* valid index */
- || readdir( dirp ) != NULL /* next buffer read */
- && (dirp->dd_loc = 0, true) /* beginning of buffer set */
- )
- && (dp = (struct dirent *)&dirp->dd_buf[dirp->dd_loc])->d_off
- <= loc /* match possible in this buffer */
- ) {
- for ( /* dp initialized above */ ;
- (char *)dp < &dirp->dd_buf[dirp->dd_size];
- dp = (struct dirent *)((char *)dp + dp->d_reclen)
- )
- if ( dp->d_off == loc )
- { /* found it! */
- dirp->dd_loc =
- (char *)dp - dirp->dd_buf;
+ if ((dirp->dd_loc < dirp->dd_size /* valid index */
+ || readdir(dirp) != NULL /* next buffer read */
+ && (dirp->dd_loc = 0, true) /* beginning of buffer set */
+ )
+ && (dp = (struct dirent*)&dirp->dd_buf[dirp->dd_loc])->d_off
+ <= loc /* match possible in this buffer */
+ )
+ {
+ for (/* dp initialized above */;
+ (char*)dp < &dirp->dd_buf[dirp->dd_size];
+ dp = (struct dirent*)((char*)dp + dp->d_reclen))
+ if (dp->d_off == loc)
+ { /* found it! */
+ dirp->dd_loc = (char*)dp - dirp->dd_buf;
return;
- }
-
- rewind = false; /* no point in backing up later */
- dirp->dd_loc = dirp->dd_size; /* set end of buffer */
- }
- else /* whole buffer past matching entry */
- if ( !rewind )
- { /* no point in searching further */
- errno = EINVAL;
- return; /* no entry at specified loc */
}
- else { /* rewind directory and start over */
- rewind = false; /* but only once! */
- dirp->dd_loc = dirp->dd_size = 0;
+ rewind = false; /* no point in backing up later */
+ dirp->dd_loc = dirp->dd_size; /* set end of buffer */
+ }
+ else /* whole buffer past matching entry */
+ if (!rewind)
+ { /* no point in searching further */
+ errno = EINVAL;
+ return; /* no entry at specified loc */
+ }
+ else
+ { /* rewind directory and start over */
+ rewind = false; /* but only once! */
- if ( _lseek( dirp->dd_fd, (off_t)0, SEEK_SET )
- != 0
- )
- return; /* errno already set (EBADF) */
+ dirp->dd_loc = dirp->dd_size = 0;
- if ( loc == 0 )
- return; /* save time */
- }
+ if (_lseek(dirp->dd_fd, (off_t)0, SEEK_SET)
+ != 0)
+ return; /* errno already set (EBADF) */
+
+ if (loc == 0)
+ return; /* save time */
}
+ }
}
*/
/* $Id$ */
-#include <signal.h>
-#include <setjmp.h>
+#include <signal.h>
+#include <setjmp.h>
int _alarm(int n);
void _pause(void);
-static jmp_buf setjmpbuf;
+static jmp_buf setjmpbuf;
static void
alfun(int sig)
{
longjmp(setjmpbuf, 1);
-} /* used with sleep() below */
+} /* used with sleep() below */
-void
-sleep(int n)
+void sleep(int n)
{
-/* sleep(n) pauses for 'n' seconds by scheduling an alarm interrupt. */
+ /* sleep(n) pauses for 'n' seconds by scheduling an alarm interrupt. */
unsigned oldalarm = 0;
void (*oldsig)(int) = 0;
- if (n <= 0) return;
- if (setjmp(setjmpbuf)) {
+ if (n <= 0)
+ return;
+ if (setjmp(setjmpbuf))
+ {
signal(SIGALRM, oldsig);
_alarm(oldalarm);
return;
}
- oldalarm = _alarm(5000); /* Who cares how long, as long
+ oldalarm = _alarm(5000); /* Who cares how long, as long
* as it is long enough
*/
- if (oldalarm > n) oldalarm -= n;
- else if (oldalarm) {
+ if (oldalarm > n)
+ oldalarm -= n;
+ else if (oldalarm)
+ {
n = oldalarm;
oldalarm = 1;
}
oldsig = signal(SIGALRM, alfun);
_alarm(n);
- for (;;) {
+ for (;;)
+ {
/* allow for other handlers ... */
_pause();
}
practically impossible to do right. Avoid using them!
*/
-#include <errno.h>
-#include <sys/errno.h>
-#include <sys/types.h>
-#include <dirent.h>
+#include <errno.h>
+#include <sys/errno.h>
+#include <sys/types.h>
+#include <dirent.h>
extern off_t _lseek(int d, int offset, int whence);
#ifndef SEEK_CUR
-#define SEEK_CUR 1
+#define SEEK_CUR 1
#endif
-off_t
-telldir(register DIR *dirp) /* return offset of next entry */
+off_t telldir(register DIR* dirp) /* return offset of next entry */
{
- if ( dirp == NULL || dirp->dd_buf == NULL )
- {
+ if (dirp == NULL || dirp->dd_buf == NULL)
+ {
errno = EFAULT;
- return -1; /* invalid pointer */
- }
+ return -1; /* invalid pointer */
+ }
- if ( dirp->dd_loc < dirp->dd_size ) /* valid index */
- return ((struct dirent *)&dirp->dd_buf[dirp->dd_loc])->d_off;
- else /* beginning of next directory block */
- return _lseek( dirp->dd_fd, (off_t)0, SEEK_CUR );
+ if (dirp->dd_loc < dirp->dd_size) /* valid index */
+ return ((struct dirent*)&dirp->dd_buf[dirp->dd_loc])->d_off;
+ else /* beginning of next directory block */
+ return _lseek(dirp->dd_fd, (off_t)0, SEEK_CUR);
}
*/
/* $Id$ */
-#if defined(_POSIX_SOURCE)
+#if defined(_POSIX_SOURCE)
/* This can't be done in setjmp.e, since SIG_SETMASK is defined in
* <signal.h>. This is a C-file, which can't be included.
*/
-#include <sys/types.h>
-#include <signal.h>
-#include <stddef.h>
+#include <sys/types.h>
+#include <signal.h>
+#include <stddef.h>
-int _sigprocmask(int, sigset_t *, sigset_t *);
+int _sigprocmask(int, sigset_t*, sigset_t*);
static void
-__testsigset(void) {
+__testsigset(void)
+{
/* This switch compiles when a sigset_t has the right size. */
- switch(0) {
- case 0:
- case sizeof(sigset_t) <= sizeof(long): break;
+ switch (0)
+ {
+ case 0:
+ case sizeof(sigset_t) <= sizeof(long):
+ break;
}
}
-void
-__newsigset(sigset_t *p)
+void __newsigset(sigset_t* p)
{
/* The SIG_SETMASK is not significant */
_sigprocmask(SIG_SETMASK, NULL, p);
}
-void
-__oldsigset(sigset_t *p)
+void __oldsigset(sigset_t* p)
{
_sigprocmask(SIG_SETMASK, p, NULL);
}
-#endif /* _POSIX_SOURCE */
+#endif /* _POSIX_SOURCE */
*/
/* $Id$ */
-#if defined(_POSIX_SOURCE)
+#if defined(_POSIX_SOURCE)
#include <sys/types.h>
#endif
#include <signal.h>
-int
-raise(int sig)
+int raise(int sig)
{
if (sig < 0 || sig > _NSIG)
return -1;
*/
/* $Id$ */
-#include <stdio.h>
+#include <stdio.h>
-void
-(clearerr)(FILE *stream)
+void(clearerr)(FILE* stream)
{
clearerr(stream);
}
*/
/* $Id$ */
-#include <stdio.h>
+#include <stdio.h>
struct __iobuf __stdin = {
0, 0, _IOREAD, 0,
- (unsigned char *)NULL, (unsigned char *)NULL,
+ (unsigned char*)NULL, (unsigned char*)NULL,
};
struct __iobuf __stdout = {
0, 1, _IOWRITE, 0,
- (unsigned char *)NULL, (unsigned char *)NULL,
+ (unsigned char*)NULL, (unsigned char*)NULL,
};
struct __iobuf __stderr = {
0, 2, _IOWRITE | _IOLBF, 0,
- (unsigned char *)NULL, (unsigned char *)NULL,
+ (unsigned char*)NULL, (unsigned char*)NULL,
};
-FILE *__iotab[FOPEN_MAX] = {
+FILE* __iotab[FOPEN_MAX] = {
&__stdin,
&__stdout,
&__stderr,
*/
/* $Id$ */
-#include <ctype.h>
-#include <stdio.h>
-#include <stdarg.h>
-#include <string.h>
-#include "loc_incl.h"
+#include <ctype.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+#include "loc_incl.h"
/* gnum() is used to get the width and precision fields of a format. */
-static const char *
-gnum(register const char *f, int *ip, va_list *app)
+static const char*
+gnum(register const char* f, int* ip, va_list* app)
{
- register int i, c;
+ register int i, c;
- if (*f == '*') {
+ if (*f == '*')
+ {
*ip = va_arg((*app), int);
f++;
- } else {
+ }
+ else
+ {
i = 0;
- while ((c = *f - '0') >= 0 && c <= 9) {
- i = i*10 + c;
+ while ((c = *f - '0') >= 0 && c <= 9)
+ {
+ i = i * 10 + c;
f++;
}
*ip = i;
return f;
}
-#if _EM_WSIZE == _EM_PSIZE
-#define set_pointer(flags) /* nothing */
-#elif _EM_LSIZE == _EM_PSIZE
-#define set_pointer(flags) (flags |= FL_LONG)
+#if _EM_WSIZE == _EM_PSIZE
+#define set_pointer(flags) /* nothing */
+#elif _EM_LSIZE == _EM_PSIZE
+#define set_pointer(flags) (flags |= FL_LONG)
#else
#error garbage pointer size
-#define set_pointer(flags) /* compilation might continue */
+#define set_pointer(flags) /* compilation might continue */
#endif
-#define PUTC(c) \
- do { \
+#define PUTC(c) \
+ do \
+ { \
int i = putc(c, stream); \
- if (i == EOF) \
- { \
- if (ferror(stream)) \
- return -1; \
- } \
+ if (i == EOF) \
+ { \
+ if (ferror(stream)) \
+ return -1; \
+ } \
} while (0)
/* print an ordinal number */
-static char *
-o_print(va_list *ap, int flags, char *s, char c, int precision, int is_signed)
+static char*
+o_print(va_list* ap, int flags, char* s, char c, int precision, int is_signed)
{
long signed_val;
unsigned long unsigned_val;
- char *old_s = s;
+ char* old_s = s;
int base;
- switch (flags & (FL_SHORT | FL_LONG)) {
- case FL_SHORT:
- if (is_signed) {
- signed_val = (short) va_arg(*ap, int);
- } else {
- unsigned_val = (unsigned short) va_arg(*ap, unsigned);
- }
- break;
- case FL_LONG:
- if (is_signed) {
- signed_val = va_arg(*ap, long);
- } else {
- unsigned_val = va_arg(*ap, unsigned long);
- }
- break;
- default:
- if (is_signed) {
- signed_val = va_arg(*ap, int);
- } else {
- unsigned_val = va_arg(*ap, unsigned int);
- }
- break;
+ switch (flags & (FL_SHORT | FL_LONG))
+ {
+ case FL_SHORT:
+ if (is_signed)
+ {
+ signed_val = (short)va_arg(*ap, int);
+ }
+ else
+ {
+ unsigned_val = (unsigned short)va_arg(*ap, unsigned);
+ }
+ break;
+ case FL_LONG:
+ if (is_signed)
+ {
+ signed_val = va_arg(*ap, long);
+ }
+ else
+ {
+ unsigned_val = va_arg(*ap, unsigned long);
+ }
+ break;
+ default:
+ if (is_signed)
+ {
+ signed_val = va_arg(*ap, int);
+ }
+ else
+ {
+ unsigned_val = va_arg(*ap, unsigned int);
+ }
+ break;
}
- if (is_signed) {
- if (signed_val < 0) {
+ if (is_signed)
+ {
+ if (signed_val < 0)
+ {
*s++ = '-';
signed_val = -signed_val;
- } else if (flags & FL_SIGN) *s++ = '+';
- else if (flags & FL_SPACE) *s++ = ' ';
+ }
+ else if (flags & FL_SIGN)
+ *s++ = '+';
+ else if (flags & FL_SPACE)
+ *s++ = ' ';
unsigned_val = signed_val;
}
- if ((flags & FL_ALT) && (c == 'o')) *s++ = '0';
- if (!unsigned_val) {
- if (!precision)
+ if ((flags & FL_ALT) && (c == 'o'))
+ *s++ = '0';
+ if (!unsigned_val)
+ {
+ if (!precision)
return s;
- } else if (((flags & FL_ALT) && (c == 'x' || c == 'X'))
- || c == 'p') {
+ }
+ else if (((flags & FL_ALT) && (c == 'x' || c == 'X'))
+ || c == 'p')
+ {
*s++ = '0';
*s++ = (c == 'X' ? 'X' : 'x');
}
- switch (c) {
- case 'b': base = 2; break;
- case 'o': base = 8; break;
- case 'd':
- case 'i':
- case 'u': base = 10; break;
- case 'x':
- case 'X':
- case 'p': base = 16; break;
+ switch (c)
+ {
+ case 'b':
+ base = 2;
+ break;
+ case 'o':
+ base = 8;
+ break;
+ case 'd':
+ case 'i':
+ case 'u':
+ base = 10;
+ break;
+ case 'x':
+ case 'X':
+ case 'p':
+ base = 16;
+ break;
}
s = _i_compute(unsigned_val, base, s, precision);
if (c == 'X')
- while (old_s != s) {
+ while (old_s != s)
+ {
*old_s = toupper(*old_s);
old_s++;
}
return s;
}
-int
-_doprnt(register const char *fmt, va_list ap, FILE *stream)
+int _doprnt(register const char* fmt, va_list ap, FILE* stream)
{
- register char *s;
- register int j;
- int i, c, width, precision, zfill, flags, between_fill;
- int nrchars=0;
- const char *oldfmt;
- char *s1, buf[1025];
+ register char* s;
+ register int j;
+ int i, c, width, precision, zfill, flags, between_fill;
+ int nrchars = 0;
+ const char* oldfmt;
+ char *s1, buf[1025];
- while (c = *fmt++) {
- if (c != '%') {
-#ifdef CPM
- if (c == '\n') {
+ while (c = *fmt++)
+ {
+ if (c != '%')
+ {
+#ifdef CPM
+ if (c == '\n')
+ {
PUTC('\r');
}
#endif
continue;
}
flags = 0;
- do {
- switch(*fmt) {
- case '-': flags |= FL_LJUST; break;
- case '+': flags |= FL_SIGN; break;
- case ' ': flags |= FL_SPACE; break;
- case '#': flags |= FL_ALT; break;
- case '0': flags |= FL_ZEROFILL; break;
- default: flags |= FL_NOMORE; continue;
+ do
+ {
+ switch (*fmt)
+ {
+ case '-':
+ flags |= FL_LJUST;
+ break;
+ case '+':
+ flags |= FL_SIGN;
+ break;
+ case ' ':
+ flags |= FL_SPACE;
+ break;
+ case '#':
+ flags |= FL_ALT;
+ break;
+ case '0':
+ flags |= FL_ZEROFILL;
+ break;
+ default:
+ flags |= FL_NOMORE;
+ continue;
}
fmt++;
- } while(!(flags & FL_NOMORE));
+ } while (!(flags & FL_NOMORE));
oldfmt = fmt;
fmt = gnum(fmt, &width, &ap);
- if (fmt != oldfmt) flags |= FL_WIDTHSPEC;
+ if (fmt != oldfmt)
+ flags |= FL_WIDTHSPEC;
- if (*fmt == '.') {
- fmt++; oldfmt = fmt;
+ if (*fmt == '.')
+ {
+ fmt++;
+ oldfmt = fmt;
fmt = gnum(fmt, &precision, &ap);
- if (precision >= 0) flags |= FL_PRECSPEC;
+ if (precision >= 0)
+ flags |= FL_PRECSPEC;
}
- if ((flags & FL_WIDTHSPEC) && width < 0) {
+ if ((flags & FL_WIDTHSPEC) && width < 0)
+ {
width = -width;
flags |= FL_LJUST;
}
- if (!(flags & FL_WIDTHSPEC)) width = 0;
-
- if (flags & FL_SIGN) flags &= ~FL_SPACE;
+ if (!(flags & FL_WIDTHSPEC))
+ width = 0;
- if (flags & FL_LJUST) flags &= ~FL_ZEROFILL;
+ if (flags & FL_SIGN)
+ flags &= ~FL_SPACE;
+ if (flags & FL_LJUST)
+ flags &= ~FL_ZEROFILL;
s = s1 = buf;
- switch (*fmt) {
- case 'h': flags |= FL_SHORT; fmt++; break;
- case 'l': flags |= FL_LONG; fmt++; break;
- case 'L': flags |= FL_LONGDOUBLE; fmt++; break;
+ switch (*fmt)
+ {
+ case 'h':
+ flags |= FL_SHORT;
+ fmt++;
+ break;
+ case 'l':
+ flags |= FL_LONG;
+ fmt++;
+ break;
+ case 'L':
+ flags |= FL_LONGDOUBLE;
+ fmt++;
+ break;
}
- switch (c = *fmt++) {
- default:
-#ifdef CPM
- if (c == '\n') {
- PUTC('\r');
- nrchars++;
- }
+ switch (c = *fmt++)
+ {
+ default:
+#ifdef CPM
+ if (c == '\n')
+ {
+ PUTC('\r');
+ nrchars++;
+ }
#endif
- PUTC(c);
- nrchars++;
- continue;
- case 'n':
- if (flags & FL_SHORT)
- *va_arg(ap, short *) = (short) nrchars;
- else if (flags & FL_LONG)
- *va_arg(ap, long *) = (long) nrchars;
- else
- *va_arg(ap, int *) = (int) nrchars;
- continue;
- case 's':
- s1 = va_arg(ap, char *);
- if (s1 == NULL)
- s1 = "(null)";
- s = s1;
- while (precision || !(flags & FL_PRECSPEC)) {
- if (*s == '\0')
- break;
- s++;
- precision--;
- }
- break;
- case 'p':
- set_pointer(flags);
+ PUTC(c);
+ nrchars++;
+ continue;
+ case 'n':
+ if (flags & FL_SHORT)
+ *va_arg(ap, short*) = (short)nrchars;
+ else if (flags & FL_LONG)
+ *va_arg(ap, long*) = (long)nrchars;
+ else
+ *va_arg(ap, int*) = (int)nrchars;
+ continue;
+ case 's':
+ s1 = va_arg(ap, char*);
+ if (s1 == NULL)
+ s1 = "(null)";
+ s = s1;
+ while (precision || !(flags & FL_PRECSPEC))
+ {
+ if (*s == '\0')
+ break;
+ s++;
+ precision--;
+ }
+ break;
+ case 'p':
+ set_pointer(flags);
/* fallthrough */
- case 'b':
- case 'o':
- case 'u':
- case 'x':
- case 'X':
- if (!(flags & FL_PRECSPEC)) precision = 1;
- else if (c != 'p') flags &= ~FL_ZEROFILL;
- s = o_print(&ap, flags, s, c, precision, 0);
- break;
- case 'd':
- case 'i':
- flags |= FL_SIGNEDCONV;
- if (!(flags & FL_PRECSPEC)) precision = 1;
- else flags &= ~FL_ZEROFILL;
- s = o_print(&ap, flags, s, c, precision, 1);
- break;
- case 'c':
- *s++ = va_arg(ap, int);
- break;
+ case 'b':
+ case 'o':
+ case 'u':
+ case 'x':
+ case 'X':
+ if (!(flags & FL_PRECSPEC))
+ precision = 1;
+ else if (c != 'p')
+ flags &= ~FL_ZEROFILL;
+ s = o_print(&ap, flags, s, c, precision, 0);
+ break;
+ case 'd':
+ case 'i':
+ flags |= FL_SIGNEDCONV;
+ if (!(flags & FL_PRECSPEC))
+ precision = 1;
+ else
+ flags &= ~FL_ZEROFILL;
+ s = o_print(&ap, flags, s, c, precision, 1);
+ break;
+ case 'c':
+ *s++ = va_arg(ap, int);
+ break;
#ifndef ACKCONF_NO_STDIO_FLOAT
- case 'G':
- case 'g':
- if ((flags & FL_PRECSPEC) && (precision == 0))
- precision = 1;
- case 'f':
- case 'E':
- case 'e':
- if (!(flags & FL_PRECSPEC))
- precision = 6;
+ case 'G':
+ case 'g':
+ if ((flags & FL_PRECSPEC) && (precision == 0))
+ precision = 1;
+ case 'f':
+ case 'E':
+ case 'e':
+ if (!(flags & FL_PRECSPEC))
+ precision = 6;
- if (precision >= sizeof(buf))
- precision = sizeof(buf) - 1;
+ if (precision >= sizeof(buf))
+ precision = sizeof(buf) - 1;
- flags |= FL_SIGNEDCONV;
- s = _f_print(&ap, flags, s, c, precision);
- break;
-#endif /* ACKCONF_NO_STDIO_FLOAT */
- case 'r':
- ap = va_arg(ap, va_list);
- fmt = va_arg(ap, char *);
- continue;
+ flags |= FL_SIGNEDCONV;
+ s = _f_print(&ap, flags, s, c, precision);
+ break;
+#endif /* ACKCONF_NO_STDIO_FLOAT */
+ case 'r':
+ ap = va_arg(ap, va_list);
+ fmt = va_arg(ap, char*);
+ continue;
}
zfill = ' ';
- if (flags & FL_ZEROFILL) zfill = '0';
+ if (flags & FL_ZEROFILL)
+ zfill = '0';
j = s - s1;
/* between_fill is true under the following conditions:
between_fill = 0;
if ((flags & FL_ZEROFILL)
&& (((c == 'x' || c == 'X') && (flags & FL_ALT))
- || (c == 'p')
- || ((flags & FL_SIGNEDCONV)
- && ( *s1 == '+' || *s1 == '-' || *s1 == ' '))))
+ || (c == 'p')
+ || ((flags & FL_SIGNEDCONV)
+ && (*s1 == '+' || *s1 == '-' || *s1 == ' '))))
between_fill++;
if ((i = width - j) > 0)
- if (!(flags & FL_LJUST)) { /* right justify */
+ if (!(flags & FL_LJUST))
+ { /* right justify */
nrchars += i;
- if (between_fill) {
- if (flags & FL_SIGNEDCONV) {
- j--; nrchars++;
- PUTC(*s1++);
- } else {
- j -= 2; nrchars += 2;
- PUTC(*s1++);
- PUTC(*s1++);
+ if (between_fill)
+ {
+ if (flags & FL_SIGNEDCONV)
+ {
+ j--;
+ nrchars++;
+ PUTC(*s1++);
+ }
+ else
+ {
+ j -= 2;
+ nrchars += 2;
+ PUTC(*s1++);
+ PUTC(*s1++);
}
}
- do {
+ do
+ {
PUTC(zfill);
} while (--i);
}
nrchars += j;
- while (--j >= 0) {
+ while (--j >= 0)
+ {
PUTC(*s1++);
}
- if (i > 0) nrchars += i;
+ if (i > 0)
+ nrchars += i;
while (--i >= 0)
PUTC(zfill);
}
*/
/* $Id$ */
-#include <stdio.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <stdarg.h>
-#include "loc_incl.h"
-
-#if _EM_WSIZE == _EM_PSIZE
-#define set_pointer(flags) /* nothing */
-#elif _EM_LSIZE == _EM_PSIZE
-#define set_pointer(flags) (flags |= FL_LONG)
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <stdarg.h>
+#include "loc_incl.h"
+
+#if _EM_WSIZE == _EM_PSIZE
+#define set_pointer(flags) /* nothing */
+#elif _EM_LSIZE == _EM_PSIZE
+#define set_pointer(flags) (flags |= FL_LONG)
#else
#error garbage pointer size
-#define set_pointer(flags) /* compilation might continue */
+#define set_pointer(flags) /* compilation might continue */
#endif
-#define NUMLEN 512
-#define NR_CHARS 256
+#define NUMLEN 512
+#define NR_CHARS 256
-static char Xtable[NR_CHARS];
-static char inp_buf[NUMLEN];
+static char Xtable[NR_CHARS];
+static char inp_buf[NUMLEN];
/* Collect a number of characters which constitite an ordinal number.
* When the type is 'i', the base can be 8, 10, or 16, depending on the
* according to the format of the number. At the end of the function, base
* is then set to 0, so strtol() will get the right argument.
*/
-static char *
-o_collect(register int c, register FILE *stream, char type,
- int width, int *basep)
+static char*
+o_collect(register int c, register FILE* stream, char type,
+ int width, int* basep)
{
- register char *bufp = inp_buf;
+ register char* bufp = inp_buf;
register int base;
- switch (type) {
- case 'i': /* i means octal, decimal or hexadecimal */
- case 'p':
- case 'x':
- case 'X': base = 16; break;
- case 'd':
- case 'u': base = 10; break;
- case 'o': base = 8; break;
- case 'b': base = 2; break;
+ switch (type)
+ {
+ case 'i': /* i means octal, decimal or hexadecimal */
+ case 'p':
+ case 'x':
+ case 'X':
+ base = 16;
+ break;
+ case 'd':
+ case 'u':
+ base = 10;
+ break;
+ case 'o':
+ base = 8;
+ break;
+ case 'b':
+ base = 2;
+ break;
}
- if (c == '-' || c == '+') {
+ if (c == '-' || c == '+')
+ {
*bufp++ = c;
if (--width)
- c = getc(stream);
+ c = getc(stream);
}
- if (width && c == '0' && base == 16) {
+ if (width && c == '0' && base == 16)
+ {
*bufp++ = c;
if (--width)
c = getc(stream);
- if (c != 'x' && c != 'X') {
- if (type == 'i') base = 8;
+ if (c != 'x' && c != 'X')
+ {
+ if (type == 'i')
+ base = 8;
}
- else if (width) {
+ else if (width)
+ {
*bufp++ = c;
if (--width)
c = getc(stream);
}
}
- else if (type == 'i') base = 10;
+ else if (type == 'i')
+ base = 10;
- while (width) {
+ while (width)
+ {
if (((base == 10) && isdigit(c))
|| ((base == 16) && isxdigit(c))
|| ((base == 8) && isdigit(c) && (c < '8'))
- || ((base == 2) && isdigit(c) && (c < '2'))) {
+ || ((base == 2) && isdigit(c) && (c < '2')))
+ {
*bufp++ = c;
if (--width)
c = getc(stream);
}
- else break;
+ else
+ break;
}
- if (width && c != EOF) ungetc(c, stream);
- if (type == 'i') base = 0;
+ if (width && c != EOF)
+ ungetc(c, stream);
+ if (type == 'i')
+ base = 0;
*basep = base;
*bufp = '\0';
return bufp - 1;
}
-#ifndef ACKCONF_NO_STDIO_FLOAT
+#ifndef ACKCONF_NO_STDIO_FLOAT
/* The function f_collect() reads a string that has the format of a
* floating-point number. The function returns as soon as a format-error
* is encountered, leaving the offending character in the input. This means
* not necessary, although the use of the width field can cause incomplete
* numbers to be passed to strtod(). (e.g. 1.3e+)
*/
-static char *
-f_collect(register int c, register FILE *stream, register int width)
+static char*
+f_collect(register int c, register FILE* stream, register int width)
{
- register char *bufp = inp_buf;
+ register char* bufp = inp_buf;
int digit_seen = 0;
- if (c == '-' || c == '+') {
+ if (c == '-' || c == '+')
+ {
*bufp++ = c;
if (--width)
c = getc(stream);
}
- while (width && isdigit(c)) {
+ while (width && isdigit(c))
+ {
digit_seen++;
*bufp++ = c;
if (--width)
c = getc(stream);
}
- if (width && c == '.') {
+ if (width && c == '.')
+ {
*bufp++ = c;
- if(--width)
+ if (--width)
c = getc(stream);
- while (width && isdigit(c)) {
+ while (width && isdigit(c))
+ {
digit_seen++;
*bufp++ = c;
if (--width)
}
}
- if (!digit_seen) {
- if (width && c != EOF) ungetc(c, stream);
+ if (!digit_seen)
+ {
+ if (width && c != EOF)
+ ungetc(c, stream);
return inp_buf - 1;
}
- else digit_seen = 0;
+ else
+ digit_seen = 0;
- if (width && (c == 'e' || c == 'E')) {
+ if (width && (c == 'e' || c == 'E'))
+ {
*bufp++ = c;
if (--width)
c = getc(stream);
- if (width && (c == '+' || c == '-')) {
+ if (width && (c == '+' || c == '-'))
+ {
*bufp++ = c;
if (--width)
c = getc(stream);
}
- while (width && isdigit(c)) {
+ while (width && isdigit(c))
+ {
digit_seen++;
*bufp++ = c;
if (--width)
c = getc(stream);
}
- if (!digit_seen) {
- if (width && c != EOF) ungetc(c,stream);
+ if (!digit_seen)
+ {
+ if (width && c != EOF)
+ ungetc(c, stream);
return inp_buf - 1;
}
}
- if (width && c != EOF) ungetc(c, stream);
+ if (width && c != EOF)
+ ungetc(c, stream);
*bufp = '\0';
return bufp - 1;
}
-#endif /* ACKCONF_NO_STDIO_FLOAT */
-
+#endif /* ACKCONF_NO_STDIO_FLOAT */
/*
* the routine that does the scanning
*/
-int
-_doscan(register FILE *stream, const char *format, va_list ap)
+int _doscan(register FILE* stream, const char* format, va_list ap)
{
- int done = 0; /* number of items done */
- int nrchars = 0; /* number of characters read */
- int conv = 0; /* # of conversions */
- int base; /* conversion base */
- unsigned long val; /* an integer value */
- register char *str; /* temporary pointer */
- char *tmp_string; /* ditto */
- unsigned width; /* width of field */
- int flags; /* some flags */
- int reverse; /* reverse the checking in [...] */
- int kind;
- register int ic; /* the input character */
-#ifndef ACKCONF_NO_STDIO_FLOAT
- long double ld_val;
+ int done = 0; /* number of items done */
+ int nrchars = 0; /* number of characters read */
+ int conv = 0; /* # of conversions */
+ int base; /* conversion base */
+ unsigned long val; /* an integer value */
+ register char* str; /* temporary pointer */
+ char* tmp_string; /* ditto */
+ unsigned width; /* width of field */
+ int flags; /* some flags */
+ int reverse; /* reverse the checking in [...] */
+ int kind;
+ register int ic; /* the input character */
+#ifndef ACKCONF_NO_STDIO_FLOAT
+ long double ld_val;
#endif
- if (!*format) return 0;
+ if (!*format)
+ return 0;
- while (1) {
- if (isspace(*format)) {
+ while (1)
+ {
+ if (isspace(*format))
+ {
while (isspace(*format))
- format++; /* skip whitespace */
+ format++; /* skip whitespace */
ic = getc(stream);
nrchars++;
- while (isspace (ic)) {
+ while (isspace(ic))
+ {
ic = getc(stream);
nrchars++;
}
- if (ic != EOF) ungetc(ic,stream);
+ if (ic != EOF)
+ ungetc(ic, stream);
nrchars--;
}
- if (!*format) break; /* end of format */
+ if (!*format)
+ break; /* end of format */
- if (*format != '%') {
+ if (*format != '%')
+ {
ic = getc(stream);
nrchars++;
- if (ic != *format++) {
- if (ic != EOF) ungetc(ic,stream);
+ if (ic != *format++)
+ {
+ if (ic != EOF)
+ ungetc(ic, stream);
nrchars--;
- break; /* error */
+ break; /* error */
}
continue;
}
format++;
- if (*format == '%') {
+ if (*format == '%')
+ {
ic = getc(stream);
nrchars++;
- if (ic == '%') {
+ if (ic == '%')
+ {
format++;
continue;
}
- else break;
+ else
+ break;
}
flags = 0;
- if (*format == '*') {
+ if (*format == '*')
+ {
format++;
flags |= FL_NOASSIGN;
}
- if (isdigit (*format)) {
+ if (isdigit(*format))
+ {
flags |= FL_WIDTHSPEC;
- for (width = 0; isdigit (*format);)
+ for (width = 0; isdigit(*format);)
width = width * 10 + *format++ - '0';
}
- switch (*format) {
- case 'h': flags |= FL_SHORT; format++; break;
- case 'l': flags |= FL_LONG; format++; break;
- case 'L': flags |= FL_LONGDOUBLE; format++; break;
+ switch (*format)
+ {
+ case 'h':
+ flags |= FL_SHORT;
+ format++;
+ break;
+ case 'l':
+ flags |= FL_LONG;
+ format++;
+ break;
+ case 'L':
+ flags |= FL_LONGDOUBLE;
+ format++;
+ break;
}
kind = *format;
- if ((kind != 'c') && (kind != '[') && (kind != 'n')) {
- do {
+ if ((kind != 'c') && (kind != '[') && (kind != 'n'))
+ {
+ do
+ {
ic = getc(stream);
nrchars++;
} while (isspace(ic));
- if (ic == EOF) break; /* outer while */
- } else if (kind != 'n') { /* %c or %[ */
+ if (ic == EOF)
+ break; /* outer while */
+ }
+ else if (kind != 'n')
+ { /* %c or %[ */
ic = getc(stream);
- if (ic == EOF) break; /* outer while */
+ if (ic == EOF)
+ break; /* outer while */
nrchars++;
}
- switch (kind) {
- default:
- /* not recognized, like %q */
- return conv || (ic != EOF) ? done : EOF;
- break;
- case 'n':
- if (!(flags & FL_NOASSIGN)) { /* silly, though */
- if (flags & FL_SHORT)
- *va_arg(ap, short *) = (short) nrchars;
- else if (flags & FL_LONG)
- *va_arg(ap, long *) = (long) nrchars;
- else
- *va_arg(ap, int *) = (int) nrchars;
- }
- break;
- case 'p': /* pointer */
- set_pointer(flags);
+ switch (kind)
+ {
+ default:
+ /* not recognized, like %q */
+ return conv || (ic != EOF) ? done : EOF;
+ break;
+ case 'n':
+ if (!(flags & FL_NOASSIGN))
+ { /* silly, though */
+ if (flags & FL_SHORT)
+ *va_arg(ap, short*) = (short)nrchars;
+ else if (flags & FL_LONG)
+ *va_arg(ap, long*) = (long)nrchars;
+ else
+ *va_arg(ap, int*) = (int)nrchars;
+ }
+ break;
+ case 'p': /* pointer */
+ set_pointer(flags);
/* fallthrough */
- case 'b': /* binary */
- case 'd': /* decimal */
- case 'i': /* general integer */
- case 'o': /* octal */
- case 'u': /* unsigned */
- case 'x': /* hexadecimal */
- case 'X': /* ditto */
- if (!(flags & FL_WIDTHSPEC) || width > NUMLEN)
- width = NUMLEN;
- if (!width) return done;
-
- str = o_collect(ic, stream, kind, width, &base);
- if (str < inp_buf
- || (str == inp_buf
- && (*str == '-'
- || *str == '+'))) return done;
-
- /*
+ case 'b': /* binary */
+ case 'd': /* decimal */
+ case 'i': /* general integer */
+ case 'o': /* octal */
+ case 'u': /* unsigned */
+ case 'x': /* hexadecimal */
+ case 'X': /* ditto */
+ if (!(flags & FL_WIDTHSPEC) || width > NUMLEN)
+ width = NUMLEN;
+ if (!width)
+ return done;
+
+ str = o_collect(ic, stream, kind, width, &base);
+ if (str < inp_buf
+ || (str == inp_buf
+ && (*str == '-'
+ || *str == '+')))
+ return done;
+
+ /*
* Although the length of the number is str-inp_buf+1
* we don't add the 1 since we counted it already
*/
- nrchars += str - inp_buf;
+ nrchars += str - inp_buf;
- if (!(flags & FL_NOASSIGN)) {
- if (kind == 'd' || kind == 'i')
- val = strtol(inp_buf, &tmp_string, base);
- else
- val = strtoul(inp_buf, &tmp_string, base);
- if (flags & FL_LONG)
- *va_arg(ap, unsigned long *) = (unsigned long) val;
- else if (flags & FL_SHORT)
- *va_arg(ap, unsigned short *) = (unsigned short) val;
- else
- *va_arg(ap, unsigned *) = (unsigned) val;
- }
- break;
- case 'c':
- if (!(flags & FL_WIDTHSPEC))
- width = 1;
- if (!(flags & FL_NOASSIGN))
- str = va_arg(ap, char *);
- if (!width) return done;
-
- while (width && ic != EOF) {
if (!(flags & FL_NOASSIGN))
- *str++ = (char) ic;
- if (--width) {
- ic = getc(stream);
- nrchars++;
+ {
+ if (kind == 'd' || kind == 'i')
+ val = strtol(inp_buf, &tmp_string, base);
+ else
+ val = strtoul(inp_buf, &tmp_string, base);
+ if (flags & FL_LONG)
+ *va_arg(ap, unsigned long*) = (unsigned long)val;
+ else if (flags & FL_SHORT)
+ *va_arg(ap, unsigned short*) = (unsigned short)val;
+ else
+ *va_arg(ap, unsigned*) = (unsigned)val;
}
- }
-
- if (width) {
- if (ic != EOF) ungetc(ic,stream);
- nrchars--;
- }
- break;
- case 's':
- if (!(flags & FL_WIDTHSPEC))
- width = 0xffff;
- if (!(flags & FL_NOASSIGN))
- str = va_arg(ap, char *);
- if (!width) return done;
-
- while (width && ic != EOF && !isspace(ic)) {
+ break;
+ case 'c':
+ if (!(flags & FL_WIDTHSPEC))
+ width = 1;
if (!(flags & FL_NOASSIGN))
- *str++ = (char) ic;
- if (--width) {
- ic = getc(stream);
- nrchars++;
+ str = va_arg(ap, char*);
+ if (!width)
+ return done;
+
+ while (width && ic != EOF)
+ {
+ if (!(flags & FL_NOASSIGN))
+ *str++ = (char)ic;
+ if (--width)
+ {
+ ic = getc(stream);
+ nrchars++;
+ }
}
- }
- /* terminate the string */
- if (!(flags & FL_NOASSIGN))
- *str = '\0';
- if (width) {
- if (ic != EOF) ungetc(ic,stream);
- nrchars--;
- }
- break;
- case '[':
- if (!(flags & FL_WIDTHSPEC))
- width = 0xffff;
- if (!width) return done;
- if ( *++format == '^' ) {
- reverse = 1;
- format++;
- } else
- reverse = 0;
+ if (width)
+ {
+ if (ic != EOF)
+ ungetc(ic, stream);
+ nrchars--;
+ }
+ break;
+ case 's':
+ if (!(flags & FL_WIDTHSPEC))
+ width = 0xffff;
+ if (!(flags & FL_NOASSIGN))
+ str = va_arg(ap, char*);
+ if (!width)
+ return done;
+
+ while (width && ic != EOF && !isspace(ic))
+ {
+ if (!(flags & FL_NOASSIGN))
+ *str++ = (char)ic;
+ if (--width)
+ {
+ ic = getc(stream);
+ nrchars++;
+ }
+ }
+ /* terminate the string */
+ if (!(flags & FL_NOASSIGN))
+ *str = '\0';
+ if (width)
+ {
+ if (ic != EOF)
+ ungetc(ic, stream);
+ nrchars--;
+ }
+ break;
+ case '[':
+ if (!(flags & FL_WIDTHSPEC))
+ width = 0xffff;
+ if (!width)
+ return done;
+
+ if (*++format == '^')
+ {
+ reverse = 1;
+ format++;
+ }
+ else
+ reverse = 0;
- for (str = Xtable; str < &Xtable[NR_CHARS]
- ; str++)
- *str = 0;
+ for (str = Xtable; str < &Xtable[NR_CHARS]; str++)
+ *str = 0;
- if (*format == ']') Xtable[*format++] = 1;
+ if (*format == ']')
+ Xtable[*format++] = 1;
- while (*format && *format != ']') {
- Xtable[*format++] = 1;
- if (*format == '-') {
- format++;
- if (*format
- && *format != ']'
- && *(format) >= *(format -2)) {
- int c;
-
- for( c = *(format -2) + 1
- ; c <= *format ; c++)
- Xtable[c] = 1;
+ while (*format && *format != ']')
+ {
+ Xtable[*format++] = 1;
+ if (*format == '-')
+ {
format++;
+ if (*format
+ && *format != ']'
+ && *(format) >= *(format - 2))
+ {
+ int c;
+
+ for (c = *(format - 2) + 1; c <= *format; c++)
+ Xtable[c] = 1;
+ format++;
+ }
+ else
+ Xtable['-'] = 1;
}
- else Xtable['-'] = 1;
}
- }
- if (!*format || !(Xtable[ic] ^ reverse)) {
- if (ic != EOF) ungetc(ic, stream);
- return done;
- }
+ if (!*format || !(Xtable[ic] ^ reverse))
+ {
+ if (ic != EOF)
+ ungetc(ic, stream);
+ return done;
+ }
- if (!(flags & FL_NOASSIGN))
- str = va_arg(ap, char *);
+ if (!(flags & FL_NOASSIGN))
+ str = va_arg(ap, char*);
+
+ do
+ {
+ if (!(flags & FL_NOASSIGN))
+ *str++ = (char)ic;
+ if (--width)
+ {
+ ic = getc(stream);
+ nrchars++;
+ }
+ } while (width && ic != EOF && (Xtable[ic] ^ reverse));
- do {
+ if (width)
+ {
+ if (ic != EOF)
+ ungetc(ic, stream);
+ nrchars--;
+ }
if (!(flags & FL_NOASSIGN))
- *str++ = (char) ic;
- if (--width) {
- ic = getc(stream);
- nrchars++;
+ { /* terminate string */
+ *str = '\0';
}
- } while (width && ic != EOF && (Xtable[ic] ^ reverse));
-
- if (width) {
- if (ic != EOF) ungetc(ic, stream);
- nrchars--;
- }
- if (!(flags & FL_NOASSIGN)) { /* terminate string */
- *str = '\0';
- }
- break;
-#ifndef ACKCONF_NO_STDIO_FLOAT
- case 'e':
- case 'E':
- case 'f':
- case 'g':
- case 'G':
- if (!(flags & FL_WIDTHSPEC) || width > NUMLEN)
- width = NUMLEN;
-
- if (!width) return done;
- str = f_collect(ic, stream, width);
-
- if (str < inp_buf
- || (str == inp_buf
- && (*str == '-'
- || *str == '+'))) return done;
-
- /*
+ break;
+#ifndef ACKCONF_NO_STDIO_FLOAT
+ case 'e':
+ case 'E':
+ case 'f':
+ case 'g':
+ case 'G':
+ if (!(flags & FL_WIDTHSPEC) || width > NUMLEN)
+ width = NUMLEN;
+
+ if (!width)
+ return done;
+ str = f_collect(ic, stream, width);
+
+ if (str < inp_buf
+ || (str == inp_buf
+ && (*str == '-'
+ || *str == '+')))
+ return done;
+
+ /*
* Although the length of the number is str-inp_buf+1
* we don't add the 1 since we counted it already
*/
- nrchars += str - inp_buf;
+ nrchars += str - inp_buf;
- if (!(flags & FL_NOASSIGN)) {
- ld_val = strtod(inp_buf, &tmp_string);
- if (flags & FL_LONGDOUBLE)
- *va_arg(ap, long double *) = (long double) ld_val;
- else
- if (flags & FL_LONG)
- *va_arg(ap, double *) = (double) ld_val;
- else
- *va_arg(ap, float *) = (float) ld_val;
- }
- break;
+ if (!(flags & FL_NOASSIGN))
+ {
+ ld_val = strtod(inp_buf, &tmp_string);
+ if (flags & FL_LONGDOUBLE)
+ *va_arg(ap, long double*) = (long double)ld_val;
+ else if (flags & FL_LONG)
+ *va_arg(ap, double*) = (double)ld_val;
+ else
+ *va_arg(ap, float*) = (float)ld_val;
+ }
+ break;
#endif
- } /* end switch */
+ } /* end switch */
conv++;
- if (!(flags & FL_NOASSIGN) && kind != 'n') done++;
+ if (!(flags & FL_NOASSIGN) && kind != 'n')
+ done++;
format++;
}
return conv || (ic != EOF) ? done : EOF;
/* $Id$ */
-#include "loc_incl.h"
+#include "loc_incl.h"
#ifndef ACKCONF_NO_STDIO_FLOAT
-#include "../stdlib/ext_fmt.h"
-void _dbl_ext_cvt(double value, struct EXTEND *e);
-char *_ext_str_cvt(struct EXTEND *e, int ndigit, int *decpt, int * sign, int ecvtflag);
+#include "../stdlib/ext_fmt.h"
+void _dbl_ext_cvt(double value, struct EXTEND* e);
+char* _ext_str_cvt(struct EXTEND* e, int ndigit, int* decpt, int* sign, int ecvtflag);
-static char *
-cvt(long double value, int ndigit, int *decpt, int *sign, int ecvtflag)
+static char*
+cvt(long double value, int ndigit, int* decpt, int* sign, int ecvtflag)
{
struct EXTEND e;
return _ext_str_cvt(&e, ndigit, decpt, sign, ecvtflag);
}
-char *
-_ecvt(long double value, int ndigit, int *decpt, int *sign)
+char* _ecvt(long double value, int ndigit, int* decpt, int* sign)
{
return cvt(value, ndigit, decpt, sign, 1);
}
-char *
-_fcvt(long double value, int ndigit, int *decpt, int *sign)
+char* _fcvt(long double value, int ndigit, int* decpt, int* sign)
{
return cvt(value, ndigit, decpt, sign, 0);
}
-#endif /* ACKCONF_NO_STDIO_FLOAT */
+#endif /* ACKCONF_NO_STDIO_FLOAT */
#include <unistd.h>
#include "loc_incl.h"
-int
-fclose(FILE *fp)
+int fclose(FILE* fp)
{
register int i, retval = 0;
- for (i=0; i<FOPEN_MAX; i++)
- if (fp == __iotab[i]) {
+ for (i = 0; i < FOPEN_MAX; i++)
+ if (fp == __iotab[i])
+ {
__iotab[i] = 0;
break;
}
if (i >= FOPEN_MAX)
return EOF;
- if (fflush(fp)) retval = EOF;
- if (close(fileno(fp))) retval = EOF;
- if ( io_testflag(fp,_IOMYBUF) && fp->_buf )
- free((void *)fp->_buf);
+ if (fflush(fp))
+ retval = EOF;
+ if (close(fileno(fp)))
+ retval = EOF;
+ if (io_testflag(fp, _IOMYBUF) && fp->_buf)
+ free((void*)fp->_buf);
if (fp != stdin && fp != stdout && fp != stderr)
- free((void *)fp);
+ free((void*)fp);
return retval;
}
*/
/* $Id$ */
-#include <stdio.h>
-#include <stdlib.h>
-#include "../stdio/loc_incl.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "../stdio/loc_incl.h"
-FILE *
-fdopen(int fd, const char *mode)
+FILE* fdopen(int fd, const char* mode)
{
register int i;
- FILE *stream;
+ FILE* stream;
int flags = 0;
- if (fd < 0) return (FILE *)NULL;
- for (i = 0; __iotab[i] != 0 ; i++)
- if (i >= FOPEN_MAX-1)
- return (FILE *)NULL;
+ if (fd < 0)
+ return (FILE*)NULL;
+ for (i = 0; __iotab[i] != 0; i++)
+ if (i >= FOPEN_MAX - 1)
+ return (FILE*)NULL;
- switch(*mode++) {
- case 'r':
- flags |= _IOREAD | _IOREADING;
- break;
- case 'a':
- flags |= _IOAPPEND;
- case 'w':
- flags |= _IOWRITE | _IOWRITING;
- break;
- default:
- return (FILE *)NULL;
- }
- while(*mode) {
- switch(*mode++) {
- case 'b':
- continue;
- case '+':
- flags |= _IOREAD | _IOWRITE;
- continue;
- /* The sequence may be followed by aditional characters */
- default:
+ switch (*mode++)
+ {
+ case 'r':
+ flags |= _IOREAD | _IOREADING;
break;
+ case 'a':
+ flags |= _IOAPPEND;
+ case 'w':
+ flags |= _IOWRITE | _IOWRITING;
+ break;
+ default:
+ return (FILE*)NULL;
+ }
+ while (*mode)
+ {
+ switch (*mode++)
+ {
+ case 'b':
+ continue;
+ case '+':
+ flags |= _IOREAD | _IOWRITE;
+ continue;
+ /* The sequence may be followed by aditional characters */
+ default:
+ break;
}
break;
}
- if ((stream = (FILE *) malloc(sizeof(FILE))) == NULL) {
- return (FILE *)NULL;
+ if ((stream = (FILE*)malloc(sizeof(FILE))) == NULL)
+ {
+ return (FILE*)NULL;
}
if ((flags & _IOREAD) && (flags & _IOWRITE))
*/
/* $Id$ */
-#include <stdio.h>
+#include <stdio.h>
-int
-(feof)(FILE *stream)
+int(feof)(FILE* stream)
{
return feof(stream);
}
*/
/* $Id$ */
-#include <stdio.h>
+#include <stdio.h>
-int
-(ferror)(FILE *stream)
+int(ferror)(FILE* stream)
{
return ferror(stream);
}
#include <unistd.h>
#include "loc_incl.h"
-int
-fflush(FILE *stream)
+int fflush(FILE* stream)
{
int count, c1, i, retval = 0;
- if (!stream) {
- for(i= 0; i < FOPEN_MAX; i++)
- if (__iotab[i] && fflush(__iotab[i]))
- retval = EOF;
- return retval;
+ if (!stream)
+ {
+ for (i = 0; i < FOPEN_MAX; i++)
+ if (__iotab[i] && fflush(__iotab[i]))
+ retval = EOF;
+ return retval;
}
if (!stream->_buf
|| (!io_testflag(stream, _IOREADING)
- && !io_testflag(stream, _IOWRITING)))
+ && !io_testflag(stream, _IOWRITING)))
return 0;
- if (io_testflag(stream, _IOREADING)) {
+ if (io_testflag(stream, _IOREADING))
+ {
/* (void) fseek(stream, 0L, SEEK_CUR); */
int adjust = 0;
- if (stream->_buf && !io_testflag(stream,_IONBF))
+ if (stream->_buf && !io_testflag(stream, _IONBF))
adjust = stream->_count;
stream->_count = 0;
- lseek(fileno(stream), (off_t) adjust, SEEK_CUR);
+ lseek(fileno(stream), (off_t)adjust, SEEK_CUR);
if (io_testflag(stream, _IOWRITE))
stream->_flags &= ~(_IOREADING | _IOWRITING);
stream->_ptr = stream->_buf;
return 0;
- } else if (io_testflag(stream, _IONBF)) return 0;
+ }
+ else if (io_testflag(stream, _IONBF))
+ return 0;
- if (io_testflag(stream, _IOREAD)) /* "a" or "+" mode */
+ if (io_testflag(stream, _IOREAD)) /* "a" or "+" mode */
stream->_flags &= ~_IOWRITING;
count = stream->_ptr - stream->_buf;
stream->_ptr = stream->_buf;
- if ( count <= 0 )
+ if (count <= 0)
return 0;
- if (io_testflag(stream, _IOAPPEND)) {
- if (lseek(fileno(stream), 0L, SEEK_END) == -1) {
+ if (io_testflag(stream, _IOAPPEND))
+ {
+ if (lseek(fileno(stream), 0L, SEEK_END) == -1)
+ {
stream->_flags |= _IOERR;
return EOF;
}
}
- c1 = write(stream->_fd, (char *)stream->_buf, count);
+ c1 = write(stream->_fd, (char*)stream->_buf, count);
stream->_count = 0;
- if ( count == c1 )
+ if (count == c1)
return 0;
stream->_flags |= _IOERR;
- return EOF;
+ return EOF;
}
-void
-__cleanup(void)
+void __cleanup(void)
{
register int i;
- for(i= 0; i < FOPEN_MAX; i++)
+ for (i = 0; i < FOPEN_MAX; i++)
if (__iotab[i] && io_testflag(__iotab[i], _IOWRITING))
- (void) fflush(__iotab[i]);
+ (void)fflush(__iotab[i]);
}
*/
/* $Id$ */
-#include <stdio.h>
+#include <stdio.h>
-int
-fgetc(FILE *stream)
+int fgetc(FILE* stream)
{
return getc(stream);
}
*/
/* $Id$ */
-#include <stdio.h>
+#include <stdio.h>
-int
-fgetpos(FILE *stream, fpos_t *pos)
+int fgetpos(FILE* stream, fpos_t* pos)
{
*pos = ftell(stream);
- if (*pos == -1) return -1;
+ if (*pos == -1)
+ return -1;
return 0;
}
*/
/* $Id$ */
-#include <stdio.h>
+#include <stdio.h>
-char *
-fgets(char *s, register int n, register FILE *stream)
+char* fgets(char* s, register int n, register FILE* stream)
{
register int ch;
- register char *ptr;
+ register char* ptr;
ptr = s;
- while (--n > 0 && (ch = getc(stream)) != EOF) {
+ while (--n > 0 && (ch = getc(stream)) != EOF)
+ {
*ptr++ = ch;
- if ( ch == '\n')
+ if (ch == '\n')
break;
}
- if (ch == EOF) {
- if (feof(stream)) {
- if (ptr == s) return NULL;
- } else return NULL;
+ if (ch == EOF)
+ {
+ if (feof(stream))
+ {
+ if (ptr == s)
+ return NULL;
+ }
+ else
+ return NULL;
}
*ptr = '\0';
return s;
*/
/* $Id$ */
-#include <stdio.h>
+#include <stdio.h>
-int
-(fileno)(FILE *stream)
+int(fileno)(FILE* stream)
{
return stream->_fd;
}
#include <unistd.h>
#include "loc_incl.h"
-int
-__fillbuf(register FILE *stream)
+int __fillbuf(register FILE* stream)
{
static unsigned char ch[FOPEN_MAX];
register int i;
stream->_count = 0;
- if (fileno(stream) < 0) return EOF;
- if (io_testflag(stream, _IOEOF)) return EOF;
- if (!io_testflag(stream, _IOREAD)) {
+ if (fileno(stream) < 0)
+ return EOF;
+ if (io_testflag(stream, _IOEOF))
+ return EOF;
+ if (!io_testflag(stream, _IOREAD))
+ {
stream->_flags |= _IOERR;
return EOF;
}
- if (io_testflag(stream, _IOWRITING)) {
+ if (io_testflag(stream, _IOWRITING))
+ {
stream->_flags |= _IOERR;
return EOF;
}
if (!io_testflag(stream, _IOREADING))
stream->_flags |= _IOREADING;
-
- if (!io_testflag(stream, _IONBF) && !stream->_buf) {
- stream->_buf = (unsigned char *) malloc(BUFSIZ);
- if (!stream->_buf) {
+
+ if (!io_testflag(stream, _IONBF) && !stream->_buf)
+ {
+ stream->_buf = (unsigned char*)malloc(BUFSIZ);
+ if (!stream->_buf)
+ {
stream->_flags |= _IONBF;
}
- else {
+ else
+ {
stream->_flags |= _IOMYBUF;
stream->_bufsiz = BUFSIZ;
}
}
/* flush line-buffered output when filling an input buffer */
- for (i = 0; i < FOPEN_MAX; i++) {
+ for (i = 0; i < FOPEN_MAX; i++)
+ {
if (__iotab[i] && io_testflag(__iotab[i], _IOLBF))
if (io_testflag(__iotab[i], _IOWRITING))
- (void) fflush(__iotab[i]);
+ (void)fflush(__iotab[i]);
}
- if (!stream->_buf) {
+ if (!stream->_buf)
+ {
stream->_buf = &ch[fileno(stream)];
stream->_bufsiz = 1;
}
stream->_ptr = stream->_buf;
- stream->_count = read(stream->_fd, (char *)stream->_buf, stream->_bufsiz);
+ stream->_count = read(stream->_fd, (char*)stream->_buf, stream->_bufsiz);
- if (stream->_count <= 0){
- if (stream->_count == 0) {
+ if (stream->_count <= 0)
+ {
+ if (stream->_count == 0)
+ {
stream->_flags |= _IOEOF;
}
- else
+ else
stream->_flags |= _IOERR;
return EOF;
*/
/* $Id$ */
-#include <string.h>
-#include <stdarg.h>
-#include "loc_incl.h"
+#include <string.h>
+#include <stdarg.h>
+#include "loc_incl.h"
-#ifndef ACKCONF_NO_STDIO_FLOAT
+#ifndef ACKCONF_NO_STDIO_FLOAT
-static char *
-_pfloat(long double r, register char *s, int n, int flags)
+static char*
+_pfloat(long double r, register char* s, int n, int flags)
{
- register char *s1;
+ register char* s1;
int sign, dp;
register int i;
else if (flags & FL_SPACE)
*s++ = ' ';
- if (dp<=0)
+ if (dp <= 0)
*s++ = '0';
- for (i=dp; i>0; i--)
- if (*s1) *s++ = *s1++;
- else *s++ = '0';
- if (((i=n) > 0) || (flags & FL_ALT))
+ for (i = dp; i > 0; i--)
+ if (*s1)
+ *s++ = *s1++;
+ else
+ *s++ = '0';
+ if (((i = n) > 0) || (flags & FL_ALT))
*s++ = '.';
- while (++dp <= 0) {
- if (--i<0)
+ while (++dp <= 0)
+ {
+ if (--i < 0)
break;
*s++ = '0';
}
while (--i >= 0)
- if (*s1) *s++ = *s1++;
- else *s++ = '0';
+ if (*s1)
+ *s++ = *s1++;
+ else
+ *s++ = '0';
return s;
}
-static char *
-_pscien(long double r, register char *s, int n, int flags)
+static char*
+_pscien(long double r, register char* s, int n, int flags)
{
- int sign, dp;
- register char *s1;
+ int sign, dp;
+ register char* s1;
s1 = _ecvt(r, n + 1, &dp, &sign);
if (sign)
if ((n > 0) || (flags & FL_ALT))
*s++ = '.';
while (--n >= 0)
- if (*s1) *s++ = *s1++;
- else *s++ = '0';
+ if (*s1)
+ *s++ = *s1++;
+ else
+ *s++ = '0';
*s++ = 'e';
- if ( r != 0 ) --dp ;
- if ( dp<0 ) {
- *s++ = '-' ; dp= -dp ;
- } else {
- *s++ = '+' ;
+ if (r != 0)
+ --dp;
+ if (dp < 0)
+ {
+ *s++ = '-';
+ dp = -dp;
+ }
+ else
+ {
+ *s++ = '+';
}
- if (dp >= 100) {
+ if (dp >= 100)
+ {
*s++ = '0' + (dp / 100);
dp %= 100;
}
- *s++ = '0' + (dp/10);
- *s++ = '0' + (dp%10);
+ *s++ = '0' + (dp / 10);
+ *s++ = '0' + (dp % 10);
return s;
}
-#define NDIGINEXP(exp) (((exp) >= 100 || (exp) <= -100) ? 3 : 2)
-#define LOW_EXP -4
-#define USE_EXP(exp, ndigits) (((exp) < LOW_EXP + 1) || (exp >= ndigits + 1))
+#define NDIGINEXP(exp) (((exp) >= 100 || (exp) <= -100) ? 3 : 2)
+#define LOW_EXP -4
+#define USE_EXP(exp, ndigits) (((exp) < LOW_EXP + 1) || (exp >= ndigits + 1))
-static char *
-_gcvt(long double value, int ndigit, char *s, int flags)
+static char*
+_gcvt(long double value, int ndigit, char* s, int flags)
{
int sign, dp;
register char *s1, *s2;
s1 = _ecvt(value, ndigit, &dp, &sign);
s2 = s;
- if (sign) *s2++ = '-';
+ if (sign)
+ *s2++ = '-';
else if (flags & FL_SIGN)
*s2++ = '+';
else if (flags & FL_SPACE)
for (i = nndigit - 1; i > 0 && s1[i] == '0'; i--)
nndigit--;
- if (USE_EXP(dp,ndigit)) {
+ if (USE_EXP(dp, ndigit))
+ {
/* Use E format */
dp--;
*s2++ = *s1++;
- if ((nndigit > 1) || (flags & FL_ALT)) *s2++ = '.';
- while (--nndigit > 0) *s2++ = *s1++;
+ if ((nndigit > 1) || (flags & FL_ALT))
+ *s2++ = '.';
+ while (--nndigit > 0)
+ *s2++ = *s1++;
*s2++ = 'e';
- if (dp < 0) {
+ if (dp < 0)
+ {
*s2++ = '-';
dp = -dp;
}
- else *s2++ = '+';
+ else
+ *s2++ = '+';
s2 += NDIGINEXP(dp);
*s2 = 0;
- for (i = NDIGINEXP(dp); i > 0; i--) {
+ for (i = NDIGINEXP(dp); i > 0; i--)
+ {
*--s2 = dp % 10 + '0';
dp /= 10;
}
return s;
}
/* Use f format */
- if (dp <= 0) {
- if (*s1 != '0') {
+ if (dp <= 0)
+ {
+ if (*s1 != '0')
+ {
/* otherwise the whole number is 0 */
*s2++ = '0';
*s2++ = '.';
}
- while (dp < 0) {
+ while (dp < 0)
+ {
dp++;
*s2++ = '0';
}
}
- for (i = 1; i <= nndigit; i++) {
+ for (i = 1; i <= nndigit; i++)
+ {
*s2++ = *s1++;
- if (i == dp) *s2++ = '.';
+ if (i == dp)
+ *s2++ = '.';
}
- if (i <= dp) {
- while (i++ <= dp) *s2++ = '0';
+ if (i <= dp)
+ {
+ while (i++ <= dp)
+ *s2++ = '0';
*s2++ = '.';
}
- if ((s2[-1]=='.') && !(flags & FL_ALT)) s2--;
+ if ((s2[-1] == '.') && !(flags & FL_ALT))
+ s2--;
*s2 = '\0';
return s;
}
-char *
-_f_print(va_list *ap, int flags, char *s, char c, int precision)
+char* _f_print(va_list* ap, int flags, char* s, char c, int precision)
{
- register char *old_s = s;
+ register char* old_s = s;
long double ld_val;
- if (flags & FL_LONGDOUBLE) ld_val = va_arg(*ap, long double);
- else ld_val = (long double) va_arg(*ap, double);
-
- switch(c) {
- case 'f':
- s = _pfloat(ld_val, s, precision, flags);
- break;
- case 'e':
- case 'E':
- s = _pscien(ld_val, s, precision , flags);
- break;
- case 'g':
- case 'G':
- s = _gcvt(ld_val, precision, s, flags);
- s += strlen(s);
- break;
+ if (flags & FL_LONGDOUBLE)
+ ld_val = va_arg(*ap, long double);
+ else
+ ld_val = (long double)va_arg(*ap, double);
+
+ switch (c)
+ {
+ case 'f':
+ s = _pfloat(ld_val, s, precision, flags);
+ break;
+ case 'e':
+ case 'E':
+ s = _pscien(ld_val, s, precision, flags);
+ break;
+ case 'g':
+ case 'G':
+ s = _gcvt(ld_val, precision, s, flags);
+ s += strlen(s);
+ break;
}
- if ( c == 'E' || c == 'G') {
- while (*old_s && *old_s != 'e') old_s++;
- if (*old_s == 'e') *old_s = 'E';
+ if (c == 'E' || c == 'G')
+ {
+ while (*old_s && *old_s != 'e')
+ old_s++;
+ if (*old_s == 'e')
+ *old_s = 'E';
}
return s;
}
-#endif /* ACKCONF_NO_STDIO_FLOAT */
+#endif /* ACKCONF_NO_STDIO_FLOAT */
extern void (*_clean)(void);
static int
-do_write(int d, char *buf, int nbytes)
+do_write(int d, char* buf, int nbytes)
{
int c;
/* POSIX actually allows write() to return a positive value less
than nbytes, so loop ...
*/
- while ((c = write(d, buf, nbytes)) > 0 && c < nbytes) {
+ while ((c = write(d, buf, nbytes)) > 0 && c < nbytes)
+ {
nbytes -= c;
buf += c;
}
return c > 0;
}
-int
-__flushbuf(int c, FILE * stream)
+int __flushbuf(int c, FILE* stream)
{
_clean = __cleanup;
- if (fileno(stream) < 0) return EOF;
- if (!io_testflag(stream, _IOWRITE)) return EOF;
- if (io_testflag(stream, _IOREADING) && !feof(stream)) return EOF;
+ if (fileno(stream) < 0)
+ return EOF;
+ if (!io_testflag(stream, _IOWRITE))
+ return EOF;
+ if (io_testflag(stream, _IOREADING) && !feof(stream))
+ return EOF;
stream->_flags &= ~_IOREADING;
stream->_flags |= _IOWRITING;
- if (!io_testflag(stream, _IONBF)) {
- if (!stream->_buf) {
- if (stream == stdout && isatty(fileno(stdout))) {
- if (!(stream->_buf =
- (unsigned char *) malloc(BUFSIZ))) {
+ if (!io_testflag(stream, _IONBF))
+ {
+ if (!stream->_buf)
+ {
+ if (stream == stdout && isatty(fileno(stdout)))
+ {
+ if (!(stream->_buf = (unsigned char*)malloc(BUFSIZ)))
+ {
stream->_flags |= _IONBF;
- } else {
- stream->_flags |= _IOLBF|_IOMYBUF;
+ }
+ else
+ {
+ stream->_flags |= _IOLBF | _IOMYBUF;
stream->_bufsiz = BUFSIZ;
stream->_count = -1;
}
- } else {
- if (!(stream->_buf =
- (unsigned char *) malloc(BUFSIZ))) {
+ }
+ else
+ {
+ if (!(stream->_buf = (unsigned char*)malloc(BUFSIZ)))
+ {
stream->_flags |= _IONBF;
- } else {
+ }
+ else
+ {
stream->_flags |= _IOMYBUF;
stream->_bufsiz = BUFSIZ;
if (!io_testflag(stream, _IOLBF))
stream->_count = BUFSIZ - 1;
- else stream->_count = -1;
+ else
+ stream->_count = -1;
}
}
stream->_ptr = stream->_buf;
}
}
- if (io_testflag(stream, _IONBF)) {
+ if (io_testflag(stream, _IONBF))
+ {
char c1 = c;
stream->_count = 0;
- if (io_testflag(stream, _IOAPPEND)) {
- if (lseek(fileno(stream), 0L, SEEK_END) == -1) {
+ if (io_testflag(stream, _IOAPPEND))
+ {
+ if (lseek(fileno(stream), 0L, SEEK_END) == -1)
+ {
stream->_flags |= _IOERR;
return EOF;
}
}
- if (write(fileno(stream), &c1, 1) != 1) {
+ if (write(fileno(stream), &c1, 1) != 1)
+ {
stream->_flags |= _IOERR;
return EOF;
}
- return (unsigned char) c;
- } else if (io_testflag(stream, _IOLBF)) {
+ return (unsigned char)c;
+ }
+ else if (io_testflag(stream, _IOLBF))
+ {
*stream->_ptr++ = c;
/* stream->_count has been updated in putc macro. */
- if (c == '\n' || stream->_count == -stream->_bufsiz) {
+ if (c == '\n' || stream->_count == -stream->_bufsiz)
+ {
int count = -stream->_count;
- stream->_ptr = stream->_buf;
+ stream->_ptr = stream->_buf;
stream->_count = 0;
- if (io_testflag(stream, _IOAPPEND)) {
- if (lseek(fileno(stream), 0L, SEEK_END) == -1) {
+ if (io_testflag(stream, _IOAPPEND))
+ {
+ if (lseek(fileno(stream), 0L, SEEK_END) == -1)
+ {
stream->_flags |= _IOERR;
return EOF;
}
}
- if (! do_write(fileno(stream), (char *)stream->_buf,
- count)) {
+ if (!do_write(fileno(stream), (char*)stream->_buf,
+ count))
+ {
stream->_flags |= _IOERR;
return EOF;
}
}
- } else {
+ }
+ else
+ {
int count = stream->_ptr - stream->_buf;
stream->_count = stream->_bufsiz - 1;
stream->_ptr = stream->_buf + 1;
- if (count > 0) {
- if (io_testflag(stream, _IOAPPEND)) {
- if (lseek(fileno(stream), 0L, SEEK_END) == -1) {
+ if (count > 0)
+ {
+ if (io_testflag(stream, _IOAPPEND))
+ {
+ if (lseek(fileno(stream), 0L, SEEK_END) == -1)
+ {
stream->_flags |= _IOERR;
return EOF;
}
}
- if (! do_write(fileno(stream), (char *)stream->_buf, count)) {
+ if (!do_write(fileno(stream), (char*)stream->_buf, count))
+ {
*(stream->_buf) = c;
stream->_flags |= _IOERR;
return EOF;
}
*(stream->_buf) = c;
}
- return (unsigned char) c;
+ return (unsigned char)c;
}
#include <unistd.h>
#include "loc_incl.h"
-#define PMODE 0666
+#define PMODE 0666
/* Since the O_CREAT flag is not available on all systems, we can't get it
* from the standard library. Furthermore, even if we know that <fcntl.h>
* Remember to fix freopen.c if changing this.
*/
-FILE *
-fopen(const char *name, const char *mode)
+FILE* fopen(const char* name, const char* mode)
{
register int i;
int rwmode = 0, rwflags = 0;
- FILE *stream;
+ FILE* stream;
int fd, flags = 0;
- for (i = 0; __iotab[i] != 0 ; i++)
- if ( i >= FOPEN_MAX-1 )
- return (FILE *)NULL;
+ for (i = 0; __iotab[i] != 0; i++)
+ if (i >= FOPEN_MAX - 1)
+ return (FILE*)NULL;
- switch(*mode++) {
- case 'r':
- flags |= _IOREAD | _IOREADING;
- rwmode = O_RDONLY;
- break;
- case 'w':
- flags |= _IOWRITE | _IOWRITING;
- rwmode = O_WRONLY;
- rwflags = O_CREAT | O_TRUNC;
- break;
- case 'a':
- flags |= _IOWRITE | _IOWRITING | _IOAPPEND;
- rwmode = O_WRONLY;
- rwflags |= O_APPEND | O_CREAT;
- break;
- default:
- return (FILE *)NULL;
+ switch (*mode++)
+ {
+ case 'r':
+ flags |= _IOREAD | _IOREADING;
+ rwmode = O_RDONLY;
+ break;
+ case 'w':
+ flags |= _IOWRITE | _IOWRITING;
+ rwmode = O_WRONLY;
+ rwflags = O_CREAT | O_TRUNC;
+ break;
+ case 'a':
+ flags |= _IOWRITE | _IOWRITING | _IOAPPEND;
+ rwmode = O_WRONLY;
+ rwflags |= O_APPEND | O_CREAT;
+ break;
+ default:
+ return (FILE*)NULL;
}
- while (*mode) {
- switch(*mode++) {
- case 'b':
- continue;
- case '+':
- rwmode = O_RDWR;
- flags |= _IOREAD | _IOWRITE;
- continue;
- /* The sequence may be followed by additional characters */
- default:
- break;
+ while (*mode)
+ {
+ switch (*mode++)
+ {
+ case 'b':
+ continue;
+ case '+':
+ rwmode = O_RDWR;
+ flags |= _IOREAD | _IOWRITE;
+ continue;
+ /* The sequence may be followed by additional characters */
+ default:
+ break;
}
break;
}
*/
if ((rwflags & O_TRUNC)
|| (((fd = open(name, rwmode)) < 0)
- && (rwflags & O_CREAT))) {
- if (((fd = creat(name, PMODE)) > 0) && flags | _IOREAD) {
- (void) close(fd);
+ && (rwflags & O_CREAT)))
+ {
+ if (((fd = creat(name, PMODE)) > 0) && flags | _IOREAD)
+ {
+ (void)close(fd);
fd = open(name, rwmode);
}
-
}
- if (fd < 0) return (FILE *)NULL;
+ if (fd < 0)
+ return (FILE*)NULL;
- if (( stream = (FILE *) malloc(sizeof(FILE))) == NULL ) {
+ if ((stream = (FILE*)malloc(sizeof(FILE))) == NULL)
+ {
close(fd);
- return (FILE *)NULL;
+ return (FILE*)NULL;
}
- if ((flags & (_IOREAD | _IOWRITE)) == (_IOREAD | _IOWRITE))
+ if ((flags & (_IOREAD | _IOWRITE)) == (_IOREAD | _IOWRITE))
flags &= ~(_IOREADING | _IOWRITING);
stream->_count = 0;
*/
/* $Id$ */
-#include <stdio.h>
-#include <stdarg.h>
-#include "loc_incl.h"
+#include <stdio.h>
+#include <stdarg.h>
+#include "loc_incl.h"
-int
-fprintf(FILE *stream, const char *format, ...)
+int fprintf(FILE* stream, const char* format, ...)
{
va_list ap;
int retval;
-
+
va_start(ap, format);
- retval = _doprnt (format, ap, stream);
+ retval = _doprnt(format, ap, stream);
va_end(ap);
*/
/* $Id$ */
-#include <stdio.h>
+#include <stdio.h>
-int
-fputc(int c, FILE *stream)
+int fputc(int c, FILE* stream)
{
return putc(c, stream);
}
*/
/* $Id$ */
-#include <stdio.h>
+#include <stdio.h>
-int
-fputs(register const char *s, register FILE *stream)
+int fputs(register const char* s, register FILE* stream)
{
register int i = 0;
- while (*s)
- if (putc(*s++, stream) == EOF) return EOF;
- else i++;
+ while (*s)
+ if (putc(*s++, stream) == EOF)
+ return EOF;
+ else
+ i++;
return i;
}
*/
/* $Id$ */
-#include <stdio.h>
+#include <stdio.h>
size_t
-fread(void *ptr, size_t size, size_t nmemb, register FILE *stream)
+fread(void* ptr, size_t size, size_t nmemb, register FILE* stream)
{
- register char *cp = ptr;
+ register char* cp = ptr;
register int c;
size_t ndone = 0;
register size_t s;
if (size)
- while ( ndone < nmemb ) {
+ while (ndone < nmemb)
+ {
s = size;
- do {
+ do
+ {
if ((c = getc(stream)) != EOF)
*cp++ = c;
else
#include <unistd.h>
#include "loc_incl.h"
-#define PMODE 0666
+#define PMODE 0666
/* Do not "optimize" this file to use the open with O_CREAT if the file
* does not exist. The reason is given in fopen.c.
*/
-FILE *
-freopen(const char *name, const char *mode, FILE *stream)
+FILE* freopen(const char* name, const char* mode, FILE* stream)
{
register int i;
int rwmode = 0, rwflags = 0;
int fd, flags = stream->_flags & (_IONBF | _IOFBF | _IOLBF | _IOMYBUF);
- (void) fflush(stream); /* ignore errors */
- (void) close(fileno(stream));
+ (void)fflush(stream); /* ignore errors */
+ (void)close(fileno(stream));
- switch(*mode++) {
- case 'r':
- flags |= _IOREAD;
- rwmode = O_RDONLY;
- break;
- case 'w':
- flags |= _IOWRITE;
- rwmode = O_WRONLY;
- rwflags = O_CREAT | O_TRUNC;
- break;
- case 'a':
- flags |= _IOWRITE | _IOAPPEND;
- rwmode = O_WRONLY;
- rwflags |= O_APPEND | O_CREAT;
- break;
- default:
- return (FILE *)NULL;
+ switch (*mode++)
+ {
+ case 'r':
+ flags |= _IOREAD;
+ rwmode = O_RDONLY;
+ break;
+ case 'w':
+ flags |= _IOWRITE;
+ rwmode = O_WRONLY;
+ rwflags = O_CREAT | O_TRUNC;
+ break;
+ case 'a':
+ flags |= _IOWRITE | _IOAPPEND;
+ rwmode = O_WRONLY;
+ rwflags |= O_APPEND | O_CREAT;
+ break;
+ default:
+ return (FILE*)NULL;
}
- while (*mode) {
- switch(*mode++) {
- case 'b':
- continue;
- case '+':
- rwmode = O_RDWR;
- flags |= _IOREAD | _IOWRITE;
- continue;
- /* The sequence may be followed by aditional characters */
- default:
- break;
+ while (*mode)
+ {
+ switch (*mode++)
+ {
+ case 'b':
+ continue;
+ case '+':
+ rwmode = O_RDWR;
+ flags |= _IOREAD | _IOWRITE;
+ continue;
+ /* The sequence may be followed by aditional characters */
+ default:
+ break;
}
break;
}
if ((rwflags & O_TRUNC)
|| (((fd = open(name, rwmode)) < 0)
- && (rwflags & O_CREAT))) {
- if (((fd = creat(name, PMODE)) < 0) && flags | _IOREAD) {
- (void) close(fd);
+ && (rwflags & O_CREAT)))
+ {
+ if (((fd = creat(name, PMODE)) < 0) && flags | _IOREAD)
+ {
+ (void)close(fd);
fd = open(name, rwmode);
}
}
- if (fd < 0) {
- for( i = 0; i < FOPEN_MAX; i++) {
- if (stream == __iotab[i]) {
+ if (fd < 0)
+ {
+ for (i = 0; i < FOPEN_MAX; i++)
+ {
+ if (stream == __iotab[i])
+ {
__iotab[i] = 0;
break;
}
}
if (stream != stdin && stream != stdout && stream != stderr)
- free((void *)stream);
- return (FILE *)NULL;
+ free((void*)stream);
+ return (FILE*)NULL;
}
stream->_count = 0;
*/
/* $Id$ */
-#include <stdio.h>
-#include <stdarg.h>
-#include "loc_incl.h"
+#include <stdio.h>
+#include <stdarg.h>
+#include "loc_incl.h"
-int
-fscanf(FILE *stream, const char *format, ...)
+int fscanf(FILE* stream, const char* format, ...)
{
va_list ap;
int retval;
#include <unistd.h>
#include "loc_incl.h"
-int
-fseek(FILE *stream, long int offset, int whence)
+int fseek(FILE* stream, long int offset, int whence)
{
int adjust = 0;
long pos;
stream->_flags &= ~(_IOEOF | _IOERR);
/* Clear both the end of file and error flags */
- if (io_testflag(stream, _IOREADING)) {
+ if (io_testflag(stream, _IOREADING))
+ {
if (whence == SEEK_CUR
&& stream->_buf
- && !io_testflag(stream,_IONBF))
+ && !io_testflag(stream, _IONBF))
adjust = stream->_count;
stream->_count = 0;
- } else if (io_testflag(stream,_IOWRITING)) {
+ }
+ else if (io_testflag(stream, _IOWRITING))
+ {
fflush(stream);
- } else /* neither reading nor writing. The buffer must be empty */
- /* EMPTY */ ;
+ }
+ else /* neither reading nor writing. The buffer must be empty */
+ /* EMPTY */;
pos = lseek(fileno(stream), offset - adjust, whence);
if (io_testflag(stream, _IOREAD) && io_testflag(stream, _IOWRITE))
*/
/* $Id$ */
-#include <stdio.h>
+#include <stdio.h>
-int
-fsetpos(FILE *stream, fpos_t *pos)
+int fsetpos(FILE* stream, fpos_t* pos)
{
return fseek(stream, *pos, SEEK_SET);
}
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
-#include "loc_incl.h"
+#include "loc_incl.h"
-long ftell(FILE *stream)
+long ftell(FILE* stream)
{
long result;
int adjust = 0;
- if (io_testflag(stream,_IOREADING))
+ if (io_testflag(stream, _IOREADING))
adjust = -stream->_count;
- else if (io_testflag(stream,_IOWRITING)
- && stream->_buf
- && !io_testflag(stream,_IONBF))
+ else if (io_testflag(stream, _IOWRITING)
+ && stream->_buf
+ && !io_testflag(stream, _IONBF))
adjust = stream->_ptr - stream->_buf;
- else adjust = 0;
+ else
+ adjust = 0;
result = lseek(fileno(stream), 0, SEEK_CUR);
- if ( result == -1 )
+ if (result == -1)
return result;
- result += (long) adjust;
+ result += (long)adjust;
return result;
}
*/
/* $Id$ */
-#include <stdio.h>
+#include <stdio.h>
size_t
-fwrite(const void *ptr, size_t size, size_t nmemb,
- register FILE *stream)
+fwrite(const void* ptr, size_t size, size_t nmemb,
+ register FILE* stream)
{
- register const unsigned char *cp = ptr;
+ register const unsigned char* cp = ptr;
register size_t s;
size_t ndone = 0;
if (size)
- while ( ndone < nmemb ) {
+ while (ndone < nmemb)
+ {
s = size;
- do {
+ do
+ {
if (putc((int)*cp, stream)
- == EOF)
+ == EOF)
return ndone;
cp++;
- }
- while (--s);
+ } while (--s);
ndone++;
}
return ndone;
*/
/* $Id$ */
-#include <stdio.h>
+#include <stdio.h>
-int
-(getc)(FILE *stream)
+int(getc)(FILE* stream)
{
return getc(stream);
}
*/
/* $Id$ */
-#include <stdio.h>
+#include <stdio.h>
-int
-(getchar)(void)
+int(getchar)(void)
{
return getchar();
}
*/
/* $Id$ */
-#include <stdio.h>
+#include <stdio.h>
-char *
-gets(char *s)
+char* gets(char* s)
{
- register FILE *stream = stdin;
+ register FILE* stream = stdin;
register int ch;
- register char *ptr;
+ register char* ptr;
ptr = s;
while ((ch = getc(stream)) != EOF && ch != '\n')
*ptr++ = ch;
- if (ch == EOF) {
- if (feof(stream)) {
- if (ptr == s) return NULL;
- } else return NULL;
+ if (ch == EOF)
+ {
+ if (feof(stream))
+ {
+ if (ptr == s)
+ return NULL;
+ }
+ else
+ return NULL;
}
*ptr = '\0';
*/
/* $Id$ */
-#include "loc_incl.h"
+#include "loc_incl.h"
/* This routine is used in doprnt.c as well as in tmpfile.c and tmpnam.c. */
-char *
-_i_compute(unsigned long val, int base, char *s, int nrdigits)
+char* _i_compute(unsigned long val, int base, char* s, int nrdigits)
{
int c;
- c= val % base ;
- val /= base ;
+ c = val % base;
+ val /= base;
if (val || nrdigits > 1)
s = _i_compute(val, base, s, nrdigits - 1);
- *s++ = (c>9 ? c-10+'a' : c+'0');
+ *s++ = (c > 9 ? c - 10 + 'a' : c + '0');
return s;
}
*/
/* $Id$ */
-int _gtty(int d, char *buf);
+int _gtty(int d, char* buf);
int _isatty(int d)
{
- char buf[128];
+ char buf[128];
/* not a sgttyb struct; it might not be large enough;
I know for a fact that it isn't large enough on PC/IX,
where gtty is an ioctl(..., TCGETA, ...)
*/
/* $Id$ */
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
-void
-perror(const char *s)
+void perror(const char* s)
{
- if (s && *s) {
- (void) fputs(s, stderr);
- (void) fputs(": ", stderr);
+ if (s && *s)
+ {
+ (void)fputs(s, stderr);
+ (void)fputs(": ", stderr);
}
- (void) fputs(strerror(errno), stderr);
- (void) fputs("\n", stderr);
+ (void)fputs(strerror(errno), stderr);
+ (void)fputs("\n", stderr);
}
*/
/* $Id$ */
-#include <stdio.h>
-#include <stdarg.h>
-#include "loc_incl.h"
+#include <stdio.h>
+#include <stdarg.h>
+#include "loc_incl.h"
-int
-printf(const char *format, ...)
+int printf(const char* format, ...)
{
va_list ap;
int retval;
*/
/* $Id$ */
-#include <stdio.h>
+#include <stdio.h>
-int
-(putc)(int c, FILE *stream)
+int(putc)(int c, FILE* stream)
{
return putc(c, stream);
}
*/
/* $Id$ */
-#include <stdio.h>
+#include <stdio.h>
-int
-(putchar)(int c)
+int(putchar)(int c)
{
return putchar(c);
}
*/
/* $Id$ */
-#include <stdio.h>
+#include <stdio.h>
-int
-puts(register const char *s)
+int puts(register const char* s)
{
- register FILE *file = stdout;
+ register FILE* file = stdout;
register int i = 0;
- while (*s) {
- if (putc(*s++, file) == EOF) return EOF;
- else i++;
+ while (*s)
+ {
+ if (putc(*s++, file) == EOF)
+ return EOF;
+ else
+ i++;
}
- if (putc('\n', file) == EOF) return EOF;
+ if (putc('\n', file) == EOF)
+ return EOF;
return i + 1;
}
#include <stdio.h>
#include <unistd.h>
-int
-remove(const char *filename) {
+int remove(const char* filename)
+{
return unlink(filename);
}
*/
/* $Id$ */
-#include <stdio.h>
-#include "loc_incl.h"
+#include <stdio.h>
+#include "loc_incl.h"
-void
-rewind(FILE *stream)
+void rewind(FILE* stream)
{
- (void) fseek(stream, 0L, SEEK_SET);
+ (void)fseek(stream, 0L, SEEK_SET);
clearerr(stream);
}
*/
/* $Id$ */
-#include <stdio.h>
-#include <stdarg.h>
-#include "loc_incl.h"
+#include <stdio.h>
+#include <stdarg.h>
+#include "loc_incl.h"
-int
-scanf(const char *format, ...)
+int scanf(const char* format, ...)
{
va_list ap;
int retval;
return retval;
}
-
-
*/
/* $Id$ */
-#include <stdio.h>
-#include "loc_incl.h"
+#include <stdio.h>
+#include "loc_incl.h"
-void
-setbuf(register FILE *stream, char *buf)
+void setbuf(register FILE* stream, char* buf)
{
- (void) setvbuf(stream, buf, (buf ? _IOFBF : _IONBF), (size_t) BUFSIZ);
+ (void)setvbuf(stream, buf, (buf ? _IOFBF : _IONBF), (size_t)BUFSIZ);
}
*/
/* $Id$ */
-#include <stdio.h>
-#include <stdlib.h>
-#include "loc_incl.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "loc_incl.h"
extern void (*_clean)(void);
-int
-setvbuf(register FILE *stream, char *buf, int mode, size_t size)
+int setvbuf(register FILE* stream, char* buf, int mode, size_t size)
{
int retval = 0;
if (mode != _IOFBF && mode != _IOLBF && mode != _IONBF)
return EOF;
- if (stream->_buf && io_testflag(stream,_IOMYBUF) )
- free((void *)stream->_buf);
+ if (stream->_buf && io_testflag(stream, _IOMYBUF))
+ free((void*)stream->_buf);
stream->_flags &= ~(_IOMYBUF | _IONBF | _IOLBF);
- if (buf && size <= 0) retval = EOF;
- if (!buf && (mode != _IONBF)) {
- if (size <= 0 || (buf = (char *) malloc(size)) == NULL) {
+ if (buf && size <= 0)
+ retval = EOF;
+ if (!buf && (mode != _IONBF))
+ {
+ if (size <= 0 || (buf = (char*)malloc(size)) == NULL)
+ {
retval = EOF;
- } else {
+ }
+ else
+ {
stream->_flags |= _IOMYBUF;
}
}
- stream->_buf = (unsigned char *) buf;
+ stream->_buf = (unsigned char*)buf;
stream->_count = 0;
stream->_flags |= mode;
stream->_ptr = stream->_buf;
- if (!buf) {
+ if (!buf)
+ {
stream->_bufsiz = 1;
- } else {
+ }
+ else
+ {
stream->_bufsiz = size;
}
*/
/* $Id$ */
-#include <stdio.h>
-#include <stdarg.h>
-#include "loc_incl.h"
+#include <stdio.h>
+#include <stdarg.h>
+#include "loc_incl.h"
-int
-snprintf(char * s, size_t len, const char *format, ...)
+int snprintf(char* s, size_t len, const char* format, ...)
{
va_list ap;
int retval;
va_start(ap, format);
- tmp_stream._fd = -1;
- tmp_stream._flags = _IOWRITE + _IONBF + _IOWRITING;
- tmp_stream._buf = (unsigned char *) s;
- tmp_stream._ptr = (unsigned char *) s;
- tmp_stream._count = len;
+ tmp_stream._fd = -1;
+ tmp_stream._flags = _IOWRITE + _IONBF + _IOWRITING;
+ tmp_stream._buf = (unsigned char*)s;
+ tmp_stream._ptr = (unsigned char*)s;
+ tmp_stream._count = len;
retval = _doprnt(format, ap, &tmp_stream);
- putc('\0',&tmp_stream);
+ putc('\0', &tmp_stream);
va_end(ap);
*/
/* $Id$ */
-#include <stdio.h>
-#include <stdarg.h>
-#include "loc_incl.h"
+#include <stdio.h>
+#include <stdarg.h>
+#include "loc_incl.h"
-int
-sprintf(char * s, const char *format, ...)
+int sprintf(char* s, const char* format, ...)
{
va_list ap;
int retval;
va_start(ap, format);
- tmp_stream._fd = -1;
- tmp_stream._flags = _IOWRITE + _IONBF + _IOWRITING;
- tmp_stream._buf = (unsigned char *) s;
- tmp_stream._ptr = (unsigned char *) s;
- tmp_stream._count = 32767;
+ tmp_stream._fd = -1;
+ tmp_stream._flags = _IOWRITE + _IONBF + _IOWRITING;
+ tmp_stream._buf = (unsigned char*)s;
+ tmp_stream._ptr = (unsigned char*)s;
+ tmp_stream._count = 32767;
retval = _doprnt(format, ap, &tmp_stream);
- putc('\0',&tmp_stream);
+ putc('\0', &tmp_stream);
va_end(ap);
*/
/* $Id$ */
-#include <stdio.h>
-#include <stdarg.h>
-#include <string.h>
-#include "loc_incl.h"
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+#include "loc_incl.h"
-int sscanf(const char *s, const char *format, ...)
+int sscanf(const char* s, const char* format, ...)
{
va_list ap;
int retval;
va_start(ap, format);
- tmp_stream._fd = -1;
- tmp_stream._flags = _IOREAD + _IONBF + _IOREADING;
- tmp_stream._buf = (unsigned char *) s;
- tmp_stream._ptr = (unsigned char *) s;
- tmp_stream._count = strlen(s);
+ tmp_stream._fd = -1;
+ tmp_stream._flags = _IOREAD + _IONBF + _IOREADING;
+ tmp_stream._buf = (unsigned char*)s;
+ tmp_stream._ptr = (unsigned char*)s;
+ tmp_stream._count = strlen(s);
retval = _doscan(&tmp_stream, format, ap);
#include <string.h>
#include "loc_incl.h"
-FILE *
-tmpfile(void) {
- static char name_buffer[L_tmpnam] = "/tmp/tmp." ;
- static char *name = NULL;
- FILE *file;
+FILE* tmpfile(void)
+{
+ static char name_buffer[L_tmpnam] = "/tmp/tmp.";
+ static char* name = NULL;
+ FILE* file;
- if (!name) {
+ if (!name)
+ {
name = name_buffer + strlen(name_buffer);
name = _i_compute(getpid(), 10, name, 5);
*name = '\0';
}
- file = fopen(name_buffer,"wb+");
- if (!file) return (FILE *)NULL;
- (void) remove(name_buffer);
+ file = fopen(name_buffer, "wb+");
+ if (!file)
+ return (FILE*)NULL;
+ (void)remove(name_buffer);
return file;
}
#include <unistd.h>
#include "loc_incl.h"
-char *
-tmpnam(char *s) {
+char* tmpnam(char* s)
+{
static char name_buffer[L_tmpnam] = "/tmp/tmp.";
static unsigned long count = 0;
- static char *name = NULL;
+ static char* name = NULL;
- if (!name) {
+ if (!name)
+ {
name = name_buffer + strlen(name_buffer);
name = _i_compute(getpid(), 10, name, 5);
*name++ = '.';
*name = '\0';
}
- if (++count > TMP_MAX) count = 1; /* wrap-around */
+ if (++count > TMP_MAX)
+ count = 1; /* wrap-around */
*_i_compute(count, 10, name, 3) = '\0';
- if (s) return strcpy(s, name_buffer);
- else return name_buffer;
+ if (s)
+ return strcpy(s, name_buffer);
+ else
+ return name_buffer;
}
*/
/* $Id$ */
-#include <stdio.h>
-#include "loc_incl.h"
+#include <stdio.h>
+#include "loc_incl.h"
-int
-ungetc(int ch, FILE *stream)
+int ungetc(int ch, FILE* stream)
{
- unsigned char *p;
+ unsigned char* p;
- if (ch == EOF || !io_testflag(stream,_IOREADING))
+ if (ch == EOF || !io_testflag(stream, _IOREADING))
return EOF;
- if (stream->_ptr == stream->_buf) {
- if (stream->_count != 0) return EOF;
+ if (stream->_ptr == stream->_buf)
+ {
+ if (stream->_count != 0)
+ return EOF;
stream->_ptr++;
}
stream->_count++;
- p = --(stream->_ptr); /* ??? Bloody vax assembler !!! */
+ p = --(stream->_ptr); /* ??? Bloody vax assembler !!! */
/* ungetc() in sscanf() shouldn't write in rom */
- if (*p != (unsigned char) ch)
- *p = (unsigned char) ch;
+ if (*p != (unsigned char)ch)
+ *p = (unsigned char)ch;
return ch;
}
*/
/* $Id$ */
-#include <stdio.h>
-#include <stdarg.h>
-#include "loc_incl.h"
+#include <stdio.h>
+#include <stdarg.h>
+#include "loc_incl.h"
-int
-vfprintf(FILE *stream, const char *format, va_list arg)
+int vfprintf(FILE* stream, const char* format, va_list arg)
{
- return _doprnt (format, arg, stream);
+ return _doprnt(format, arg, stream);
}
*/
/* $Id$ */
-#include <stdio.h>
-#include <stdarg.h>
-#include "loc_incl.h"
+#include <stdio.h>
+#include <stdarg.h>
+#include "loc_incl.h"
-int
-vprintf(const char *format, va_list arg)
+int vprintf(const char* format, va_list arg)
{
return _doprnt(format, arg, stdout);
}
*/
/* $Id$ */
-#include <stdio.h>
-#include <stdarg.h>
-#include "loc_incl.h"
+#include <stdio.h>
+#include <stdarg.h>
+#include "loc_incl.h"
-int
-vsnprintf(char *s, size_t len, const char *format, va_list arg)
+int vsnprintf(char* s, size_t len, const char* format, va_list arg)
{
int retval;
FILE tmp_stream;
- tmp_stream._fd = -1;
- tmp_stream._flags = _IOWRITE + _IONBF + _IOWRITING;
- tmp_stream._buf = (unsigned char *) s;
- tmp_stream._ptr = (unsigned char *) s;
- tmp_stream._count = len;
+ tmp_stream._fd = -1;
+ tmp_stream._flags = _IOWRITE + _IONBF + _IOWRITING;
+ tmp_stream._buf = (unsigned char*)s;
+ tmp_stream._ptr = (unsigned char*)s;
+ tmp_stream._count = len;
retval = _doprnt(format, arg, &tmp_stream);
- putc('\0',&tmp_stream);
+ putc('\0', &tmp_stream);
return retval;
}
*/
/* $Id$ */
-#include <stdio.h>
-#include <stdarg.h>
-#include "loc_incl.h"
+#include <stdio.h>
+#include <stdarg.h>
+#include "loc_incl.h"
-int
-vsprintf(char *s, const char *format, va_list arg)
+int vsprintf(char* s, const char* format, va_list arg)
{
int retval;
FILE tmp_stream;
- tmp_stream._fd = -1;
- tmp_stream._flags = _IOWRITE + _IONBF + _IOWRITING;
- tmp_stream._buf = (unsigned char *) s;
- tmp_stream._ptr = (unsigned char *) s;
- tmp_stream._count = 32767;
+ tmp_stream._fd = -1;
+ tmp_stream._flags = _IOWRITE + _IONBF + _IOWRITING;
+ tmp_stream._buf = (unsigned char*)s;
+ tmp_stream._ptr = (unsigned char*)s;
+ tmp_stream._count = 32767;
retval = _doprnt(format, arg, &tmp_stream);
- putc('\0',&tmp_stream);
+ putc('\0', &tmp_stream);
return retval;
}
*/
/* $Id$ */
-#if defined(_POSIX_SOURCE)
-#include <sys/types.h>
+#if defined(_POSIX_SOURCE)
+#include <sys/types.h>
#endif
-#include <signal.h>
-#include <stdlib.h>
+#include <signal.h>
+#include <stdlib.h>
extern void (*_clean)(void);
-void
-abort(void)
+void abort(void)
{
- if (_clean) _clean(); /* flush all output files */
+ if (_clean)
+ _clean(); /* flush all output files */
raise(SIGABRT);
}
-
*/
/* $Id$ */
-#include <stdlib.h>
+#include <stdlib.h>
-int
-abs(register int i)
+int abs(register int i)
{
return i >= 0 ? i : -i;
}
/* $Id$ */
-#include <stdlib.h>
+#include <stdlib.h>
-#define NEXITS 32
+#define NEXITS 32
extern void (*__functab[NEXITS])(void);
extern int __funccnt;
-int
-atexit(void (*func)(void))
+int atexit(void (*func)(void))
{
if (__funccnt >= NEXITS)
return 1;
*/
/* $Id$ */
-#include <stdlib.h>
-#include <errno.h>
+#include <stdlib.h>
+#include <errno.h>
-double
-(atof)(const char *nptr)
+double(atof)(const char* nptr)
{
double d;
int e = errno;
- d = strtod(nptr, (char **) NULL);
+ d = strtod(nptr, (char**)NULL);
errno = e;
return d;
}
*/
/* $Id$ */
-#include <ctype.h>
+#include <ctype.h>
/* We do not use strtol here for backwards compatibility in behaviour on
overflow.
*/
-int
-atoi(register const char *nptr)
+int atoi(register const char* nptr)
{
int total = 0;
int minus = 0;
- while (isspace(*nptr)) nptr++;
- if (*nptr == '+') nptr++;
- else if (*nptr == '-') {
+ while (isspace(*nptr))
+ nptr++;
+ if (*nptr == '+')
+ nptr++;
+ else if (*nptr == '-')
+ {
minus = 1;
nptr++;
}
- while (isdigit(*nptr)) {
+ while (isdigit(*nptr))
+ {
total *= 10;
total += (*nptr++ - '0');
}
*/
/* $Id$ */
-#include <ctype.h>
+#include <ctype.h>
/* We do not use strtol here for backwards compatibility in behaviour on
overflow.
*/
-long
-atol(register const char *nptr)
+long atol(register const char* nptr)
{
long total = 0;
int minus = 0;
- while (isspace(*nptr)) nptr++;
- if (*nptr == '+') nptr++;
- else if (*nptr == '-') {
+ while (isspace(*nptr))
+ nptr++;
+ if (*nptr == '+')
+ nptr++;
+ else if (*nptr == '-')
+ {
minus = 1;
nptr++;
}
- while (isdigit(*nptr)) {
+ while (isdigit(*nptr))
+ {
total *= 10;
total += (*nptr++ - '0');
}
*/
/* $Id$ */
-#include <stdlib.h>
+#include <stdlib.h>
-void *
-bsearch(register const void *key, register const void *base,
- register size_t nmemb, register size_t size,
- int (*compar)(const void *, const void *))
+void* bsearch(register const void* key, register const void* base,
+ register size_t nmemb, register size_t size,
+ int (*compar)(const void*, const void*))
{
- register const void *mid_point;
- register int cmp;
+ register const void* mid_point;
+ register int cmp;
- while (nmemb > 0) {
- mid_point = (char *)base + size * (nmemb >> 1);
+ while (nmemb > 0)
+ {
+ mid_point = (char*)base + size * (nmemb >> 1);
if ((cmp = (*compar)(key, mid_point)) == 0)
- return (void *)mid_point;
- if (cmp >= 0) {
- base = (char *)mid_point + size;
+ return (void*)mid_point;
+ if (cmp >= 0)
+ {
+ base = (char*)mid_point + size;
nmemb = (nmemb - 1) >> 1;
- } else
+ }
+ else
nmemb >>= 1;
}
- return (void *)NULL;
+ return (void*)NULL;
}
*/
/* $Id$ */
-#include <stdlib.h>
+#include <stdlib.h>
-div_t
-div(register int numer, register int denom)
+div_t div(register int numer, register int denom)
{
div_t r;
- r.quot = numer / denom; /* might trap if denom == 0 */
+ r.quot = numer / denom; /* might trap if denom == 0 */
r.rem = numer % denom;
- if (r.rem != 0 && (numer > 0) != (r.rem > 0)) {
+ if (r.rem != 0 && (numer > 0) != (r.rem > 0))
+ {
r.quot++;
r.rem -= denom;
}
#include <stdio.h>
#include <unistd.h>
-#define NEXITS 32
+#define NEXITS 32
void (*__functab[NEXITS])(void);
int __funccnt = 0;
_calls(void)
{
register int i = __funccnt;
-
+
/* "Called in reversed order of their registration" */
while (--i >= 0)
(*__functab[i])();
}
-void
-exit(int status)
+void exit(int status)
{
_calls();
- if (_clean) _clean();
- _exit(status) ;
+ if (_clean)
+ _clean();
+ _exit(status);
}
bytes. In this case, these routines may become obsolete. ???
*/
-#include "ext_fmt.h"
-#include <float.h>
-#include <errno.h>
-#include <ctype.h>
-#include <ack/config.h>
+#include "ext_fmt.h"
+#include <float.h>
+#include <errno.h>
+#include <ctype.h>
+#include <ack/config.h>
-static int b64_add(struct mantissa *e1, struct mantissa *e2);
-static b64_sft(struct mantissa *e1, int n);
+static int b64_add(struct mantissa* e1, struct mantissa* e2);
+static b64_sft(struct mantissa* e1, int n);
-static
-mul_ext(struct EXTEND *e1, struct EXTEND *e2, struct EXTEND *e3)
+static mul_ext(struct EXTEND* e1, struct EXTEND* e2, struct EXTEND* e3)
{
/* Multiply the extended numbers e1 and e2, and put the
result in e3.
*/
- register int i,j; /* loop control */
- unsigned short mp[4];
- unsigned short mc[4];
- unsigned short result[8]; /* result */
+ register int i, j; /* loop control */
+ unsigned short mp[4];
+ unsigned short mc[4];
+ unsigned short result[8]; /* result */
- register unsigned short *pres;
+ register unsigned short* pres;
/* first save the sign (XOR) */
e3->sign = e1->sign ^ e2->sign;
/* assign unknown long formats */
/* to known unsigned word formats */
mp[0] = e1->m1 >> 16;
- mp[1] = (unsigned short) e1->m1;
+ mp[1] = (unsigned short)e1->m1;
mp[2] = e1->m2 >> 16;
- mp[3] = (unsigned short) e1->m2;
+ mp[3] = (unsigned short)e1->m2;
mc[0] = e2->m1 >> 16;
- mc[1] = (unsigned short) e2->m1;
+ mc[1] = (unsigned short)e2->m1;
mc[2] = e2->m2 >> 16;
- mc[3] = (unsigned short) e2->m2;
- for (i = 8; i--;) {
+ mc[3] = (unsigned short)e2->m2;
+ for (i = 8; i--;)
+ {
result[i] = 0;
}
/*
* fill registers with their components
*/
- for(i=4, pres = &result[4];i--;pres--) if (mp[i]) {
- unsigned short k = 0;
- unsigned long mpi = mp[i];
- for(j=4;j--;) {
- unsigned long tmp = (unsigned long)pres[j] + k;
- if (mc[j]) tmp += mpi * mc[j];
- pres[j] = tmp;
- k = tmp >> 16;
+ for (i = 4, pres = &result[4]; i--; pres--)
+ if (mp[i])
+ {
+ unsigned short k = 0;
+ unsigned long mpi = mp[i];
+ for (j = 4; j--;)
+ {
+ unsigned long tmp = (unsigned long)pres[j] + k;
+ if (mc[j])
+ tmp += mpi * mc[j];
+ pres[j] = tmp;
+ k = tmp >> 16;
+ }
+ pres[-1] = k;
}
- pres[-1] = k;
- }
- if (! (result[0] & 0x8000)) {
+ if (!(result[0] & 0x8000))
+ {
e3->exp--;
- for (i = 0; i <= 3; i++) {
+ for (i = 0; i <= 3; i++)
+ {
result[i] <<= 1;
- if (result[i+1]&0x8000) result[i] |= 1;
+ if (result[i + 1] & 0x8000)
+ result[i] |= 1;
}
result[4] <<= 1;
- }
+ }
/*
* combine the registers to a total
*/
e3->m1 = ((unsigned long)(result[0]) << 16) + result[1];
e3->m2 = ((unsigned long)(result[2]) << 16) + result[3];
- if (result[4] & 0x8000) {
- if (++e3->m2 == 0) {
- if (++e3->m1 == 0) {
+ if (result[4] & 0x8000)
+ {
+ if (++e3->m2 == 0)
+ {
+ if (++e3->m1 == 0)
+ {
e3->m1 = 0x80000000;
e3->exp++;
}
}
}
-static
-add_ext(struct EXTEND *e1, struct EXTEND *e2, struct EXTEND *e3)
+static add_ext(struct EXTEND* e1, struct EXTEND* e2, struct EXTEND* e3)
{
/* Add two extended numbers e1 and e2, and put the result
in e3
struct EXTEND ce2;
int diff;
- if ((e2->m1 | e2->m2) == 0L) {
+ if ((e2->m1 | e2->m2) == 0L)
+ {
*e3 = *e1;
return;
}
- if ((e1->m1 | e1->m2) == 0L) {
+ if ((e1->m1 | e1->m2) == 0L)
+ {
*e3 = *e2;
return;
}
/* adjust mantissas to equal power */
diff = e3->exp - e1->exp;
- if (diff < 0) {
+ if (diff < 0)
+ {
diff = -diff;
e3->exp += diff;
b64_sft(&(e3->mantissa), diff);
}
- else if (diff > 0) {
+ else if (diff > 0)
+ {
e1->exp += diff;
b64_sft(&(e1->mantissa), diff);
}
- if (e1->sign != e3->sign) {
+ if (e1->sign != e3->sign)
+ {
/* e3 + e1 = e3 - (-e1) */
- if (e1->m1 > e3->m1 ||
- (e1->m1 == e3->m1 && e1->m2 > e3->m2)) {
- /* abs(e1) > abs(e3) */
- if (e3->m2 > e1->m2) {
- e1->m1 -= 1; /* carry in */
- }
- e1->m1 -= e3->m1;
- e1->m2 -= e3->m2;
- *e3 = *e1;
- }
- else {
- if (e1->m2 > e3->m2)
- e3->m1 -= 1; /* carry in */
- e3->m1 -= e1->m1;
- e3->m2 -= e1->m2;
- }
- }
- else {
- if (b64_add(&e3->mantissa,&e1->mantissa)) {/* addition carry */
- b64_sft(&e3->mantissa,1);/* shift mantissa one bit RIGHT */
- e3->m1 |= 0x80000000L; /* set max bit */
- e3->exp++; /* increase the exponent */
+ if (e1->m1 > e3->m1 || (e1->m1 == e3->m1 && e1->m2 > e3->m2))
+ {
+ /* abs(e1) > abs(e3) */
+ if (e3->m2 > e1->m2)
+ {
+ e1->m1 -= 1; /* carry in */
+ }
+ e1->m1 -= e3->m1;
+ e1->m2 -= e3->m2;
+ *e3 = *e1;
+ }
+ else
+ {
+ if (e1->m2 > e3->m2)
+ e3->m1 -= 1; /* carry in */
+ e3->m1 -= e1->m1;
+ e3->m2 -= e1->m2;
}
}
- if ((e3->m2 | e3->m1) != 0L) {
+ else
+ {
+ if (b64_add(&e3->mantissa, &e1->mantissa))
+ { /* addition carry */
+ b64_sft(&e3->mantissa, 1); /* shift mantissa one bit RIGHT */
+ e3->m1 |= 0x80000000L; /* set max bit */
+ e3->exp++; /* increase the exponent */
+ }
+ }
+ if ((e3->m2 | e3->m1) != 0L)
+ {
/* normalize */
- if (e3->m1 == 0L) {
- e3->m1 = e3->m2; e3->m2 = 0L; e3->exp -= 32;
+ if (e3->m1 == 0L)
+ {
+ e3->m1 = e3->m2;
+ e3->m2 = 0L;
+ e3->exp -= 32;
}
- if (!(e3->m1 & 0x80000000)) {
+ if (!(e3->m1 & 0x80000000))
+ {
unsigned long l = 0x40000000;
int cnt = -1;
- while (! (l & e3->m1)) {
- l >>= 1; cnt--;
+ while (!(l & e3->m1))
+ {
+ l >>= 1;
+ cnt--;
}
e3->exp += cnt;
b64_sft(&(e3->mantissa), cnt);
}
static int
-cmp_ext(struct EXTEND *e1, struct EXTEND *e2)
+cmp_ext(struct EXTEND* e1, struct EXTEND* e2)
{
- struct EXTEND tmp;
-
- e2->sign = ! e2->sign;
- add_ext(e1, e2, &tmp);
- e2->sign = ! e2->sign;
- if (tmp.m1 == 0 && tmp.m2 == 0) return 0;
- if (tmp.sign) return -1;
- return 1;
+ struct EXTEND tmp;
+
+ e2->sign = !e2->sign;
+ add_ext(e1, e2, &tmp);
+ e2->sign = !e2->sign;
+ if (tmp.m1 == 0 && tmp.m2 == 0)
+ return 0;
+ if (tmp.sign)
+ return -1;
+ return 1;
}
-static
-b64_sft(struct mantissa *e1, int n)
+static b64_sft(struct mantissa* e1, int n)
{
- if (n > 0) {
- if (n > 63) {
+ if (n > 0)
+ {
+ if (n > 63)
+ {
e1->l_32 = 0;
e1->h_32 = 0;
return;
}
- if (n >= 32) {
+ if (n >= 32)
+ {
e1->l_32 = e1->h_32;
e1->h_32 = 0;
n -= 32;
}
- if (n > 0) {
+ if (n > 0)
+ {
e1->l_32 >>= n;
- if (e1->h_32 != 0) {
+ if (e1->h_32 != 0)
+ {
e1->l_32 |= (e1->h_32 << (32 - n));
e1->h_32 >>= n;
}
return;
}
n = -n;
- if (n > 0) {
- if (n > 63) {
+ if (n > 0)
+ {
+ if (n > 63)
+ {
e1->l_32 = 0;
e1->h_32 = 0;
return;
}
- if (n >= 32) {
+ if (n >= 32)
+ {
e1->h_32 = e1->l_32;
e1->l_32 = 0;
n -= 32;
}
- if (n > 0) {
+ if (n > 0)
+ {
e1->h_32 <<= n;
- if (e1->l_32 != 0) {
+ if (e1->l_32 != 0)
+ {
e1->h_32 |= (e1->l_32 >> (32 - n));
e1->l_32 <<= n;
}
}
static int
-b64_add(struct mantissa *e1, struct mantissa *e2)
- /*
+b64_add(struct mantissa* e1, struct mantissa* e2)
+/*
* pointers to 64 bit 'registers'
*/
{
- register int overflow;
- int carry;
+ register int overflow;
+ int carry;
- /* add higher pair of 32 bits */
- overflow = ((unsigned long) 0xFFFFFFFF - e1->h_32 < e2->h_32);
+ /* add higher pair of 32 bits */
+ overflow = ((unsigned long)0xFFFFFFFF - e1->h_32 < e2->h_32);
e1->h_32 += e2->h_32;
- /* add lower pair of 32 bits */
- carry = ((unsigned long) 0xFFFFFFFF - e1->l_32 < e2->l_32);
+ /* add lower pair of 32 bits */
+ carry = ((unsigned long)0xFFFFFFFF - e1->l_32 < e2->l_32);
e1->l_32 += e2->l_32;
if ((carry) && (++e1->h_32 == 0))
- return(1); /* had a 64 bit overflow */
+ return (1); /* had a 64 bit overflow */
else
- return(overflow); /* return status from higher add */
+ return (overflow); /* return status from higher add */
}
/* The following tables can be computed with the following bc(1)
0
*/
-static struct EXTEND ten_powers[] = { /* representation of 10 ** i */
- { 0, 0, 0x80000000, 0 },
- { 0, 3, 0xA0000000, 0 },
- { 0, 6, 0xC8000000, 0 },
- { 0, 9, 0xFA000000, 0 },
- { 0, 13, 0x9C400000, 0 },
- { 0, 16, 0xC3500000, 0 },
- { 0, 19, 0xF4240000, 0 },
- { 0, 23, 0x98968000, 0 },
- { 0, 26, 0xBEBC2000, 0 },
- { 0, 29, 0xEE6B2800, 0 },
- { 0, 33, 0x9502F900, 0 },
- { 0, 36, 0xBA43B740, 0 },
- { 0, 39, 0xE8D4A510, 0 },
- { 0, 43, 0x9184E72A, 0 },
- { 0, 46, 0xB5E620F4, 0x80000000 },
- { 0, 49, 0xE35FA931, 0xA0000000 },
- { 0, 53, 0x8E1BC9BF, 0x04000000 },
- { 0, 56, 0xB1A2BC2E, 0xC5000000 },
- { 0, 59, 0xDE0B6B3A, 0x76400000 },
- { 0, 63, 0x8AC72304, 0x89E80000 },
- { 0, 66, 0xAD78EBC5, 0xAC620000 },
- { 0, 69, 0xD8D726B7, 0x177A8000 },
- { 0, 73, 0x87867832, 0x6EAC9000 },
- { 0, 76, 0xA968163F, 0x0A57B400 },
- { 0, 79, 0xD3C21BCE, 0xCCEDA100 },
- { 0, 83, 0x84595161, 0x401484A0 },
- { 0, 86, 0xA56FA5B9, 0x9019A5C8 },
- { 0, 89, 0xCECB8F27, 0xF4200F3A }
+static struct EXTEND ten_powers[] = { /* representation of 10 ** i */
+ { 0, 0, 0x80000000, 0 },
+ { 0, 3, 0xA0000000, 0 },
+ { 0, 6, 0xC8000000, 0 },
+ { 0, 9, 0xFA000000, 0 },
+ { 0, 13, 0x9C400000, 0 },
+ { 0, 16, 0xC3500000, 0 },
+ { 0, 19, 0xF4240000, 0 },
+ { 0, 23, 0x98968000, 0 },
+ { 0, 26, 0xBEBC2000, 0 },
+ { 0, 29, 0xEE6B2800, 0 },
+ { 0, 33, 0x9502F900, 0 },
+ { 0, 36, 0xBA43B740, 0 },
+ { 0, 39, 0xE8D4A510, 0 },
+ { 0, 43, 0x9184E72A, 0 },
+ { 0, 46, 0xB5E620F4, 0x80000000 },
+ { 0, 49, 0xE35FA931, 0xA0000000 },
+ { 0, 53, 0x8E1BC9BF, 0x04000000 },
+ { 0, 56, 0xB1A2BC2E, 0xC5000000 },
+ { 0, 59, 0xDE0B6B3A, 0x76400000 },
+ { 0, 63, 0x8AC72304, 0x89E80000 },
+ { 0, 66, 0xAD78EBC5, 0xAC620000 },
+ { 0, 69, 0xD8D726B7, 0x177A8000 },
+ { 0, 73, 0x87867832, 0x6EAC9000 },
+ { 0, 76, 0xA968163F, 0x0A57B400 },
+ { 0, 79, 0xD3C21BCE, 0xCCEDA100 },
+ { 0, 83, 0x84595161, 0x401484A0 },
+ { 0, 86, 0xA56FA5B9, 0x9019A5C8 },
+ { 0, 89, 0xCECB8F27, 0xF4200F3A }
};
-static struct EXTEND big_ten_powers[] = { /* representation of 10 ** (28*i) */
- { 0, 0, 0x80000000, 0 },
- { 0, 93, 0x813F3978, 0xF8940984 },
- { 0, 186, 0x82818F12, 0x81ED44A0 },
- { 0, 279, 0x83C7088E, 0x1AAB65DB },
- { 0, 372, 0x850FADC0, 0x9923329E },
- { 0, 465, 0x865B8692, 0x5B9BC5C2 },
- { 0, 558, 0x87AA9AFF, 0x79042287 },
- { 0, 651, 0x88FCF317, 0xF22241E2 },
- { 0, 744, 0x8A5296FF, 0xE33CC930 },
- { 0, 837, 0x8BAB8EEF, 0xB6409C1A },
- { 0, 930, 0x8D07E334, 0x55637EB3 },
- { 0, 1023, 0x8E679C2F, 0x5E44FF8F },
- { 0, 1116, 0x8FCAC257, 0x558EE4E6 },
- { 0, 1209, 0x91315E37, 0xDB165AA9 },
- { 0, 1302, 0x929B7871, 0xDE7F22B9 },
- { 0, 1395, 0x940919BB, 0xD4620B6D },
- { 0, 1488, 0x957A4AE1, 0xEBF7F3D4 },
- { 0, 1581, 0x96EF14C6, 0x454AA840 },
- { 0, 1674, 0x98678061, 0x27ECE4F5 },
- { 0, 1767, 0x99E396C1, 0x3A3ACFF2 }
+static struct EXTEND big_ten_powers[] = { /* representation of 10 ** (28*i) */
+ { 0, 0, 0x80000000, 0 },
+ { 0, 93, 0x813F3978, 0xF8940984 },
+ { 0, 186, 0x82818F12, 0x81ED44A0 },
+ { 0, 279, 0x83C7088E, 0x1AAB65DB },
+ { 0, 372, 0x850FADC0, 0x9923329E },
+ { 0, 465, 0x865B8692, 0x5B9BC5C2 },
+ { 0, 558, 0x87AA9AFF, 0x79042287 },
+ { 0, 651, 0x88FCF317, 0xF22241E2 },
+ { 0, 744, 0x8A5296FF, 0xE33CC930 },
+ { 0, 837, 0x8BAB8EEF, 0xB6409C1A },
+ { 0, 930, 0x8D07E334, 0x55637EB3 },
+ { 0, 1023, 0x8E679C2F, 0x5E44FF8F },
+ { 0, 1116, 0x8FCAC257, 0x558EE4E6 },
+ { 0, 1209, 0x91315E37, 0xDB165AA9 },
+ { 0, 1302, 0x929B7871, 0xDE7F22B9 },
+ { 0, 1395, 0x940919BB, 0xD4620B6D },
+ { 0, 1488, 0x957A4AE1, 0xEBF7F3D4 },
+ { 0, 1581, 0x96EF14C6, 0x454AA840 },
+ { 0, 1674, 0x98678061, 0x27ECE4F5 },
+ { 0, 1767, 0x99E396C1, 0x3A3ACFF2 }
};
static struct EXTEND r_ten_powers[] = { /* representation of 10 ** -i */
- { 0, 0, 0x80000000, 0 },
- { 0, -4, 0xCCCCCCCC, 0xCCCCCCCD },
- { 0, -7, 0xA3D70A3D, 0x70A3D70A },
- { 0, -10, 0x83126E97, 0x8D4FDF3B },
- { 0, -14, 0xD1B71758, 0xE219652C },
- { 0, -17, 0xA7C5AC47, 0x1B478423 },
- { 0, -20, 0x8637BD05, 0xAF6C69B6 },
- { 0, -24, 0xD6BF94D5, 0xE57A42BC },
- { 0, -27, 0xABCC7711, 0x8461CEFD },
- { 0, -30, 0x89705F41, 0x36B4A597 },
- { 0, -34, 0xDBE6FECE, 0xBDEDD5BF },
- { 0, -37, 0xAFEBFF0B, 0xCB24AAFF },
- { 0, -40, 0x8CBCCC09, 0x6F5088CC },
- { 0, -44, 0xE12E1342, 0x4BB40E13 },
- { 0, -47, 0xB424DC35, 0x095CD80F },
- { 0, -50, 0x901D7CF7, 0x3AB0ACD9 },
- { 0, -54, 0xE69594BE, 0xC44DE15B },
- { 0, -57, 0xB877AA32, 0x36A4B449 },
- { 0, -60, 0x9392EE8E, 0x921D5D07 },
- { 0, -64, 0xEC1E4A7D, 0xB69561A5 },
- { 0, -67, 0xBCE50864, 0x92111AEB },
- { 0, -70, 0x971DA050, 0x74DA7BEF },
- { 0, -74, 0xF1C90080, 0xBAF72CB1 },
- { 0, -77, 0xC16D9A00, 0x95928A27 },
- { 0, -80, 0x9ABE14CD, 0x44753B53 },
- { 0, -84, 0xF79687AE, 0xD3EEC551 },
- { 0, -87, 0xC6120625, 0x76589DDB },
- { 0, -90, 0x9E74D1B7, 0x91E07E48 }
+ { 0, 0, 0x80000000, 0 },
+ { 0, -4, 0xCCCCCCCC, 0xCCCCCCCD },
+ { 0, -7, 0xA3D70A3D, 0x70A3D70A },
+ { 0, -10, 0x83126E97, 0x8D4FDF3B },
+ { 0, -14, 0xD1B71758, 0xE219652C },
+ { 0, -17, 0xA7C5AC47, 0x1B478423 },
+ { 0, -20, 0x8637BD05, 0xAF6C69B6 },
+ { 0, -24, 0xD6BF94D5, 0xE57A42BC },
+ { 0, -27, 0xABCC7711, 0x8461CEFD },
+ { 0, -30, 0x89705F41, 0x36B4A597 },
+ { 0, -34, 0xDBE6FECE, 0xBDEDD5BF },
+ { 0, -37, 0xAFEBFF0B, 0xCB24AAFF },
+ { 0, -40, 0x8CBCCC09, 0x6F5088CC },
+ { 0, -44, 0xE12E1342, 0x4BB40E13 },
+ { 0, -47, 0xB424DC35, 0x095CD80F },
+ { 0, -50, 0x901D7CF7, 0x3AB0ACD9 },
+ { 0, -54, 0xE69594BE, 0xC44DE15B },
+ { 0, -57, 0xB877AA32, 0x36A4B449 },
+ { 0, -60, 0x9392EE8E, 0x921D5D07 },
+ { 0, -64, 0xEC1E4A7D, 0xB69561A5 },
+ { 0, -67, 0xBCE50864, 0x92111AEB },
+ { 0, -70, 0x971DA050, 0x74DA7BEF },
+ { 0, -74, 0xF1C90080, 0xBAF72CB1 },
+ { 0, -77, 0xC16D9A00, 0x95928A27 },
+ { 0, -80, 0x9ABE14CD, 0x44753B53 },
+ { 0, -84, 0xF79687AE, 0xD3EEC551 },
+ { 0, -87, 0xC6120625, 0x76589DDB },
+ { 0, -90, 0x9E74D1B7, 0x91E07E48 }
};
static struct EXTEND r_big_ten_powers[] = { /* representation of 10 ** -(28*i) */
- { 0, 0, 0x80000000, 0 },
- { 0, -94, 0xFD87B5F2, 0x8300CA0E },
- { 0, -187, 0xFB158592, 0xBE068D2F },
- { 0, -280, 0xF8A95FCF, 0x88747D94 },
- { 0, -373, 0xF64335BC, 0xF065D37D },
- { 0, -466, 0xF3E2F893, 0xDEC3F126 },
- { 0, -559, 0xF18899B1, 0xBC3F8CA2 },
- { 0, -652, 0xEF340A98, 0x172AACE5 },
- { 0, -745, 0xECE53CEC, 0x4A314EBE },
- { 0, -838, 0xEA9C2277, 0x23EE8BCB },
- { 0, -931, 0xE858AD24, 0x8F5C22CA },
- { 0, -1024, 0xE61ACF03, 0x3D1A45DF },
- { 0, -1117, 0xE3E27A44, 0x4D8D98B8 },
- { 0, -1210, 0xE1AFA13A, 0xFBD14D6E },
- { 0, -1303, 0xDF82365C, 0x497B5454 },
- { 0, -1396, 0xDD5A2C3E, 0xAB3097CC },
- { 0, -1489, 0xDB377599, 0xB6074245 },
- { 0, -1582, 0xD91A0545, 0xCDB51186 },
- { 0, -1675, 0xD701CE3B, 0xD387BF48 },
- { 0, -1768, 0xD4EEC394, 0xD6258BF8 }
+ { 0, 0, 0x80000000, 0 },
+ { 0, -94, 0xFD87B5F2, 0x8300CA0E },
+ { 0, -187, 0xFB158592, 0xBE068D2F },
+ { 0, -280, 0xF8A95FCF, 0x88747D94 },
+ { 0, -373, 0xF64335BC, 0xF065D37D },
+ { 0, -466, 0xF3E2F893, 0xDEC3F126 },
+ { 0, -559, 0xF18899B1, 0xBC3F8CA2 },
+ { 0, -652, 0xEF340A98, 0x172AACE5 },
+ { 0, -745, 0xECE53CEC, 0x4A314EBE },
+ { 0, -838, 0xEA9C2277, 0x23EE8BCB },
+ { 0, -931, 0xE858AD24, 0x8F5C22CA },
+ { 0, -1024, 0xE61ACF03, 0x3D1A45DF },
+ { 0, -1117, 0xE3E27A44, 0x4D8D98B8 },
+ { 0, -1210, 0xE1AFA13A, 0xFBD14D6E },
+ { 0, -1303, 0xDF82365C, 0x497B5454 },
+ { 0, -1396, 0xDD5A2C3E, 0xAB3097CC },
+ { 0, -1489, 0xDB377599, 0xB6074245 },
+ { 0, -1582, 0xD91A0545, 0xCDB51186 },
+ { 0, -1675, 0xD701CE3B, 0xD387BF48 },
+ { 0, -1768, 0xD4EEC394, 0xD6258BF8 }
};
-#define TP (int)(sizeof(ten_powers)/sizeof(ten_powers[0]))
-#define BTP (int)(sizeof(big_ten_powers)/sizeof(big_ten_powers[0]))
-#define MAX_EXP (TP * BTP - 1)
+#define TP (int)(sizeof(ten_powers) / sizeof(ten_powers[0]))
+#define BTP (int)(sizeof(big_ten_powers) / sizeof(big_ten_powers[0]))
+#define MAX_EXP (TP * BTP - 1)
-static
-add_exponent(struct EXTEND *e, int exp)
+static add_exponent(struct EXTEND* e, int exp)
{
int neg = exp < 0;
int divsz, modsz;
struct EXTEND x;
- if (neg) exp = -exp;
+ if (neg)
+ exp = -exp;
divsz = exp / TP;
modsz = exp % TP;
- if (neg) {
+ if (neg)
+ {
mul_ext(e, &r_ten_powers[modsz], &x);
mul_ext(&x, &r_big_ten_powers[divsz], e);
}
- else {
+ else
+ {
mul_ext(e, &ten_powers[modsz], &x);
mul_ext(&x, &big_ten_powers[divsz], e);
}
}
-_str_ext_cvt(const char *s, char **ss, struct EXTEND *e)
+_str_ext_cvt(const char* s, char** ss, struct EXTEND* e)
{
/* Like strtod, but for extended precision */
- register int c;
- int dotseen = 0;
- int digitseen = 0;
- int exp = 0;
-
- if (ss) *ss = (char *)s;
- while (isspace(*s)) s++;
+ register int c;
+ int dotseen = 0;
+ int digitseen = 0;
+ int exp = 0;
+
+ if (ss)
+ *ss = (char*)s;
+ while (isspace(*s))
+ s++;
e->sign = 0;
e->exp = 0;
e->m1 = e->m2 = 0;
c = *s;
- switch(c) {
- case '-':
- e->sign = 1;
- case '+':
- s++;
+ switch (c)
+ {
+ case '-':
+ e->sign = 1;
+ case '+':
+ s++;
}
- while (c = *s++, isdigit(c) || (c == '.' && ! dotseen++)) {
- if (c == '.') continue;
+ while (c = *s++, isdigit(c) || (c == '.' && !dotseen++))
+ {
+ if (c == '.')
+ continue;
digitseen = 1;
- if (e->m1 <= (unsigned long)(0xFFFFFFFF)/10) {
- struct mantissa a1;
+ if (e->m1 <= (unsigned long)(0xFFFFFFFF) / 10)
+ {
+ struct mantissa a1;
a1 = e->mantissa;
b64_sft(&(e->mantissa), -3);
a1.l_32 = c - '0';
b64_add(&(e->mantissa), &a1);
}
- else exp++;
- if (dotseen) exp--;
+ else
+ exp++;
+ if (dotseen)
+ exp--;
}
- if (! digitseen) return;
-
- if (ss) *ss = (char *)s - 1;
-
- if (c == 'E' || c == 'e') {
- int exp1 = 0;
- int sign = 1;
- int exp_overflow = 0;
+ if (!digitseen)
+ return;
- switch(*s) {
- case '-':
- sign = -1;
- case '+':
- s++;
+ if (ss)
+ *ss = (char*)s - 1;
+
+ if (c == 'E' || c == 'e')
+ {
+ int exp1 = 0;
+ int sign = 1;
+ int exp_overflow = 0;
+
+ switch (*s)
+ {
+ case '-':
+ sign = -1;
+ case '+':
+ s++;
}
- if (c = *s, isdigit(c)) {
- do {
+ if (c = *s, isdigit(c))
+ {
+ do
+ {
int tmp;
exp1 = 10 * exp1 + (c - '0');
- if ((tmp = sign * exp1 + exp) > MAX_EXP ||
- tmp < -MAX_EXP) {
+ if ((tmp = sign * exp1 + exp) > MAX_EXP || tmp < -MAX_EXP)
+ {
exp_overflow = 1;
}
} while (c = *++s, isdigit(c));
- if (ss) *ss = (char *)s;
+ if (ss)
+ *ss = (char*)s;
}
exp += sign * exp1;
- if (exp_overflow) {
+ if (exp_overflow)
+ {
exp = sign * MAX_EXP;
- if (e->m1 != 0 || e->m2 != 0) errno = ERANGE;
+ if (e->m1 != 0 || e->m2 != 0)
+ errno = ERANGE;
}
}
- if (e->m1 == 0 && e->m2 == 0) return;
+ if (e->m1 == 0 && e->m2 == 0)
+ return;
e->exp = 63;
- while (! (e->m1 & 0x80000000)) {
- b64_sft(&(e->mantissa),-1);
+ while (!(e->m1 & 0x80000000))
+ {
+ b64_sft(&(e->mantissa), -1);
e->exp--;
}
add_exponent(e, exp);
}
-#include <math.h>
+#include <math.h>
-static
-ten_mult(struct EXTEND *e)
+static ten_mult(struct EXTEND* e)
{
struct EXTEND e1 = *e;
#define NDIGITS 128
#define NSIGNIFICANT 19
-char *
-_ext_str_cvt(struct EXTEND *e, int ndigit, int *decpt, int *sign, int ecvtflag)
+char* _ext_str_cvt(struct EXTEND* e, int ndigit, int* decpt, int* sign, int ecvtflag)
{
/* Like cvt(), but for extended precision */
- static char buf[NDIGITS+1];
+ static char buf[NDIGITS + 1];
struct EXTEND m;
- register char *p = buf;
- register char *pe;
+ register char* p = buf;
+ register char* pe;
int findex = 0;
- if (ndigit < 0) ndigit = 0;
- if (ndigit > NDIGITS) ndigit = NDIGITS;
+ if (ndigit < 0)
+ ndigit = 0;
+ if (ndigit > NDIGITS)
+ ndigit = NDIGITS;
pe = &buf[ndigit];
buf[0] = '\0';
*sign = 0;
- if (e->sign) {
+ if (e->sign)
+ {
*sign = 1;
e->sign = 0;
}
*decpt = 0;
- if (e->m1 != 0) {
- register struct EXTEND *pp = &big_ten_powers[1];
+ if (e->m1 != 0)
+ {
+ register struct EXTEND* pp = &big_ten_powers[1];
- while(cmp_ext(e,pp) >= 0) {
+ while (cmp_ext(e, pp) >= 0)
+ {
pp++;
findex = pp - big_ten_powers;
- if (findex >= BTP) break;
+ if (findex >= BTP)
+ break;
}
pp--;
findex = pp - big_ten_powers;
- mul_ext(e,&r_big_ten_powers[findex],e);
+ mul_ext(e, &r_big_ten_powers[findex], e);
*decpt += findex * TP;
pp = &ten_powers[1];
- while(pp < &ten_powers[TP] && cmp_ext(e, pp) >= 0) pp++;
+ while (pp < &ten_powers[TP] && cmp_ext(e, pp) >= 0)
+ pp++;
pp--;
findex = pp - ten_powers;
*decpt += findex;
- if (cmp_ext(e, &ten_powers[0]) < 0) {
+ if (cmp_ext(e, &ten_powers[0]) < 0)
+ {
pp = &r_big_ten_powers[1];
- while(cmp_ext(e,pp) < 0) pp++;
+ while (cmp_ext(e, pp) < 0)
+ pp++;
pp--;
findex = pp - r_big_ten_powers;
mul_ext(e, &big_ten_powers[findex], e);
ten_mult(e);
(*decpt)--;
pp = &r_ten_powers[0];
- while(cmp_ext(e, pp) < 0) pp++;
+ while (cmp_ext(e, pp) < 0)
+ pp++;
findex = pp - r_ten_powers;
mul_ext(e, &ten_powers[findex], e);
*decpt -= findex;
findex = 0;
}
- (*decpt)++; /* because now value in [1.0, 10.0) */
+ (*decpt)++; /* because now value in [1.0, 10.0) */
}
- if (! ecvtflag) {
+ if (!ecvtflag)
+ {
/* for fcvt() we need ndigit digits behind the dot */
pe += *decpt;
- if (pe > &buf[NDIGITS]) pe = &buf[NDIGITS];
+ if (pe > &buf[NDIGITS])
+ pe = &buf[NDIGITS];
}
m.exp = -62;
m.sign = 0;
m.m1 = 0xA0000000;
m.m2 = 0;
- while (p <= pe) {
+ while (p <= pe)
+ {
struct EXTEND oneminm;
- if (p - pe > NSIGNIFICANT) {
+ if (p - pe > NSIGNIFICANT)
+ {
findex = 0;
e->m1 = 0;
}
- if (findex) {
+ if (findex)
+ {
struct EXTEND tc, oldtc;
int count = 0;
oldtc.m1 = 0;
oldtc.m2 = 0;
tc = ten_powers[findex];
- while (cmp_ext(e, &tc) >= 0) {
+ while (cmp_ext(e, &tc) >= 0)
+ {
oldtc = tc;
add_ext(&tc, &ten_powers[findex], &tc);
count++;
findex--;
continue;
}
- if (e->m1) {
+ if (e->m1)
+ {
m.sign = 1;
add_ext(&ten_powers[0], &m, &oneminm);
m.sign = 0;
- if (e->exp >= 0) {
+ if (e->exp >= 0)
+ {
struct EXTEND x;
- x.m2 = 0; x.exp = e->exp;
+ x.m2 = 0;
+ x.exp = e->exp;
x.sign = 1;
- x.m1 = e->m1>>(31-e->exp);
+ x.m1 = e->m1 >> (31 - e->exp);
*p++ = (x.m1) + '0';
- x.m1 = x.m1 << (31-e->exp);
+ x.m1 = x.m1 << (31 - e->exp);
add_ext(e, &x, e);
}
- else *p++ = '0';
+ else
+ *p++ = '0';
/* Check that remainder is still significant */
- if (cmp_ext(&m, e) > 0 || cmp_ext(e, &oneminm) > 0) {
- if (e->m1 && e->exp >= -1) *(p-1) += 1;
+ if (cmp_ext(&m, e) > 0 || cmp_ext(e, &oneminm) > 0)
+ {
+ if (e->m1 && e->exp >= -1)
+ *(p - 1) += 1;
e->m1 = 0;
continue;
}
ten_mult(&m);
ten_mult(e);
}
- else *p++ = '0';
+ else
+ *p++ = '0';
}
- if (pe >= buf) {
+ if (pe >= buf)
+ {
p = pe;
- *p += 5; /* round of at the end */
- while (*p > '9') {
+ *p += 5; /* round of at the end */
+ while (*p > '9')
+ {
*p = '0';
- if (p > buf) ++*--p;
- else {
+ if (p > buf)
+ ++*--p;
+ else
+ {
*p = '1';
++*decpt;
- if (! ecvtflag) {
+ if (!ecvtflag)
+ {
/* maybe add another digit at the end,
because the point was shifted right
*/
- if (pe > buf) *pe = '0';
+ if (pe > buf)
+ *pe = '0';
pe++;
}
}
return buf;
}
-_dbl_ext_cvt(double value, struct EXTEND *e)
+_dbl_ext_cvt(double value, struct EXTEND* e)
{
/* Convert double to extended
*/
value = frexp(value, &exponent);
e->sign = value < 0.0;
- if (e->sign) value = -value;
+ if (e->sign)
+ value = -value;
e->exp = exponent - 1;
value *= 4294967296.0;
e->m1 = value;
static struct EXTEND max_d;
double
-_ext_dbl_cvt(struct EXTEND *e)
+_ext_dbl_cvt(struct EXTEND* e)
{
/* Convert extended to double
*/
int sign = e->sign;
e->sign = 0;
- if (e->m1 == 0 && e->m2 == 0) {
+ if (e->m1 == 0 && e->m2 == 0)
+ {
return 0.0;
}
- if (max_d.exp == 0) {
+ if (max_d.exp == 0)
+ {
_dbl_ext_cvt(DBL_MAX, &max_d);
}
- if (cmp_ext(&max_d, e) < 0) {
+ if (cmp_ext(&max_d, e) < 0)
+ {
f = HUGE_VAL;
errno = ERANGE;
}
- else f = ldexp((double)e->m1*4294967296.0 + (double)e->m2, e->exp-63);
- if (sign) f = -f;
- if (f == 0.0 && (e->m1 != 0 || e->m2 != 0)) {
+ else
+ f = ldexp((double)e->m1 * 4294967296.0 + (double)e->m2, e->exp - 63);
+ if (sign)
+ f = -f;
+ if (f == 0.0 && (e->m1 != 0 || e->m2 != 0))
+ {
errno = ERANGE;
}
return f;
*/
char* getenv(const char* name)
{
- int offset;
+ int offset;
- return(_findenv(name,&offset));
+ return (_findenv(name, &offset));
}
/*
*/
char* _findenv(register const char* name, int* offset)
{
- extern char **environ;
- register int len;
- register char **P;
- register const char *C;
+ extern char** environ;
+ register int len;
+ register char** P;
+ register const char* C;
if (!environ)
return NULL;
- for (C = name,len = 0;*C && *C != '=';++C,++len);
- for (P = environ;*P;++P)
- if (!strncmp(*P,name,len))
- if (*(C = *P + len) == '=') {
- *offset = P - environ;
- return (char*)(++C);
- }
- return(NULL);
+ for (C = name, len = 0; *C && *C != '='; ++C, ++len)
+ ;
+ for (P = environ; *P; ++P)
+ if (!strncmp(*P, name, len))
+ if (*(C = *P + len) == '=')
+ {
+ *offset = P - environ;
+ return (char*)(++C);
+ }
+ return (NULL);
}
-
*/
/* $Id$ */
-#include <stdlib.h>
+#include <stdlib.h>
-long
-labs(register long l)
+long labs(register long l)
{
return l >= 0 ? l : -l;
}
*/
/* $Id$ */
-#include <stdlib.h>
+#include <stdlib.h>
ldiv_t
ldiv(register long numer, register long denom)
{
ldiv_t r;
- r.quot = numer / denom; /* might trap if denom == 0 */
+ r.quot = numer / denom; /* might trap if denom == 0 */
r.rem = numer % denom;
- if (r.rem != 0 && (numer > 0) != (r.rem > 0)) {
+ if (r.rem != 0 && (numer > 0) != (r.rem > 0))
+ {
r.quot++;
r.rem -= denom;
}
*/
/* $Id$ */
-#include <stdlib.h>
-#include <limits.h>
+#include <stdlib.h>
+#include <limits.h>
-#define CHAR_SHIFT 8
+#define CHAR_SHIFT 8
-int
-(mblen)(const char *s, size_t n)
+int(mblen)(const char* s, size_t n)
{
- if (s == (const char *)NULL) return 0; /* no state dependent codings */
- if (n <= 0) return 0;
+ if (s == (const char*)NULL)
+ return 0; /* no state dependent codings */
+ if (n <= 0)
+ return 0;
return (*s != 0);
}
*/
/* $Id$ */
-#include <stdlib.h>
+#include <stdlib.h>
size_t
-mbstowcs(register wchar_t *pwcs, register const char *s, size_t n)
+mbstowcs(register wchar_t* pwcs, register const char* s, size_t n)
{
register int i = n;
- while (--i >= 0) {
+ while (--i >= 0)
+ {
if (!(*pwcs++ = *s++))
return n - i - 1;
}
return n - i;
}
-
*/
/* $Id$ */
-#include <stdlib.h>
-#include <limits.h>
+#include <stdlib.h>
+#include <limits.h>
-int
-mbtowc(wchar_t *pwc, register const char *s, size_t n)
+int mbtowc(wchar_t* pwc, register const char* s, size_t n)
{
- if (s == (const char *)NULL) return 0;
- if (n <= 0) return 0;
- if (pwc) *pwc = *s;
+ if (s == (const char*)NULL)
+ return 0;
+ if (n <= 0)
+ return 0;
+ if (pwc)
+ *pwc = *s;
return (*s != 0);
}
*/
/* $Id$ */
-#include <stdlib.h>
-#include <string.h>
+#include <stdlib.h>
+#include <string.h>
-#define ENTRY_INC 10
-#define rounded(x) (((x / ENTRY_INC) + 1) * ENTRY_INC)
+#define ENTRY_INC 10
+#define rounded(x) (((x / ENTRY_INC) + 1) * ENTRY_INC)
-extern char **environ;
+extern char** environ;
-int
-putenv(char *name)
+int putenv(char* name)
{
- register char **v = environ;
- register char *r;
+ register char** v = environ;
+ register char* r;
static int size = 0;
/* When size != 0, it contains the number of entries in the
* table (including the final NULL pointer). This means that the
* last non-null entry is environ[size - 2].
*/
- if (!name) return 0;
- if (r = strchr(name, '=')) {
+ if (!name)
+ return 0;
+ if (r = strchr(name, '='))
+ {
register const char *p, *q;
*r = '\0';
- if (v != NULL) {
- while ((p = *v) != NULL) {
+ if (v != NULL)
+ {
+ while ((p = *v) != NULL)
+ {
q = name;
while (*q && (*q++ == *p++))
- /* EMPTY */ ;
- if (*q || (*p != '=')) {
+ /* EMPTY */;
+ if (*q || (*p != '='))
+ {
v++;
- } else {
+ }
+ else
+ {
/* The name was already in the
* environment.
*/
v = environ;
}
- if (!size) {
- register char **p;
+ if (!size)
+ {
+ register char** p;
register int i = 0;
if (v)
- do {
+ do
+ {
i++;
} while (*v++);
- if (!(v = malloc(rounded(i) * sizeof(char **))))
+ if (!(v = malloc(rounded(i) * sizeof(char**))))
return 1;
size = i;
p = environ;
environ = v;
- while (*v++ = *p++); /* copy the environment */
+ while (*v++ = *p++)
+ ; /* copy the environment */
v = environ;
- } else if (!(size % ENTRY_INC)) {
- if (!(v = realloc(environ, rounded(size) * sizeof(char **))))
+ }
+ else if (!(size % ENTRY_INC))
+ {
+ if (!(v = realloc(environ, rounded(size) * sizeof(char**))))
return 1;
environ = v;
}
*/
/* $Id$ */
-#include <stdlib.h>
+#include <stdlib.h>
-static void qsort1(char *, char *, size_t);
-static int (*qcompar)(const char *, const char *);
-static void qexchange(char *, char *, size_t);
-static void q3exchange(char *, char *, char *, size_t);
+static void qsort1(char*, char*, size_t);
+static int (*qcompar)(const char*, const char*);
+static void qexchange(char*, char*, size_t);
+static void q3exchange(char*, char*, char*, size_t);
-void
-qsort(void *base, size_t nel, size_t width,
- int (*compar)(const void *, const void *))
+void qsort(void* base, size_t nel, size_t width,
+ int (*compar)(const void*, const void*))
{
/* when nel is 0, the expression '(nel - 1) * width' is wrong */
- if (!nel) return;
- qcompar = (int (*)(const char *, const char *)) compar;
- qsort1(base, (char *)base + (nel - 1) * width, width);
+ if (!nel)
+ return;
+ qcompar = (int (*)(const char*, const char*))compar;
+ qsort1(base, (char*)base + (nel - 1) * width, width);
}
static void
-qsort1(char *a1, char *a2, register size_t width)
+qsort1(char* a1, char* a2, register size_t width)
{
register char *left, *right;
register char *lefteq, *righteq;
int cmp;
- for (;;) {
- if (a2 <= a1) return;
+ for (;;)
+ {
+ if (a2 <= a1)
+ return;
left = a1;
right = a2;
- lefteq = righteq = a1 + width * (((a2-a1)+width)/(2*width));
- /*
+ lefteq = righteq = a1 + width * (((a2 - a1) + width) / (2 * width));
+ /*
Pick an element in the middle of the array.
We will collect the equals around it.
"lefteq" and "righteq" indicate the left and right
Smaller elements end up left of it, larger elements end
up right of it.
*/
-again:
- while (left < lefteq && (cmp = (*qcompar)(left, lefteq)) <= 0) {
- if (cmp < 0) {
+ again:
+ while (left < lefteq && (cmp = (*qcompar)(left, lefteq)) <= 0)
+ {
+ if (cmp < 0)
+ {
/* leave it where it is */
left += width;
}
- else {
+ else
+ {
/* equal, so exchange with the element to
the left of the "equal"-interval.
*/
qexchange(left, lefteq, width);
}
}
- while (right > righteq) {
- if ((cmp = (*qcompar)(right, righteq)) < 0) {
+ while (right > righteq)
+ {
+ if ((cmp = (*qcompar)(right, righteq)) < 0)
+ {
/* smaller, should go to left part
*/
- if (left < lefteq) {
+ if (left < lefteq)
+ {
/* yes, we had a larger one at the
left, so we can just exchange
*/
lefteq += width;
left = lefteq;
}
- else if (cmp == 0) {
+ else if (cmp == 0)
+ {
/* equal, so exchange with the element to
the right of the "equal-interval"
*/
righteq += width;
qexchange(right, righteq, width);
}
- else /* just leave it */ right -= width;
+ else /* just leave it */
+ right -= width;
}
- if (left < lefteq) {
+ if (left < lefteq)
+ {
/* larger element to the left, but no more room,
so move the "equal-interval" one place to the
left, and the larger element to the right
}
static void
-qexchange(register char *p, register char *q,
- register size_t n)
+qexchange(register char* p, register char* q,
+ register size_t n)
{
register int c;
- while (n-- > 0) {
+ while (n-- > 0)
+ {
c = *p;
*p++ = *q;
*q++ = c;
}
static void
-q3exchange(register char *p, register char *q, register char *r,
- register size_t n)
+q3exchange(register char* p, register char* q, register char* r,
+ register size_t n)
{
register int c;
- while (n-- > 0) {
+ while (n-- > 0)
+ {
c = *p;
*p++ = *r;
*r++ = *q;
*/
/* $Id$ */
-#include <stdlib.h>
+#include <stdlib.h>
static unsigned long int next = 1;
int rand(void)
{
next = next * 1103515245 + 12345;
- return (unsigned int)(next/(2 * (RAND_MAX +1L)) % (RAND_MAX+1L));
+ return (unsigned int)(next / (2 * (RAND_MAX + 1L)) % (RAND_MAX + 1L));
}
void srand(unsigned int seed)
#include <string.h>
extern char* _findenv(const char* name, int* offset);
-extern char **environ;
+extern char** environ;
/*
* setenv(name,value,rewrite)
*/
int setenv(register const char* name, register const char* value, int rewrite)
{
- static int alloced = 0; /* if allocated space before */
- register char *C;
- int l_value,
- offset;
+ static int alloced = 0; /* if allocated space before */
+ register char* C;
+ int l_value,
+ offset;
- if (*value == '=') /* no `=' in value */
- ++value;
- l_value = strlen(value);
- if ((C = _findenv(name,&offset))) { /* find if already exists */
- if (!rewrite)
- return(0);
- if (strlen(C) >= l_value) { /* old larger; copy over */
- while (*C++ = *value++);
- return(0);
- }
- }
- else { /* create new slot */
- register int cnt = 0;
- register char **P;
+ if (*value == '=') /* no `=' in value */
+ ++value;
+ l_value = strlen(value);
+ if ((C = _findenv(name, &offset)))
+ { /* find if already exists */
+ if (!rewrite)
+ return (0);
+ if (strlen(C) >= l_value)
+ { /* old larger; copy over */
+ while (*C++ = *value++)
+ ;
+ return (0);
+ }
+ }
+ else
+ { /* create new slot */
+ register int cnt = 0;
+ register char** P;
if (environ)
- for (P = environ;*P;++P,++cnt);
- if (alloced) { /* just increase size */
- environ = (char **)realloc((char *)environ,
- (unsigned)(sizeof(char *) * (cnt + 2)));
- if (!environ)
- return(-1);
- }
- else { /* get new space */
- alloced = 1; /* copy old entries into it */
- P = (char **)malloc((unsigned)(sizeof(char *) *
- (cnt + 2)));
- if (!P)
- return(-1);
- if (environ)
- bcopy(environ,P,cnt * sizeof(char *));
- environ = P;
- }
- environ[cnt + 1] = NULL;
- offset = cnt;
- }
- for (C = name;*C && *C != '=';++C); /* no `=' in name */
- if (!(environ[offset] = /* name + `=' + value */
- malloc((unsigned)((int)(C - name) + l_value + 2))))
- return(-1);
- for (C = environ[offset];(*C = *name++) && *C != '=';++C);
- for (*C++ = '=';*C++ = *value++;);
- return(0);
+ for (P = environ; *P; ++P, ++cnt)
+ ;
+ if (alloced)
+ { /* just increase size */
+ environ = (char**)realloc((char*)environ,
+ (unsigned)(sizeof(char*) * (cnt + 2)));
+ if (!environ)
+ return (-1);
+ }
+ else
+ { /* get new space */
+ alloced = 1; /* copy old entries into it */
+ P = (char**)malloc((unsigned)(sizeof(char*) * (cnt + 2)));
+ if (!P)
+ return (-1);
+ if (environ)
+ bcopy(environ, P, cnt * sizeof(char*));
+ environ = P;
+ }
+ environ[cnt + 1] = NULL;
+ offset = cnt;
+ }
+ for (C = name; *C && *C != '='; ++C)
+ ; /* no `=' in name */
+ if (!(environ[offset] = /* name + `=' + value */
+ malloc((unsigned)((int)(C - name) + l_value + 2))))
+ return (-1);
+ for (C = environ[offset]; (*C = *name++) && *C != '='; ++C)
+ ;
+ for (*C++ = '='; *C++ = *value++;)
+ ;
+ return (0);
}
/*
* unsetenv(name) --
* Delete environmental variable "name".
*/
-int
-unsetenv(const char* name)
+int unsetenv(const char* name)
{
- register char **P;
- int offset;
+ register char** P;
+ int offset;
- while (_findenv(name,&offset)) /* if set multiple times */
- for (P = &environ[offset];;++P)
- if (!(*P = *(P + 1)))
- break;
+ while (_findenv(name, &offset)) /* if set multiple times */
+ for (P = &environ[offset];; ++P)
+ if (!(*P = *(P + 1)))
+ break;
- return 0;
+ return 0;
}
-
/* $Id$ */
-#include <stdlib.h>
-#include "ext_fmt.h"
+#include <stdlib.h>
+#include "ext_fmt.h"
-#ifndef ACKCONF_NO_STDIO_FLOAT
+#ifndef ACKCONF_NO_STDIO_FLOAT
-void _str_ext_cvt(const char *s, char **ss, struct EXTEND *e);
-double _ext_dbl_cvt(struct EXTEND *e);
+void _str_ext_cvt(const char* s, char** ss, struct EXTEND* e);
+double _ext_dbl_cvt(struct EXTEND* e);
double
-strtod(const char *p, char **pp)
+strtod(const char* p, char** pp)
{
struct EXTEND e;
*/
/* $Id$ */
-#include <ctype.h>
-#include <errno.h>
-#include <limits.h>
-#include <stdlib.h>
+#include <ctype.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdlib.h>
static unsigned long
-string2long(register const char *nptr, char **endptr,
- int base, int is_signed);
+string2long(register const char* nptr, char** endptr,
+ int base, int is_signed);
long int
-strtol(register const char *nptr, char **endptr, int base)
+strtol(register const char* nptr, char** endptr, int base)
{
return (signed long)string2long(nptr, endptr, base, 1);
}
unsigned long int
-strtoul(register const char *nptr, char **endptr, int base)
+strtoul(register const char* nptr, char** endptr, int base)
{
return (unsigned long)string2long(nptr, endptr, base, 0);
}
static unsigned long
-string2long(register const char *nptr, char ** const endptr,
- int base, int is_signed)
+string2long(register const char* nptr, char** const endptr,
+ int base, int is_signed)
{
register unsigned int v;
register unsigned long val = 0;
int ovfl = 0, sign = 1;
const char *startnptr = nptr, *nrstart;
- if (endptr) *endptr = (char *)nptr;
- while (isspace(*nptr)) nptr++;
+ if (endptr)
+ *endptr = (char*)nptr;
+ while (isspace(*nptr))
+ nptr++;
c = *nptr;
- if (c == '-' || c == '+') {
- if (c == '-') sign = -1;
+ if (c == '-' || c == '+')
+ {
+ if (c == '-')
+ sign = -1;
nptr++;
}
- nrstart = nptr; /* start of the number */
+ nrstart = nptr; /* start of the number */
/* When base is 0, the syntax determines the actual base */
if (base == 0)
if (*nptr == '0')
- if (*++nptr == 'x' || *nptr == 'X') {
+ if (*++nptr == 'x' || *nptr == 'X')
+ {
base = 16;
nptr++;
}
- else base = 8;
- else base = 10;
- else if (base==16 && *nptr=='0' && (*++nptr =='x' || *nptr =='X'))
+ else
+ base = 8;
+ else
+ base = 10;
+ else if (base == 16 && *nptr == '0' && (*++nptr == 'x' || *nptr == 'X'))
nptr++;
- while (isdigit(c = *nptr) || isalpha(c)) {
- if (!ovfl) {
+ while (isdigit(c = *nptr) || isalpha(c))
+ {
+ if (!ovfl)
+ {
if (isalpha(c))
v = 10 + (isupper(c) ? c - 'A' : c - 'a');
else
v = c - '0';
- if (v >= base) break;
- if (val > (ULONG_MAX - v) / base) ++ovfl;
- else val = (val * base) + v;
+ if (v >= base)
+ break;
+ if (val > (ULONG_MAX - v) / base)
+ ++ovfl;
+ else
+ val = (val * base) + v;
}
nptr++;
}
- if (endptr) {
- if (nrstart == nptr) *endptr = (char *)startnptr;
- else *endptr = (char *)nptr;
+ if (endptr)
+ {
+ if (nrstart == nptr)
+ *endptr = (char*)startnptr;
+ else
+ *endptr = (char*)nptr;
}
- if (!ovfl) {
+ if (!ovfl)
+ {
/* Overflow is only possible when converting a signed long.
* The "-(LONG_MIN+1)+(unsigned long) 1" construction is there
* to prevent overflow warnings on -LONG_MIN.
*/
if (is_signed
- && ( (sign < 0 && val > -(LONG_MIN+1)+(unsigned long) 1)
- || (sign > 0 && val > LONG_MAX)))
- ovfl++;
+ && ((sign < 0 && val > -(LONG_MIN + 1) + (unsigned long)1)
+ || (sign > 0 && val > LONG_MAX)))
+ ovfl++;
}
- if (ovfl) {
+ if (ovfl)
+ {
errno = ERANGE;
if (is_signed)
- if (sign < 0) return LONG_MIN;
- else return LONG_MAX;
- else return ULONG_MAX;
+ if (sign < 0)
+ return LONG_MIN;
+ else
+ return LONG_MAX;
+ else
+ return ULONG_MAX;
}
return (sign * val);
}
*/
/* $Id$ */
-#if defined(_POSIX_SOURCE)
+#if defined(_POSIX_SOURCE)
#include <sys/types.h>
#endif
#include <stdlib.h>
extern char** environ;
extern int _fork(void);
-extern int _wait(int *);
+extern int _wait(int*);
extern void _exit(int);
-extern void _execve(const char *path, const char ** argv, const char ** envp);
+extern void _execve(const char* path, const char** argv, const char** envp);
extern void _close(int);
-#define FAIL 127
+#define FAIL 127
-static const char *exec_tab[] = {
- "sh", /* argv[0] */
- "-c", /* argument to the shell */
- NULL, /* to be filled with user command */
- NULL /* terminating NULL */
- };
+static const char* exec_tab[] = {
+ "sh", /* argv[0] */
+ "-c", /* argument to the shell */
+ NULL, /* to be filled with user command */
+ NULL /* terminating NULL */
+};
-int
-system(const char *str)
+int system(const char* str)
{
int pid, exitstatus, waitval;
int i;
- if ((pid = _fork()) < 0) return str ? -1 : 0;
+ if ((pid = _fork()) < 0)
+ return str ? -1 : 0;
- if (pid == 0) {
+ if (pid == 0)
+ {
for (i = 3; i <= 20; i++)
_close(i);
- if (!str) str = "cd ."; /* just testing for a shell */
- exec_tab[2] = str; /* fill in command */
- _execve("/bin/sh", exec_tab, (char const**) environ);
+ if (!str)
+ str = "cd ."; /* just testing for a shell */
+ exec_tab[2] = str; /* fill in command */
+ _execve("/bin/sh", exec_tab, (char const**)environ);
/* get here if execve fails ... */
- _exit(FAIL); /* see manual page */
+ _exit(FAIL); /* see manual page */
}
- while ((waitval = _wait(&exitstatus)) != pid) {
- if (waitval == -1) break;
+ while ((waitval = _wait(&exitstatus)) != pid)
+ {
+ if (waitval == -1)
+ break;
}
- if (waitval == -1) {
+ if (waitval == -1)
+ {
/* no child ??? or maybe interrupted ??? */
exitstatus = -1;
}
- if (!str) {
- if (exitstatus == FAIL << 8) /* execve() failed */
+ if (!str)
+ {
+ if (exitstatus == FAIL << 8) /* execve() failed */
exitstatus = 0;
- else exitstatus = 1; /* /bin/sh exists */
+ else
+ exitstatus = 1; /* /bin/sh exists */
}
return exitstatus;
}
*/
/* $Id$ */
-#include <stdlib.h>
-#include <locale.h>
-#include <limits.h>
+#include <stdlib.h>
+#include <locale.h>
+#include <limits.h>
size_t
-wcstombs(register char *s, register const wchar_t *pwcs, size_t n)
+wcstombs(register char* s, register const wchar_t* pwcs, size_t n)
{
register int i = n;
- while (--i >= 0) {
+ while (--i >= 0)
+ {
if (!(*s++ = *pwcs++))
break;
}
*/
/* $Id$ */
-#include <stdlib.h>
-#include <limits.h>
+#include <stdlib.h>
+#include <limits.h>
-int
-wctomb(char *s, wchar_t wchar)
+int wctomb(char* s, wchar_t wchar)
{
- if (!s) return 0; /* no state dependent codings */
+ if (!s)
+ return 0; /* no state dependent codings */
*s = wchar;
return 1;
*/
/* $Id$ */
-#include <string.h>
+#include <string.h>
-void *
-memchr(const void *s, register int c, register size_t n)
+void* memchr(const void* s, register int c, register size_t n)
{
- register const unsigned char *s1 = s;
+ register const unsigned char* s1 = s;
- c = (unsigned char) c;
- if (n) {
+ c = (unsigned char)c;
+ if (n)
+ {
n++;
- while (--n > 0) {
- if (*s1++ != c) continue;
- return (void *) --s1;
+ while (--n > 0)
+ {
+ if (*s1++ != c)
+ continue;
+ return (void*)--s1;
}
}
return NULL;
*/
/* $Id$ */
-#include <string.h>
+#include <string.h>
-int
-memcmp(const void *s1, const void *s2, size_t n)
+int memcmp(const void* s1, const void* s2, size_t n)
{
register const unsigned char *p1 = s1, *p2 = s2;
- if (n) {
+ if (n)
+ {
n++;
- while (--n > 0) {
- if (*p1++ == *p2++) continue;
+ while (--n > 0)
+ {
+ if (*p1++ == *p2++)
+ continue;
return *--p1 - *--p2;
}
}
*/
/* $Id$ */
-#include <string.h>
+#include <string.h>
-void *
-memcpy(void *s1, const void *s2, register size_t n)
+void* memcpy(void* s1, const void* s2, register size_t n)
{
- register char *p1 = s1;
- register const char *p2 = s2;
+ register char* p1 = s1;
+ register const char* p2 = s2;
-
- if (n) {
+ if (n)
+ {
n++;
- while (--n > 0) {
+ while (--n > 0)
+ {
*p1++ = *p2++;
}
}
*/
/* $Id$ */
-#include <string.h>
+#include <string.h>
-void *
-memmove(void *s1, const void *s2, register size_t n)
+void* memmove(void* s1, const void* s2, register size_t n)
{
- register char *p1 = s1;
- register const char *p2 = s2;
+ register char* p1 = s1;
+ register const char* p2 = s2;
- if (n>0) {
- if (p2 <= p1 && p2 + n > p1) {
+ if (n > 0)
+ {
+ if (p2 <= p1 && p2 + n > p1)
+ {
/* overlap, copy backwards */
p1 += n;
p2 += n;
n++;
- while (--n > 0) {
+ while (--n > 0)
+ {
*--p1 = *--p2;
}
- } else {
+ }
+ else
+ {
n++;
- while (--n > 0) {
+ while (--n > 0)
+ {
*p1++ = *p2++;
}
}
*/
/* $Id$ */
-#include <string.h>
+#include <string.h>
-void *
-memset(void *s, register int c, register size_t n)
+void* memset(void* s, register int c, register size_t n)
{
- register char *s1 = s;
+ register char* s1 = s;
- if (n>0) {
+ if (n > 0)
+ {
n++;
- while (--n > 0) {
+ while (--n > 0)
+ {
*s1++ = c;
}
}
*/
/* $Id$ */
-#include <string.h>
+#include <string.h>
-char *
-strcat(char *ret, register const char *s2)
+char* strcat(char* ret, register const char* s2)
{
- register char *s1 = ret;
+ register char* s1 = ret;
while (*s1++ != '\0')
- /* EMPTY */ ;
+ /* EMPTY */;
s1--;
while (*s1++ = *s2++)
- /* EMPTY */ ;
+ /* EMPTY */;
return ret;
}
*/
/* $Id$ */
-#include <string.h>
+#include <string.h>
-char *
-strchr(register const char *s, register int c)
+char* strchr(register const char* s, register int c)
{
- c = (char) c;
+ c = (char)c;
- while (c != *s) {
- if (*s++ == '\0') return NULL;
+ while (c != *s)
+ {
+ if (*s++ == '\0')
+ return NULL;
}
- return (char *)s;
+ return (char*)s;
}
*/
/* $Id$ */
-#include <string.h>
+#include <string.h>
-int
-strcmp(register const char *s1, register const char *s2)
+int strcmp(register const char* s1, register const char* s2)
{
- while (*s1 == *s2++) {
- if (*s1++ == '\0') {
+ while (*s1 == *s2++)
+ {
+ if (*s1++ == '\0')
+ {
return 0;
}
}
- if (*s1 == '\0') return -1;
- if (*--s2 == '\0') return 1;
- return (unsigned char) *s1 - (unsigned char) *s2;
+ if (*s1 == '\0')
+ return -1;
+ if (*--s2 == '\0')
+ return 1;
+ return (unsigned char)*s1 - (unsigned char)*s2;
}
*/
/* $Id$ */
-#include <string.h>
-#include <locale.h>
+#include <string.h>
+#include <locale.h>
-int
-strcoll(register const char *s1, register const char *s2)
+int strcoll(register const char* s1, register const char* s2)
{
- while (*s1 == *s2++) {
- if (*s1++ == '\0') {
+ while (*s1 == *s2++)
+ {
+ if (*s1++ == '\0')
+ {
return 0;
}
}
*/
/* $Id$ */
-#include <string.h>
+#include <string.h>
-char *
-strcpy(char *ret, register const char *s2)
+char* strcpy(char* ret, register const char* s2)
{
- register char *s1 = ret;
+ register char* s1 = ret;
while (*s1++ = *s2++)
- /* EMPTY */ ;
+ /* EMPTY */;
return ret;
}
*/
/* $Id$ */
-#include <string.h>
+#include <string.h>
size_t
-strcspn(const char *string, const char *notin)
+strcspn(const char* string, const char* notin)
{
register const char *s1, *s2;
- for (s1 = string; *s1; s1++) {
- for(s2 = notin; *s2 != *s1 && *s2; s2++)
- /* EMPTY */ ;
+ for (s1 = string; *s1; s1++)
+ {
+ for (s2 = notin; *s2 != *s1 && *s2; s2++)
+ /* EMPTY */;
if (*s2)
break;
}
#include <stdlib.h>
#include <string.h>
-char*
-strdup(const char *s)
+char* strdup(const char* s)
{
int len = strlen(s);
- char *p = malloc(len+1);
+ char* p = malloc(len + 1);
if (p)
- memcpy(p, s, len+1);
+ memcpy(p, s, len + 1);
return p;
}
*/
/* $Id$ */
-#include <string.h>
+#include <string.h>
/*
* I don't know why, but X3J11 says that strerror() should be in declared
* in <string.h>. That is why the function is defined here.
*/
-char *
-strerror(register int errnum)
+char* strerror(register int errnum)
{
- extern const char *_sys_errlist[];
+ extern const char* _sys_errlist[];
extern const int _sys_nerr;
- if (errnum < 0 || errnum >= _sys_nerr)
+ if (errnum < 0 || errnum >= _sys_nerr)
return "unknown error";
- return (char *)_sys_errlist[errnum];
+ return (char*)_sys_errlist[errnum];
}
*/
/* $Id$ */
-#include <string.h>
+#include <string.h>
size_t
-strlen(const char *org)
+strlen(const char* org)
{
- register const char *s = org;
+ register const char* s = org;
while (*s++)
- /* EMPTY */ ;
+ /* EMPTY */;
return --s - org;
}
*/
/* $Id$ */
-#include <string.h>
+#include <string.h>
-char *
-strncat(char *ret, register const char *s2, size_t n)
+char* strncat(char* ret, register const char* s2, size_t n)
{
- register char *s1 = ret;
+ register char* s1 = ret;
- if (n > 0) {
+ if (n > 0)
+ {
while (*s1++)
- /* EMPTY */ ;
+ /* EMPTY */;
s1--;
- while (*s1++ = *s2++) {
- if (--n > 0) continue;
+ while (*s1++ = *s2++)
+ {
+ if (--n > 0)
+ continue;
*s1 = '\0';
break;
}
return ret;
- } else return s1;
+ }
+ else
+ return s1;
}
*/
/* $Id$ */
-#include <string.h>
+#include <string.h>
-int
-strncmp(register const char *s1, register const char *s2, register size_t n)
+int strncmp(register const char* s1, register const char* s2, register size_t n)
{
- if (n) {
- do {
+ if (n)
+ {
+ do
+ {
if (*s1 != *s2++)
break;
if (*s1++ == '\0')
return 0;
} while (--n > 0);
- if (n > 0) {
- if (*s1 == '\0') return -1;
- if (*--s2 == '\0') return 1;
- return (unsigned char) *s1 - (unsigned char) *s2;
+ if (n > 0)
+ {
+ if (*s1 == '\0')
+ return -1;
+ if (*--s2 == '\0')
+ return 1;
+ return (unsigned char)*s1 - (unsigned char)*s2;
}
}
return 0;
*/
/* $Id$ */
-#include <string.h>
+#include <string.h>
-char *
-strncpy(char *ret, register const char *s2, register size_t n)
+char* strncpy(char* ret, register const char* s2, register size_t n)
{
- register char *s1 = ret;
+ register char* s1 = ret;
- if (n>0) {
- while((*s1++ = *s2++) && --n > 0)
- /* EMPTY */ ;
- if ((*--s2 == '\0') && --n > 0) {
- do {
+ if (n > 0)
+ {
+ while ((*s1++ = *s2++) && --n > 0)
+ /* EMPTY */;
+ if ((*--s2 == '\0') && --n > 0)
+ {
+ do
+ {
*s1++ = '\0';
- } while(--n > 0);
+ } while (--n > 0);
}
}
return ret;
*/
/* $Id$ */
-#include <string.h>
+#include <string.h>
-char *
-strpbrk(register const char *string, register const char *brk)
+char* strpbrk(register const char* string, register const char* brk)
{
- register const char *s1;
+ register const char* s1;
- while (*string) {
+ while (*string)
+ {
for (s1 = brk; *s1 && *s1 != *string; s1++)
- /* EMPTY */ ;
+ /* EMPTY */;
if (*s1)
- return (char *)string;
+ return (char*)string;
string++;
}
- return (char *)NULL;
+ return (char*)NULL;
}
*/
/* $Id$ */
-#include <string.h>
+#include <string.h>
-char *
-strrchr(register const char *s, int c)
+char* strrchr(register const char* s, int c)
{
- register const char *result = NULL;
+ register const char* result = NULL;
- c = (char) c;
+ c = (char)c;
- do {
+ do
+ {
if (c == *s)
result = s;
} while (*s++ != '\0');
- return (char *)result;
+ return (char*)result;
}
*/
/* $Id$ */
-#include <string.h>
+#include <string.h>
size_t
-strspn(const char *string, const char *in)
+strspn(const char* string, const char* in)
{
register const char *s1, *s2;
- for (s1 = string; *s1; s1++) {
+ for (s1 = string; *s1; s1++)
+ {
for (s2 = in; *s2 && *s2 != *s1; s2++)
- /* EMPTY */ ;
+ /* EMPTY */;
if (*s2 == '\0')
break;
}
*/
/* $Id$ */
-#include <string.h>
+#include <string.h>
-char *
-strstr(register const char *s, register const char *wanted)
+char* strstr(register const char* s, register const char* wanted)
{
register const int len = strlen(wanted);
- if (len == 0) return (char *)s;
+ if (len == 0)
+ return (char*)s;
while (*s != *wanted || strncmp(s, wanted, len))
if (*s++ == '\0')
- return (char *)NULL;
- return (char *)s;
+ return (char*)NULL;
+ return (char*)s;
}
*/
/* $Id$ */
-#include <string.h>
+#include <string.h>
-char *
-strtok(register char *string, const char *separators)
+char* strtok(register char* string, const char* separators)
{
register char *s1, *s2;
- static char *savestring;
+ static char* savestring;
- if (string == NULL) {
+ if (string == NULL)
+ {
string = savestring;
- if (string == NULL) return (char *)NULL;
+ if (string == NULL)
+ return (char*)NULL;
}
s1 = string + strspn(string, separators);
- if (*s1 == '\0') {
+ if (*s1 == '\0')
+ {
savestring = NULL;
- return (char *)NULL;
+ return (char*)NULL;
}
s2 = strpbrk(s1, separators);
*/
/* $Id$ */
-#include <string.h>
+#include <string.h>
size_t
-strxfrm(register char *s1, register const char *save, register size_t n)
+strxfrm(register char* s1, register const char* save, register size_t n)
{
- register const char *s2 = save;
+ register const char* s2 = save;
- while (*s2) {
- if (n > 1) {
+ while (*s2)
+ {
+ if (n > 1)
+ {
n--;
*s1++ = *s2++;
- } else
+ }
+ else
s2++;
}
if (n > 0)
*/
/* $Id$ */
-#include <string.h>
-#include <time.h>
-#include "loc_time.h"
+#include <string.h>
+#include <time.h>
+#include "loc_time.h"
-#define DATE_STR "??? ??? ?? ??:??:?? ????\n"
+#define DATE_STR "??? ??? ?? ??:??:?? ????\n"
-static char *
-two_digits(register char *pb, int i, int nospace)
+static char*
+two_digits(register char* pb, int i, int nospace)
{
*pb = (i / 10) % 10 + '0';
- if (!nospace && *pb == '0') *pb = ' ';
+ if (!nospace && *pb == '0')
+ *pb = ' ';
pb++;
*pb++ = (i % 10) + '0';
return ++pb;
}
-static char *
-four_digits(register char *pb, int i)
+static char*
+four_digits(register char* pb, int i)
{
i %= 10000;
*pb++ = (i / 1000) + '0';
return ++pb;
}
-char *asctime(const struct tm *timeptr)
+char* asctime(const struct tm* timeptr)
{
static char buf[26];
- register char *pb = buf;
- register const char *ps;
+ register char* pb = buf;
+ register const char* ps;
register int n;
strcpy(pb, DATE_STR);
ps = _days[timeptr->tm_wday];
n = ABB_LEN;
- while(--n >= 0) *pb++ = *ps++;
+ while (--n >= 0)
+ *pb++ = *ps++;
pb++;
ps = _months[timeptr->tm_mon];
n = ABB_LEN;
- while(--n >= 0) *pb++ = *ps++;
+ while (--n >= 0)
+ *pb++ = *ps++;
pb++;
pb = two_digits(
- two_digits(
- two_digits(two_digits(pb, timeptr->tm_mday, 0)
- , timeptr->tm_hour, 1)
- , timeptr->tm_min, 1)
- , timeptr->tm_sec, 1);
+ two_digits(
+ two_digits(two_digits(pb, timeptr->tm_mday, 0), timeptr->tm_hour, 1), timeptr->tm_min, 1),
+ timeptr->tm_sec, 1);
four_digits(pb, timeptr->tm_year + 1900);
return buf;
*/
/* $Id$ */
-#include <time.h>
-
-#if defined(__BSD4_2)
-
-#define RUSAGE_SELF 0
-#define RUSAGE_CHILDREN -1
-
-struct rusage {
- struct timeval ru_utime; /* user time used */
- struct timeval ru_stime; /* system time used */
- long ru_maxrss;
- long ru_ixrss; /* integral shared memory size */
- long ru_idrss; /* integral unshared data size */
- long ru_isrss; /* integral unshared stack size */
- long ru_minflt; /* page reclaims */
- long ru_majflt; /* page faults */
- long ru_nswap; /* swaps */
- long ru_inblock; /* block input operations */
- long ru_oublock; /* block output operations */
- long ru_msgsnd; /* messages sent */
- long ru_msgrcv; /* messages received */
- long ru_nsignals; /* signals received */
- long ru_nvcsw; /* voluntary context switches */
- long ru_nivcsw; /* involuntary context switches */
+#include <time.h>
+
+#if defined(__BSD4_2)
+
+#define RUSAGE_SELF 0
+#define RUSAGE_CHILDREN -1
+
+struct rusage
+{
+ struct timeval ru_utime; /* user time used */
+ struct timeval ru_stime; /* system time used */
+ long ru_maxrss;
+ long ru_ixrss; /* integral shared memory size */
+ long ru_idrss; /* integral unshared data size */
+ long ru_isrss; /* integral unshared stack size */
+ long ru_minflt; /* page reclaims */
+ long ru_majflt; /* page faults */
+ long ru_nswap; /* swaps */
+ long ru_inblock; /* block input operations */
+ long ru_oublock; /* block output operations */
+ long ru_msgsnd; /* messages sent */
+ long ru_msgrcv; /* messages received */
+ long ru_nsignals; /* signals received */
+ long ru_nvcsw; /* voluntary context switches */
+ long ru_nivcsw; /* involuntary context switches */
};
-void _getrusage(int who, struct rusage *rusage);
+void _getrusage(int who, struct rusage* rusage);
-#elif defined(_POSIX_SOURCE) || defined(__USG)
+#elif defined(_POSIX_SOURCE) || defined(__USG)
-struct tms {
- time_t tms_utime; /* user time */
- time_t tms_stime; /* system time */
- time_t tms_cutime; /* user time, children */
- time_t tms_cstime; /* system time, children */
+struct tms
+{
+ time_t tms_utime; /* user time */
+ time_t tms_stime; /* system time */
+ time_t tms_cutime; /* user time, children */
+ time_t tms_cstime; /* system time, children */
};
-long _times(struct tms *buffer);
+long _times(struct tms* buffer);
-#else /* Version 7 UNIX */
+#else /* Version 7 UNIX */
-struct tbuffer {
+struct tbuffer
+{
long proc_user_time;
long proc_system_time;
long child_user_time;
long child_system_time;
};
-long _times(struct tbuffer *buffer);
+long _times(struct tbuffer* buffer);
#endif
clock_t
clock(void)
{
-#if defined(__BSD4_2)
+#if defined(__BSD4_2)
struct rusage rusage;
_getrusage(RUSAGE_SELF, &rusage);
return (((unsigned long)rusage.ru_utime.tv_sec * CLOCKS_PER_SEC)
- + rusage.ru_utime.tv_usec);
-#elif defined(_POSIX_SOURCE) || defined(__USG)
+ + rusage.ru_utime.tv_usec);
+#elif defined(_POSIX_SOURCE) || defined(__USG)
struct tms tms;
_times(&tms);
*/
/* $Id$ */
-#include <time.h>
+#include <time.h>
-char *
-(ctime)(const time_t *timer)
+char*(ctime)(const time_t* timer)
{
return asctime(localtime(timer));
}
*/
/* $Id$ */
-#include <time.h>
+#include <time.h>
double
difftime(time_t time1, time_t time0)
{
/* be careful: time_t may be unsigned */
- if ((time_t)-1 > 0 && time0 > time1) {
- return - (double) (time0 - time1);
- } else {
+ if ((time_t)-1 > 0 && time0 > time1)
+ {
+ return -(double)(time0 - time1);
+ }
+ else
+ {
return (double)(time1 - time0);
}
}
*/
/* $Id$ */
-#include <time.h>
-#include <limits.h>
-#include "loc_time.h"
+#include <time.h>
+#include <limits.h>
+#include "loc_time.h"
-struct tm *
-gmtime(register const time_t *timer)
+struct tm*
+gmtime(register const time_t* timer)
{
static struct tm br_time;
- register struct tm *timep = &br_time;
+ register struct tm* timep = &br_time;
time_t tim = *timer;
register unsigned long dayclock, dayno;
int year = EPOCH_YR;
timep->tm_sec = dayclock % 60;
timep->tm_min = (dayclock % 3600) / 60;
timep->tm_hour = dayclock / 3600;
- timep->tm_wday = (dayno + 4) % 7; /* day 0 was a thursday */
- while (dayno >= YEARSIZE(year)) {
+ timep->tm_wday = (dayno + 4) % 7; /* day 0 was a thursday */
+ while (dayno >= YEARSIZE(year))
+ {
dayno -= YEARSIZE(year);
year++;
}
timep->tm_year = year - YEAR0;
timep->tm_yday = dayno;
timep->tm_mon = 0;
- while (dayno >= _ytab[LEAPYEAR(year)][timep->tm_mon]) {
+ while (dayno >= _ytab[LEAPYEAR(year)][timep->tm_mon])
+ {
dayno -= _ytab[LEAPYEAR(year)][timep->tm_mon];
timep->tm_mon++;
}
*/
/* $Id$ */
-#include <time.h>
-#include "loc_time.h"
+#include <time.h>
+#include "loc_time.h"
/* We must be careful, since an int can't represent all the seconds in a day.
* Hence the adjustment of minutes when adding timezone and dst information.
* Furthermore, it is assumed that both fit into an integer when expressed as
* minutes (this is about 22 days, so this should not cause any problems).
*/
-struct tm *
-localtime(const time_t *timer)
+struct tm*
+localtime(const time_t* timer)
{
- struct tm *timep;
+ struct tm* timep;
unsigned dst;
_tzset();
- timep = gmtime(timer); /* tm->tm_isdst == 0 */
+ timep = gmtime(timer); /* tm->tm_isdst == 0 */
timep->tm_min -= _timezone / 60;
timep->tm_sec -= _timezone % 60;
mktime(timep);
dst = _dstget(timep);
- if (dst) {
+ if (dst)
+ {
timep->tm_min += dst / 60;
timep->tm_sec += dst % 60;
mktime(timep);
*/
/* $Id$ */
-#include <ctype.h>
-#include <time.h>
-#include <stdlib.h>
-#include <string.h>
+#include <ctype.h>
+#include <time.h>
+#include <stdlib.h>
+#include <string.h>
-#if defined(__BSD4_2)
+#if defined(__BSD4_2)
-extern int _gettimeofday(struct timeval *tp, struct timezone *tzp);
+extern int _gettimeofday(struct timeval* tp, struct timezone* tzp);
-#elif !defined(_POSIX_SOURCE) && !defined(__USG)
-#if !defined(_MINIX) /* MINIX has no ftime() */
-struct timeb {
- long time;
+#elif !defined(_POSIX_SOURCE) && !defined(__USG)
+#if !defined(_MINIX) /* MINIX has no ftime() */
+struct timeb
+{
+ long time;
unsigned short millitm;
- short timezone;
- short dstflag;
+ short timezone;
+ short dstflag;
};
-void _ftime(struct timeb *bp);
+void _ftime(struct timeb* bp);
#endif
#endif
-#include "loc_time.h"
+#include "loc_time.h"
-#define RULE_LEN 120
-#define TZ_LEN 10
+#define RULE_LEN 120
+#define TZ_LEN 10
/* Make sure that the strings do not end up in ROM.
* These strings probably contain the wrong value, and we cannot obtain the
* right value from the system. TZ is the only help.
*/
-static char ntstr[TZ_LEN + 1] = "GMT"; /* string for normal time */
-static char dststr[TZ_LEN + 1] = "GDT"; /* string for daylight saving */
+static char ntstr[TZ_LEN + 1] = "GMT"; /* string for normal time */
+static char dststr[TZ_LEN + 1] = "GDT"; /* string for daylight saving */
-long _timezone = 0;
-long _dst_off = 60 * 60;
-int _daylight = 0;
-char *_tzname[2] = {ntstr, dststr};
+long _timezone = 0;
+long _dst_off = 60 * 60;
+int _daylight = 0;
+char* _tzname[2] = { ntstr, dststr };
-#if defined(__USG) || defined(_POSIX_SOURCE)
-char *tzname[2] = {ntstr, dststr};
+#if defined(__USG) || defined(_POSIX_SOURCE)
+char* tzname[2] = { ntstr, dststr };
-#if defined(__USG)
-long timezone = 0;
-int daylight = 0;
+#if defined(__USG)
+long timezone = 0;
+int daylight = 0;
#endif
#endif
-static struct dsttype {
- char ds_type; /* Unknown, Julian, Zero-based or M */
- int ds_date[3]; /* months, weeks, days */
- long ds_sec; /* usually 02:00:00 */
-} dststart = { 'U', { 0, 0, 0 }, 2 * 60 * 60 }
- , dstend = { 'U', { 0, 0, 0 }, 2 * 60 * 60 };
-
-const char *_days[] = {
- "Sunday", "Monday", "Tuesday", "Wednesday",
- "Thursday", "Friday", "Saturday"
- };
-
-const char *_months[] = {
- "January", "February", "March",
- "April", "May", "June",
- "July", "August", "September",
- "October", "November", "December"
- };
+static struct dsttype
+{
+ char ds_type; /* Unknown, Julian, Zero-based or M */
+ int ds_date[3]; /* months, weeks, days */
+ long ds_sec; /* usually 02:00:00 */
+} dststart = { 'U', { 0, 0, 0 }, 2 * 60 * 60 }, dstend = { 'U', { 0, 0, 0 }, 2 * 60 * 60 };
+
+const char* _days[] = {
+ "Sunday", "Monday", "Tuesday", "Wednesday",
+ "Thursday", "Friday", "Saturday"
+};
+
+const char* _months[] = {
+ "January", "February", "March",
+ "April", "May", "June",
+ "July", "August", "September",
+ "October", "November", "December"
+};
const int _ytab[2][12] = {
- { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
- { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
- };
+ { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
+ { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
+};
-#if !defined(_POSIX_SOURCE) && !defined(__USG)
-#define USE_TABLE 1
+#if !defined(_POSIX_SOURCE) && !defined(__USG)
+#define USE_TABLE 1
#endif
-#if USE_TABLE
+#if USE_TABLE
static int usetable = 1;
-typedef struct table {
- const char *tz_name;
+typedef struct table
+{
+ const char* tz_name;
const int daylight;
const long zoneoffset;
} TABLE;
-#define HOUR(x) ((x) * 60*60)
+#define HOUR(x) ((x)*60 * 60)
static TABLE TimezoneTable[] = {
- {"GMT", 0, HOUR(0) }, /* Greenwich Mean */
- {"BST", 60*60, HOUR(0) }, /* British Summer */
- {"WAT", 0, HOUR(1) }, /* West Africa */
- {"AT", 0, HOUR(2) }, /* Azores */
- {"BST", 0, HOUR(3) }, /* Brazil Standard */
- {"NFT", 0, HOUR(3.5) }, /* Newfoundland */
- {"NDT", 60*60, HOUR(3.5) }, /* Newfoundland Daylight */
- {"AST", 0, HOUR(4) }, /* Atlantic Standard */
- {"ADT", 60*60, HOUR(4) }, /* Atlantic Daylight */
- {"EST", 0, HOUR(5) }, /* Eastern Standard */
- {"EDT", 60*60, HOUR(5) }, /* Eastern Daylight */
- {"CST", 0, HOUR(6) }, /* Central Standard */
- {"CDT", 60*60, HOUR(6) }, /* Central Daylight */
- {"MST", 0, HOUR(7) }, /* Mountain Standard */
- {"MDT", 60*60, HOUR(7) }, /* Mountain Daylight */
- {"PST", 0, HOUR(8) }, /* Pacific Standard */
- {"PDT", 60*60, HOUR(8) }, /* Pacific Daylight */
- {"YST", 0, HOUR(9) }, /* Yukon Standard */
- {"YDT", 60*60, HOUR(9) }, /* Yukon Daylight */
- {"HST", 0, HOUR(10) }, /* Hawaii Standard */
- {"HDT", 60*60, HOUR(10) }, /* Hawaii Daylight */
- {"NT", 0, HOUR(11) }, /* Nome */
- {"IDLW", 0, HOUR(12) }, /* International Date Line West */
- {"MET", 0, -HOUR(1) }, /* Middle European */
- {"MDT", 60*60, -HOUR(1) }, /* Middle European Summer */
- {"EET", 0, -HOUR(2) }, /* Eastern Europe, USSR Zone 1 */
- {"BT", 0, -HOUR(3) }, /* Baghdad, USSR Zone 2 */
- {"IT", 0, -HOUR(3.5) }, /* Iran */
- {"ZP4", 0, -HOUR(4) }, /* USSR Zone 3 */
- {"ZP5", 0, -HOUR(5) }, /* USSR Zone 4 */
- {"IST", 0, -HOUR(5.5) }, /* Indian Standard */
- {"ZP6", 0, -HOUR(6) }, /* USSR Zone 5 */
- {"NST", 0, -HOUR(6.5) }, /* North Sumatra */
- {"SST", 0, -HOUR(7) }, /* South Sumatra, USSR Zone 6 */
- {"WAST", 0, -HOUR(7) }, /* West Australian Standard */
- {"WADT", 60*60, -HOUR(7) }, /* West Australian Daylight */
- {"JT", 0, -HOUR(7.5) }, /* Java (3pm in Cronusland!) */
- {"CCT", 0, -HOUR(8) }, /* China Coast, USSR Zone 7 */
- {"JST", 0, -HOUR(9) }, /* Japan Standard, USSR Zone 8 */
- {"CAST", 0, -HOUR(9.5) }, /* Central Australian Standard */
- {"CADT", 60*60, -HOUR(9.5) }, /* Central Australian Daylight */
- {"EAST", 0, -HOUR(10) }, /* Eastern Australian Standard */
- {"EADT", 60*60, -HOUR(10) }, /* Eastern Australian Daylight */
- {"NZT", 0, -HOUR(12) }, /* New Zealand */
- {"NZDT", 60*60, -HOUR(12) }, /* New Zealand Daylight */
- { NULL, 0, 0 }
+ { "GMT", 0, HOUR(0) }, /* Greenwich Mean */
+ { "BST", 60 * 60, HOUR(0) }, /* British Summer */
+ { "WAT", 0, HOUR(1) }, /* West Africa */
+ { "AT", 0, HOUR(2) }, /* Azores */
+ { "BST", 0, HOUR(3) }, /* Brazil Standard */
+ { "NFT", 0, HOUR(3.5) }, /* Newfoundland */
+ { "NDT", 60 * 60, HOUR(3.5) }, /* Newfoundland Daylight */
+ { "AST", 0, HOUR(4) }, /* Atlantic Standard */
+ { "ADT", 60 * 60, HOUR(4) }, /* Atlantic Daylight */
+ { "EST", 0, HOUR(5) }, /* Eastern Standard */
+ { "EDT", 60 * 60, HOUR(5) }, /* Eastern Daylight */
+ { "CST", 0, HOUR(6) }, /* Central Standard */
+ { "CDT", 60 * 60, HOUR(6) }, /* Central Daylight */
+ { "MST", 0, HOUR(7) }, /* Mountain Standard */
+ { "MDT", 60 * 60, HOUR(7) }, /* Mountain Daylight */
+ { "PST", 0, HOUR(8) }, /* Pacific Standard */
+ { "PDT", 60 * 60, HOUR(8) }, /* Pacific Daylight */
+ { "YST", 0, HOUR(9) }, /* Yukon Standard */
+ { "YDT", 60 * 60, HOUR(9) }, /* Yukon Daylight */
+ { "HST", 0, HOUR(10) }, /* Hawaii Standard */
+ { "HDT", 60 * 60, HOUR(10) }, /* Hawaii Daylight */
+ { "NT", 0, HOUR(11) }, /* Nome */
+ { "IDLW", 0, HOUR(12) }, /* International Date Line West */
+ { "MET", 0, -HOUR(1) }, /* Middle European */
+ { "MDT", 60 * 60, -HOUR(1) }, /* Middle European Summer */
+ { "EET", 0, -HOUR(2) }, /* Eastern Europe, USSR Zone 1 */
+ { "BT", 0, -HOUR(3) }, /* Baghdad, USSR Zone 2 */
+ { "IT", 0, -HOUR(3.5) }, /* Iran */
+ { "ZP4", 0, -HOUR(4) }, /* USSR Zone 3 */
+ { "ZP5", 0, -HOUR(5) }, /* USSR Zone 4 */
+ { "IST", 0, -HOUR(5.5) }, /* Indian Standard */
+ { "ZP6", 0, -HOUR(6) }, /* USSR Zone 5 */
+ { "NST", 0, -HOUR(6.5) }, /* North Sumatra */
+ { "SST", 0, -HOUR(7) }, /* South Sumatra, USSR Zone 6 */
+ { "WAST", 0, -HOUR(7) }, /* West Australian Standard */
+ { "WADT", 60 * 60, -HOUR(7) }, /* West Australian Daylight */
+ { "JT", 0, -HOUR(7.5) }, /* Java (3pm in Cronusland!) */
+ { "CCT", 0, -HOUR(8) }, /* China Coast, USSR Zone 7 */
+ { "JST", 0, -HOUR(9) }, /* Japan Standard, USSR Zone 8 */
+ { "CAST", 0, -HOUR(9.5) }, /* Central Australian Standard */
+ { "CADT", 60 * 60, -HOUR(9.5) }, /* Central Australian Daylight */
+ { "EAST", 0, -HOUR(10) }, /* Eastern Australian Standard */
+ { "EADT", 60 * 60, -HOUR(10) }, /* Eastern Australian Daylight */
+ { "NZT", 0, -HOUR(12) }, /* New Zealand */
+ { "NZDT", 60 * 60, -HOUR(12) }, /* New Zealand Daylight */
+ { NULL, 0, 0 }
};
/*
static void
ZoneFromTable(long timezone)
{
- register TABLE *tptr = TimezoneTable;
-
- while (tptr->tz_name != NULL) {
- if (tptr->zoneoffset == timezone) {
- if (tptr->daylight == 0) {
- strncpy(ntstr,tptr->tz_name, TZ_LEN);
+ register TABLE* tptr = TimezoneTable;
+
+ while (tptr->tz_name != NULL)
+ {
+ if (tptr->zoneoffset == timezone)
+ {
+ if (tptr->daylight == 0)
+ {
+ strncpy(ntstr, tptr->tz_name, TZ_LEN);
ntstr[TZ_LEN] = '\0';
- } else {
- strncpy(dststr,tptr->tz_name, TZ_LEN);
+ }
+ else
+ {
+ strncpy(dststr, tptr->tz_name, TZ_LEN);
dststr[TZ_LEN] = '\0';
}
}
tptr++;
}
}
-#endif /* USE_TABLE */
+#endif /* USE_TABLE */
-static const char *
-parseZoneName(register char *buf, register const char *p)
+static const char*
+parseZoneName(register char* buf, register const char* p)
{
register int n = 0;
- if (*p == ':') return NULL;
- while (*p && !isdigit(*p) && *p != ',' && *p != '-' && *p != '+') {
+ if (*p == ':')
+ return NULL;
+ while (*p && !isdigit(*p) && *p != ',' && *p != '-' && *p != '+')
+ {
if (n < TZ_LEN)
*buf++ = *p;
p++;
n++;
}
- if (n < 3) return NULL; /* error */
+ if (n < 3)
+ return NULL; /* error */
*buf = '\0';
return p;
}
-static const char *
-parseTime(register long *tm, const char *p, register struct dsttype *dst)
+static const char*
+parseTime(register long* tm, const char* p, register struct dsttype* dst)
{
register int n = 0;
- register const char *q = p;
+ register const char* q = p;
char ds_type = (dst ? dst->ds_type : '\0');
- if (dst) dst->ds_type = 'U';
+ if (dst)
+ dst->ds_type = 'U';
*tm = 0;
- while(*p >= '0' && *p <= '9') {
+ while (*p >= '0' && *p <= '9')
+ {
n = 10 * n + (*p++ - '0');
}
- if (q == p) return NULL; /* "The hour shall be required" */
- if (n < 0 || n >= 24) return NULL;
+ if (q == p)
+ return NULL; /* "The hour shall be required" */
+ if (n < 0 || n >= 24)
+ return NULL;
*tm = n * 60 * 60;
- if (*p == ':') {
+ if (*p == ':')
+ {
p++;
n = 0;
- while(*p >= '0' && *p <= '9') {
+ while (*p >= '0' && *p <= '9')
+ {
n = 10 * n + (*p++ - '0');
}
- if (q == p) return NULL; /* format error */
- if (n < 0 || n >= 60) return NULL;
+ if (q == p)
+ return NULL; /* format error */
+ if (n < 0 || n >= 60)
+ return NULL;
*tm += n * 60;
- if (*p == ':') {
+ if (*p == ':')
+ {
p++;
n = 0;
- while(*p >= '0' && *p <= '9') {
+ while (*p >= '0' && *p <= '9')
+ {
n = 10 * n + (*p++ - '0');
}
- if (q == p) return NULL; /* format error */
- if (n < 0 || n >= 60) return NULL;
+ if (q == p)
+ return NULL; /* format error */
+ if (n < 0 || n >= 60)
+ return NULL;
*tm += n;
}
}
- if (dst) {
+ if (dst)
+ {
dst->ds_type = ds_type;
dst->ds_sec = *tm;
}
return p;
}
-static const char *
-parseDate(register char *buf, register const char *p, struct dsttype *dstinfo)
+static const char*
+parseDate(register char* buf, register const char* p, struct dsttype* dstinfo)
{
- register const char *q;
+ register const char* q;
register int n = 0;
int cnt = 0;
- const int bnds[3][2] = { { 1, 12 },
- { 1, 5 },
- { 0, 6}
- };
+ const int bnds[3][2] = { { 1, 12 },
+ { 1, 5 },
+ { 0, 6 } };
char ds_type;
- if (*p != 'M') {
- if (*p == 'J') {
+ if (*p != 'M')
+ {
+ if (*p == 'J')
+ {
*buf++ = *p++;
ds_type = 'J';
}
- else ds_type = 'Z';
+ else
+ ds_type = 'Z';
q = p;
- while(*p >= '0' && *p <= '9') {
+ while (*p >= '0' && *p <= '9')
+ {
n = 10 * n + (*p - '0');
*buf++ = *p++;
}
- if (q == p) return NULL; /* format error */
- if (n < (ds_type == 'J') || n > 365) return NULL;
+ if (q == p)
+ return NULL; /* format error */
+ if (n < (ds_type == 'J') || n > 365)
+ return NULL;
dstinfo->ds_type = ds_type;
dstinfo->ds_date[0] = n;
return p;
}
ds_type = 'M';
- do {
+ do
+ {
*buf++ = *p++;
q = p;
n = 0;
- while(*p >= '0' && *p <= '9') {
+ while (*p >= '0' && *p <= '9')
+ {
n = 10 * n + (*p - '0');
*buf++ = *p++;
}
- if (q == p) return NULL; /* format error */
- if (n < bnds[cnt][0] || n > bnds[cnt][1]) return NULL;
+ if (q == p)
+ return NULL; /* format error */
+ if (n < bnds[cnt][0] || n > bnds[cnt][1])
+ return NULL;
dstinfo->ds_date[cnt] = n;
cnt++;
} while (cnt < 3 && *p == '.');
- if (cnt != 3) return NULL;
+ if (cnt != 3)
+ return NULL;
*buf = '\0';
dstinfo->ds_type = ds_type;
return p;
}
-static const char *
-parseRule(register char *buf, register const char *p)
+static const char*
+parseRule(register char* buf, register const char* p)
{
long tim;
- register const char *q;
+ register const char* q;
- if (!(p = parseDate(buf, p, &dststart))) return NULL;
+ if (!(p = parseDate(buf, p, &dststart)))
+ return NULL;
buf += strlen(buf);
- if (*p == '/') {
+ if (*p == '/')
+ {
q = ++p;
- if (!(p = parseTime(&tim, p, &dststart))) return NULL;
- while( p != q) *buf++ = *q++;
+ if (!(p = parseTime(&tim, p, &dststart)))
+ return NULL;
+ while (p != q)
+ *buf++ = *q++;
}
- if (*p != ',') return NULL;
+ if (*p != ',')
+ return NULL;
p++;
- if (!(p = parseDate(buf, p, &dstend))) return NULL;
+ if (!(p = parseDate(buf, p, &dstend)))
+ return NULL;
buf += strlen(buf);
- if (*p == '/') {
+ if (*p == '/')
+ {
q = ++p;
- if (!(p = parseTime(&tim, p, &dstend))) return NULL;
- while(*buf++ = *q++);
+ if (!(p = parseTime(&tim, p, &dstend)))
+ return NULL;
+ while (*buf++ = *q++)
+ ;
}
- if (*p) return NULL;
+ if (*p)
+ return NULL;
return p;
}
* The function returns as soon as it spots an error.
*/
static void
-parseTZ(const char *p)
+parseTZ(const char* p)
{
long tz, dst = 60 * 60, sign = 1;
static char lastTZ[2 * RULE_LEN];
static char buffer[RULE_LEN];
- if (!p) return;
+ if (!p)
+ return;
-#if USE_TABLE
+#if USE_TABLE
usetable = 0;
#endif
- if (*p == ':') {
+ if (*p == ':')
+ {
/*
* According to POSIX, this is implementation defined.
* Since it depends on the particular operating system, we
return;
}
- if (!strcmp(lastTZ, p)) return; /* nothing changed */
+ if (!strcmp(lastTZ, p))
+ return; /* nothing changed */
*_tzname[0] = '\0';
*_tzname[1] = '\0';
dstend.ds_type = 'U';
dstend.ds_sec = 2 * 60 * 60;
- if (strlen(p) > 2 * RULE_LEN) return;
+ if (strlen(p) > 2 * RULE_LEN)
+ return;
strcpy(lastTZ, p);
- if (!(p = parseZoneName(buffer, p))) return;
+ if (!(p = parseZoneName(buffer, p)))
+ return;
- if (*p == '-') {
+ if (*p == '-')
+ {
sign = -1;
p++;
- } else if (*p == '+') p++;
+ }
+ else if (*p == '+')
+ p++;
- if (!(p = parseTime(&tz, p, NULL))) return;
+ if (!(p = parseTime(&tz, p, NULL)))
+ return;
tz *= sign;
_timezone = tz;
strncpy(_tzname[0], buffer, TZ_LEN);
- if (!(_daylight = (*p != '\0'))) return;
+ if (!(_daylight = (*p != '\0')))
+ return;
buffer[0] = '\0';
- if (!(p = parseZoneName(buffer, p))) return;
+ if (!(p = parseZoneName(buffer, p)))
+ return;
strncpy(_tzname[1], buffer, TZ_LEN);
buffer[0] = '\0';
if (*p && (*p != ','))
- if (!(p = parseTime(&dst, p, NULL))) return;
- _dst_off = dst; /* dst was initialized to 1 hour */
- if (*p) {
- if (*p != ',') return;
+ if (!(p = parseTime(&dst, p, NULL)))
+ return;
+ _dst_off = dst; /* dst was initialized to 1 hour */
+ if (*p)
+ {
+ if (*p != ',')
+ return;
p++;
- if (strlen(p) > RULE_LEN) return;
- if (!(p = parseRule(buffer, p))) return;
+ if (strlen(p) > RULE_LEN)
+ return;
+ if (!(p = parseRule(buffer, p)))
+ return;
}
}
-void
-_tzset(void)
+void _tzset(void)
{
-#if defined(__BSD4_2)
+#if defined(__BSD4_2)
struct timeval tv;
struct timezone tz;
_daylight = tz.tz_dsttime;
_timezone = tz.tz_minuteswest * 60L;
-#elif !defined(_POSIX_SOURCE) && !defined(__USG)
+#elif !defined(_POSIX_SOURCE) && !defined(__USG)
-#if !defined(_MINIX) /* MINIX has no ftime() */
+#if !defined(_MINIX) /* MINIX has no ftime() */
struct timeb tim;
_ftime(&tim);
_daylight = tim.dstflag;
#endif
-#endif /* !_POSIX_SOURCE && !__USG */
+#endif /* !_POSIX_SOURCE && !__USG */
- parseTZ(getenv("TZ")); /* should go inside #if */
+ parseTZ(getenv("TZ")); /* should go inside #if */
-#if defined(__USG) || defined(_POSIX_SOURCE)
+#if defined(__USG) || defined(_POSIX_SOURCE)
tzname[0] = _tzname[0];
tzname[1] = _tzname[1];
-#if defined(__USG)
+#if defined(__USG)
timezone = _timezone;
daylight = _daylight;
#endif
-#endif /* __USG || _POSIX_SOURCE */
+#endif /* __USG || _POSIX_SOURCE */
}
static int
-last_sunday(register int day, register struct tm *timep)
+last_sunday(register int day, register struct tm* timep)
{
int first = FIRSTSUNDAY(timep);
- if (day >= 58 && LEAPYEAR(YEAR0 + timep->tm_year)) day++;
- if (day < first) return first;
+ if (day >= 58 && LEAPYEAR(YEAR0 + timep->tm_year))
+ day++;
+ if (day < first)
+ return first;
return day - (day - first) % 7;
}
static int
-date_of(register struct dsttype *dst, struct tm *timep)
+date_of(register struct dsttype* dst, struct tm* timep)
{
int leap = LEAPYEAR(YEAR0 + timep->tm_year);
int firstday, tmpday;
register int day, month;
- if (dst->ds_type != 'M') {
- return dst->ds_date[0] -
- (dst->ds_type == 'J'
- && leap
- && dst->ds_date[0] < 58);
+ if (dst->ds_type != 'M')
+ {
+ return dst->ds_date[0] - (dst->ds_type == 'J'
+ && leap
+ && dst->ds_date[0] < 58);
}
day = 0;
month = 1;
- while (month < dst->ds_date[0]) {
+ while (month < dst->ds_date[0])
+ {
day += _ytab[leap][month - 1];
month++;
}
firstday = (day + FIRSTDAYOF(timep)) % 7;
tmpday = day;
day += (dst->ds_date[2] - firstday + 7) % 7
- + 7 * (dst->ds_date[1] - 1);
- if (day >= tmpday + _ytab[leap][month]) day -= 7;
+ + 7 * (dst->ds_date[1] - 1);
+ if (day >= tmpday + _ytab[leap][month])
+ day -= 7;
return day;
}
* Britain).
*/
unsigned
-_dstget(register struct tm *timep)
+_dstget(register struct tm* timep)
{
int begindst, enddst;
register struct dsttype *dsts = &dststart, *dste = &dstend;
_tzset();
timep->tm_isdst = _daylight;
- if (!_daylight) return 0;
+ if (!_daylight)
+ return 0;
if (dsts->ds_type != 'U')
begindst = date_of(dsts, timep);
- else begindst = last_sunday(89, timep); /* last Sun before Apr */
+ else
+ begindst = last_sunday(89, timep); /* last Sun before Apr */
if (dste->ds_type != 'U')
enddst = date_of(dste, timep);
- else enddst = last_sunday(272, timep); /* last Sun in Sep */
+ else
+ enddst = last_sunday(272, timep); /* last Sun in Sep */
/* assume begindst != enddst (otherwise it would be no use) */
- if (begindst < enddst) { /* northern hemisphere */
+ if (begindst < enddst)
+ { /* northern hemisphere */
if (timep->tm_yday > begindst && timep->tm_yday < enddst)
do_dst = 1;
- } else { /* southern hemisphere */
+ }
+ else
+ { /* southern hemisphere */
if (timep->tm_yday > begindst || timep->tm_yday < enddst)
do_dst = 1;
}
if (!do_dst
- && (timep->tm_yday == begindst || timep->tm_yday == enddst)) {
- long dsttranssec; /* transition when day is this old */
+ && (timep->tm_yday == begindst || timep->tm_yday == enddst))
+ {
+ long dsttranssec; /* transition when day is this old */
long cursec;
if (timep->tm_yday == begindst)
dsttranssec = dsts->ds_sec;
- else dsttranssec = dste->ds_sec;
+ else
+ dsttranssec = dste->ds_sec;
cursec = ((timep->tm_hour * 60) + timep->tm_min) * 60L
- + timep->tm_sec;
+ + timep->tm_sec;
if ((timep->tm_yday == begindst && cursec >= dsttranssec)
|| (timep->tm_yday == enddst && cursec < dsttranssec))
do_dst = 1;
}
#if USE_TABLE
- if (usetable) ZoneFromTable(_timezone);
+ if (usetable)
+ ZoneFromTable(_timezone);
#endif
- if (do_dst) return _dst_off;
+ if (do_dst)
+ return _dst_off;
timep->tm_isdst = 0;
return 0;
}
*/
/* $Id$ */
-#include <time.h>
-#include <limits.h>
-#include "loc_time.h"
+#include <time.h>
+#include <limits.h>
+#include "loc_time.h"
/* The code assumes that unsigned long can be converted to time_t.
* A time_t should not be wider than unsigned long, since this would mean
* that the check for overflow at the end could fail.
*/
time_t
-mktime(register struct tm *timep)
+mktime(register struct tm* timep)
{
register long day, year;
register int tm_year;
timep->tm_min += timep->tm_sec / 60;
timep->tm_sec %= 60;
- if (timep->tm_sec < 0) {
+ if (timep->tm_sec < 0)
+ {
timep->tm_sec += 60;
timep->tm_min--;
}
timep->tm_hour += timep->tm_min / 60;
timep->tm_min = timep->tm_min % 60;
- if (timep->tm_min < 0) {
+ if (timep->tm_min < 0)
+ {
timep->tm_min += 60;
timep->tm_hour--;
}
day = timep->tm_hour / 24;
- timep->tm_hour= timep->tm_hour % 24;
- if (timep->tm_hour < 0) {
+ timep->tm_hour = timep->tm_hour % 24;
+ if (timep->tm_hour < 0)
+ {
timep->tm_hour += 24;
day--;
}
timep->tm_year += timep->tm_mon / 12;
timep->tm_mon %= 12;
- if (timep->tm_mon < 0) {
+ if (timep->tm_mon < 0)
+ {
timep->tm_mon += 12;
timep->tm_year--;
}
day += (timep->tm_mday - 1);
- while (day < 0) {
+ while (day < 0)
+ {
day += YEARSIZE(YEAR0 + timep->tm_year - 1);
timep->tm_year--;
}
- while (day >= YEARSIZE(YEAR0 + timep->tm_year)) {
+ while (day >= YEARSIZE(YEAR0 + timep->tm_year))
+ {
day -= YEARSIZE(YEAR0 + timep->tm_year);
timep->tm_year++;
}
- while (day >= _ytab[LEAPYEAR(YEAR0 + timep->tm_year)][timep->tm_mon]) {
+ while (day >= _ytab[LEAPYEAR(YEAR0 + timep->tm_year)][timep->tm_mon])
+ {
day -= _ytab[LEAPYEAR(YEAR0 + timep->tm_year)][timep->tm_mon];
- if (++(timep->tm_mon) == 12) {
+ if (++(timep->tm_mon) == 12)
+ {
timep->tm_mon = 0;
timep->tm_year++;
}
}
timep->tm_mday = day + 1;
- _tzset(); /* set timezone and dst info */
+ _tzset(); /* set timezone and dst info */
year = EPOCH_YR;
- if (timep->tm_year < year - YEAR0) return (time_t)-1;
+ if (timep->tm_year < year - YEAR0)
+ return (time_t)-1;
seconds = 0;
- day = 0; /* means days since day 0 now */
+ day = 0; /* means days since day 0 now */
overflow = 0;
- /* Assume that when day becomes negative, there will certainly
+/* Assume that when day becomes negative, there will certainly
* be overflow on seconds.
* The check for overflow needs not to be done for leapyears
* divisible by 400.
* The code only works when year (1970) is not a leapyear.
*/
-#if EPOCH_YR != 1970
-#error EPOCH_YR != 1970
+#if EPOCH_YR != 1970
+#error EPOCH_YR != 1970
#endif
tm_year = timep->tm_year + YEAR0;
- if (LONG_MAX / 365 < tm_year - year) overflow++;
+ if (LONG_MAX / 365 < tm_year - year)
+ overflow++;
day = (tm_year - year) * 365;
- if (LONG_MAX - day < (tm_year - year) / 4 + 1) overflow++;
+ if (LONG_MAX - day < (tm_year - year) / 4 + 1)
+ overflow++;
day += (tm_year - year) / 4
- + ((tm_year % 4) && tm_year % 4 < year % 4);
+ + ((tm_year % 4) && tm_year % 4 < year % 4);
day -= (tm_year - year) / 100
- + ((tm_year % 100) && tm_year % 100 < year % 100);
+ + ((tm_year % 100) && tm_year % 100 < year % 100);
day += (tm_year - year) / 400
- + ((tm_year % 400) && tm_year % 400 < year % 400);
+ + ((tm_year % 400) && tm_year % 400 < year % 400);
yday = month = 0;
- while (month < timep->tm_mon) {
+ while (month < timep->tm_mon)
+ {
yday += _ytab[LEAPYEAR(tm_year)][month];
month++;
}
yday += (timep->tm_mday - 1);
- if (day + yday < 0) overflow++;
+ if (day + yday < 0)
+ overflow++;
day += yday;
timep->tm_yday = yday;
- timep->tm_wday = (day + 4) % 7; /* day 0 was thursday (4) */
+ timep->tm_wday = (day + 4) % 7; /* day 0 was thursday (4) */
seconds = ((timep->tm_hour * 60L) + timep->tm_min) * 60L + timep->tm_sec;
- if ((TIME_MAX - seconds) / SECS_DAY < day) overflow++;
+ if ((TIME_MAX - seconds) / SECS_DAY < day)
+ overflow++;
seconds += day * SECS_DAY;
/* Now adjust according to timezone and daylight saving time */
dst = _dstget(timep);
else if (timep->tm_isdst)
dst = _dst_off;
- else dst = 0;
+ else
+ dst = 0;
- if (dst > seconds) overflow++; /* dst is always non-negative */
+ if (dst > seconds)
+ overflow++; /* dst is always non-negative */
seconds -= dst;
- if (overflow) return (time_t)-1;
+ if (overflow)
+ return (time_t)-1;
- if ((time_t)seconds != seconds) return (time_t)-1;
+ if ((time_t)seconds != seconds)
+ return (time_t)-1;
return (time_t)seconds;
}
*/
/* $Id$ */
-#include <time.h>
-#include "loc_time.h"
+#include <time.h>
+#include "loc_time.h"
/* The width can be -1 in both s_prnt() as in u_prnt(). This
* indicates that as many characters as needed should be printed.
*/
-static char *
-s_prnt(char *s, size_t maxsize, const char *str, int width)
+static char*
+s_prnt(char* s, size_t maxsize, const char* str, int width)
{
- while (width > 0 || (width < 0 && *str)) {
- if (!maxsize) break;
+ while (width > 0 || (width < 0 && *str))
+ {
+ if (!maxsize)
+ break;
*s++ = *str++;
maxsize--;
width--;
return s;
}
-static char *
-u_prnt(char *s, size_t maxsize, unsigned val, int width)
+static char*
+u_prnt(char* s, size_t maxsize, unsigned val, int width)
{
int c;
val = val / 10;
if (--width > 0 || (width < 0 && val != 0))
s = u_prnt(s, (maxsize ? maxsize - 1 : 0), val, width);
- if (maxsize) *s++ = c + '0';
+ if (maxsize)
+ *s++ = c + '0';
return s;
}
size_t
-strftime(char *s, size_t maxsize,
- const char *format, const struct tm *timeptr)
+strftime(char* s, size_t maxsize,
+ const char* format, const struct tm* timeptr)
{
size_t n;
char *firsts, *olds;
- if (!format) return 0;
+ if (!format)
+ return 0;
- _tzset(); /* for %Z conversion */
+ _tzset(); /* for %Z conversion */
firsts = s;
- while (maxsize && *format) {
- while (maxsize && *format && *format != '%') {
+ while (maxsize && *format)
+ {
+ while (maxsize && *format && *format != '%')
+ {
*s++ = *format++;
maxsize--;
}
- if (!maxsize || !*format) break;
+ if (!maxsize || !*format)
+ break;
format++;
olds = s;
- switch (*format++) {
- case 'a':
- s = s_prnt(s, maxsize,
- _days[timeptr->tm_wday], ABB_LEN);
- maxsize -= s - olds;
- break;
- case 'A':
- s = s_prnt(s, maxsize, _days[timeptr->tm_wday], -1);
- maxsize -= s - olds;
- break;
- case 'b':
- s = s_prnt(s, maxsize,
- _months[timeptr->tm_mon], ABB_LEN);
- maxsize -= s - olds;
- break;
- case 'B':
- s = s_prnt(s, maxsize, _months[timeptr->tm_mon], -1);
- maxsize -= s - olds;
- break;
- case 'c':
- n = strftime(s, maxsize,
- "%a %b %d %H:%M:%S %Y", timeptr);
- if (n) maxsize -= n;
- else maxsize = 0;
- s += n;
- break;
- case 'd':
- s = u_prnt(s, maxsize, timeptr->tm_mday, 2);
- maxsize -= s - olds;
- break;
- case 'H':
- s = u_prnt(s, maxsize, timeptr->tm_hour, 2);
- maxsize -= s - olds;
- break;
- case 'I':
- s = u_prnt(s, maxsize,
- (timeptr->tm_hour + 11) % 12 + 1, 2);
- maxsize -= s - olds;
- break;
- case 'j':
- s = u_prnt(s, maxsize, timeptr->tm_yday + 1, 3);
- maxsize -= s - olds;
- break;
- case 'm':
- s = u_prnt(s, maxsize, timeptr->tm_mon + 1, 2);
- maxsize -= s - olds;
- break;
- case 'M':
- s = u_prnt(s, maxsize, timeptr->tm_min, 2);
- maxsize -= s - olds;
- break;
- case 'p':
- s = s_prnt(s, maxsize,
+ switch (*format++)
+ {
+ case 'a':
+ s = s_prnt(s, maxsize,
+ _days[timeptr->tm_wday], ABB_LEN);
+ maxsize -= s - olds;
+ break;
+ case 'A':
+ s = s_prnt(s, maxsize, _days[timeptr->tm_wday], -1);
+ maxsize -= s - olds;
+ break;
+ case 'b':
+ s = s_prnt(s, maxsize,
+ _months[timeptr->tm_mon], ABB_LEN);
+ maxsize -= s - olds;
+ break;
+ case 'B':
+ s = s_prnt(s, maxsize, _months[timeptr->tm_mon], -1);
+ maxsize -= s - olds;
+ break;
+ case 'c':
+ n = strftime(s, maxsize,
+ "%a %b %d %H:%M:%S %Y", timeptr);
+ if (n)
+ maxsize -= n;
+ else
+ maxsize = 0;
+ s += n;
+ break;
+ case 'd':
+ s = u_prnt(s, maxsize, timeptr->tm_mday, 2);
+ maxsize -= s - olds;
+ break;
+ case 'H':
+ s = u_prnt(s, maxsize, timeptr->tm_hour, 2);
+ maxsize -= s - olds;
+ break;
+ case 'I':
+ s = u_prnt(s, maxsize,
+ (timeptr->tm_hour + 11) % 12 + 1, 2);
+ maxsize -= s - olds;
+ break;
+ case 'j':
+ s = u_prnt(s, maxsize, timeptr->tm_yday + 1, 3);
+ maxsize -= s - olds;
+ break;
+ case 'm':
+ s = u_prnt(s, maxsize, timeptr->tm_mon + 1, 2);
+ maxsize -= s - olds;
+ break;
+ case 'M':
+ s = u_prnt(s, maxsize, timeptr->tm_min, 2);
+ maxsize -= s - olds;
+ break;
+ case 'p':
+ s = s_prnt(s, maxsize,
(timeptr->tm_hour < 12) ? "AM" : "PM", 2);
- maxsize -= s - olds;
- break;
- case 'S':
- s = u_prnt(s, maxsize, timeptr->tm_sec, 2);
- maxsize -= s - olds;
- break;
- case 'U':
- s = u_prnt(s, maxsize, /* ??? */
- (timeptr->tm_yday + 7 - timeptr->tm_wday) / 7, 2);
- maxsize -= s - olds;
- break;
- case 'w':
- s = u_prnt(s, maxsize, timeptr->tm_wday, 1);
- maxsize -= s - olds;
- break;
- case 'W':
- s = u_prnt(s, maxsize, /* ??? */
- (timeptr->tm_yday+7-(timeptr->tm_wday+6)%7)/7,2);
- maxsize -= s - olds;
- break;
- case 'x':
- n = strftime(s, maxsize, "%a %b %d %Y", timeptr);
- if (n) maxsize -= n;
- else maxsize = 0;
- s += n;
- break;
- case 'X':
- n = strftime(s, maxsize, "%H:%M:%S", timeptr);
- if (n) maxsize -= n;
- else maxsize = 0;
- s += n;
- break;
- case 'y':
- s = u_prnt(s, maxsize, timeptr->tm_year % 100, 2);
- maxsize -= s - olds;
- break;
- case 'Y':
- s = u_prnt(s, maxsize, timeptr->tm_year + YEAR0, -1);
- maxsize -= s - olds;
- break;
- case 'Z':
- s = s_prnt(s, maxsize,
- _tzname[(timeptr->tm_isdst > 0)], -1);
- maxsize -= s - olds;
- break;
- case '%':
- *s++ = '%';
- maxsize--;
- break;
- default:
- /* A conversion error. Leave the loop. */
- while (*format) format++;
- break;
+ maxsize -= s - olds;
+ break;
+ case 'S':
+ s = u_prnt(s, maxsize, timeptr->tm_sec, 2);
+ maxsize -= s - olds;
+ break;
+ case 'U':
+ s = u_prnt(s, maxsize, /* ??? */
+ (timeptr->tm_yday + 7 - timeptr->tm_wday) / 7, 2);
+ maxsize -= s - olds;
+ break;
+ case 'w':
+ s = u_prnt(s, maxsize, timeptr->tm_wday, 1);
+ maxsize -= s - olds;
+ break;
+ case 'W':
+ s = u_prnt(s, maxsize, /* ??? */
+ (timeptr->tm_yday + 7 - (timeptr->tm_wday + 6) % 7) / 7, 2);
+ maxsize -= s - olds;
+ break;
+ case 'x':
+ n = strftime(s, maxsize, "%a %b %d %Y", timeptr);
+ if (n)
+ maxsize -= n;
+ else
+ maxsize = 0;
+ s += n;
+ break;
+ case 'X':
+ n = strftime(s, maxsize, "%H:%M:%S", timeptr);
+ if (n)
+ maxsize -= n;
+ else
+ maxsize = 0;
+ s += n;
+ break;
+ case 'y':
+ s = u_prnt(s, maxsize, timeptr->tm_year % 100, 2);
+ maxsize -= s - olds;
+ break;
+ case 'Y':
+ s = u_prnt(s, maxsize, timeptr->tm_year + YEAR0, -1);
+ maxsize -= s - olds;
+ break;
+ case 'Z':
+ s = s_prnt(s, maxsize,
+ _tzname[(timeptr->tm_isdst > 0)], -1);
+ maxsize -= s - olds;
+ break;
+ case '%':
+ *s++ = '%';
+ maxsize--;
+ break;
+ default:
+ /* A conversion error. Leave the loop. */
+ while (*format)
+ format++;
+ break;
}
-
}
- if (maxsize) {
+ if (maxsize)
+ {
*s = '\0';
return s - firsts;
}
- return 0; /* The buffer is full */
+ return 0; /* The buffer is full */
}
#ifndef ACKCONF_TIME_IS_A_SYSCALL
time_t
-time(time_t *timer)
+time(time_t* timer)
{
struct timeval tv;
struct timezone tz;
gettimeofday(&tv, &tz);
- if (timer) *timer = tv.tv_sec;
+ if (timer)
+ *timer = tv.tv_sec;
return tv.tv_sec;
}
/* This function is present for System V && POSIX */
-#include <time.h>
-#include "loc_time.h"
+#include <time.h>
+#include "loc_time.h"
-void
-tzset(void)
+void tzset(void)
{
- _tzset(); /* does the job */
+ _tzset(); /* does the job */
}