Run libcc.ansi through clang-format.

This commit is contained in:
David Given 2018-06-21 22:33:47 +02:00
parent 60b7d8de6e
commit 93f39e4bbf
157 changed files with 3836 additions and 3121 deletions

View file

@ -7,7 +7,8 @@
#include <stdio.h>
#include <stdlib.h>
void __bad_assertion(const char *mess) {
void __bad_assertion(const char* mess)
{
fputs(mess, stderr);
abort();

View file

@ -1,5 +1,6 @@
#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;
}

View file

@ -1,5 +1,6 @@
#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;
}

View file

@ -6,7 +6,7 @@
#include <errno.h>
const char *_sys_errlist[] = {
const char* _sys_errlist[] = {
"Error 0",
"Not owner",
"No such file or directory",

View file

@ -8,10 +8,10 @@
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 = "";

View file

@ -8,21 +8,23 @@
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;
if (!locale)
return "C";
if (*locale && strcmp(locale, "C"))
return (char*)NULL;
switch(category) {
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";
return *locale ? (char*)locale : "C";
default:
return (char *)NULL;
return (char*)NULL;
}
}

View file

@ -3,7 +3,7 @@
#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. */
@ -57,7 +57,7 @@ void* malloc(size_t size)
* 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)
{
@ -67,7 +67,7 @@ void* malloc(size_t size)
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)
@ -84,7 +84,7 @@ void* malloc(size_t size)
}
}
void free(void *ptr)
void free(void* ptr)
{
block_t* h = BLOCKOF(ptr);
block_t* p;
@ -148,4 +148,3 @@ void free(void *ptr)
/* ...and update the ring pointer. */
__mem_freelist = p;
}

View file

@ -4,7 +4,7 @@
#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;

View file

@ -32,40 +32,50 @@ asin_acos(double x, int cosfl)
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;
}

View file

@ -43,30 +43,35 @@ atan(double x)
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;
}

View file

@ -15,26 +15,32 @@ 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;
}

View file

@ -13,7 +13,7 @@ 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
*/

View file

@ -11,7 +11,6 @@
#include <errno.h>
#include "localmath.h"
double
exp(double x)
{
@ -36,37 +35,42 @@ exp(double x)
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 */
xn = n;
{
double x1 = (long) x;
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));
}

View file

@ -13,7 +13,7 @@ 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
*/

View file

@ -6,29 +6,34 @@
#include <math.h>
#include <errno.h>
double
(fmod)(double x, double 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;
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| */
t = frexp(x, &xchar);
for (n = xchar - ychar; 0 <= n; --n) {
for (n = xchar - ychar; 0 <= n; --n)
{
/* try to substract |y|*2^n */
t = ldexp(y, n);
if (t <= x) x -= t;
if (t <= x)
x -= t;
}
return (neg ? -x : x);
}

View file

@ -10,25 +10,30 @@
/* $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

View file

@ -4,8 +4,8 @@ __IsNan(double d)
#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;
}

View file

@ -14,42 +14,52 @@ 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;
}

View file

@ -33,34 +33,42 @@ log(double x)
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;

View file

@ -13,15 +13,18 @@
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;
}

View file

@ -19,81 +19,103 @@ pow(double x, double y)
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);

View file

@ -33,27 +33,32 @@ sinus(double x, int cos_flag)
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.
*/
@ -63,8 +68,10 @@ sinus(double x, int cos_flag)
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;
@ -73,7 +80,8 @@ sinus(double x, int cos_flag)
#undef A2
}
if (x < 0) {
if (x < 0)
{
neg = -neg;
x = -x;
}
@ -82,7 +90,7 @@ sinus(double x, int cos_flag)
y = x * x;
x += x * y * POLYNOM7(y, r);
return neg==-1 ? -x : x;
return neg == -1 ? -x : x;
}
double
@ -94,6 +102,7 @@ sin(double x)
double
cos(double x)
{
if (x < 0) x = -x;
if (x < 0)
x = -x;
return sinus(x, 1);
}

View file

@ -34,35 +34,41 @@ sinh_cosh(double x, int cosh_flag)
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 */
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 (w < M_LN_MAX_D + M_LN2 - LNV)
{
x = exp(w);
x += VD2M1 * x;
}
else {
else
{
errno = ERANGE;
x = HUGE_VAL;
}
}
else {
else
{
double z = exp(y);
x = 0.5 * (z + (cosh_flag ? 1.0 : -1.0)/z);
x = 0.5 * (z + (cosh_flag ? 1.0 : -1.0) / z);
}
return negative ? -x : x;
}
@ -76,6 +82,7 @@ sinh(double x)
double
cosh(double x)
{
if (x < 0) x = -x;
if (x < 0)
x = -x;
return sinh_cosh(x, 1);
}

View file

@ -18,25 +18,31 @@ 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;

View file

@ -36,41 +36,46 @@ tan(double x)
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;
}

View file

@ -32,24 +32,29 @@ tanh(double x)
};
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);
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;
}

View file

@ -10,7 +10,7 @@
#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
@ -18,19 +18,18 @@ typedef void *pointer; /* (void *) if you have it */
int _close(int d);
int
closedir(register DIR *dirp) /* stream from opendir */
int closedir(register DIR* dirp) /* stream from opendir */
{
register int fd;
if ( dirp == NULL || dirp->dd_buf == NULL )
if (dirp == NULL || dirp->dd_buf == NULL)
{
errno = EFAULT;
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 );
free((pointer)dirp->dd_buf);
free((pointer)dirp);
return _close(fd);
}

View file

@ -41,7 +41,8 @@
#define DIRSIZ 14 /* 14 char filename in Version 7 */
#endif
#define MAXNAMLEN 255
struct direct {
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 */
@ -73,31 +74,31 @@ struct direct {
#endif
#ifdef UFS
#define RecLen( dp ) (sizeof(struct direct)) /* fixed-length entries */
#define RecLen(dp) (sizeof(struct direct)) /* fixed-length entries */
#else /* BFS || NFS */
#define RecLen( dp ) ((dp)->d_reclen) /* variable-length entries */
#define RecLen(dp) ((dp)->d_reclen) /* variable-length entries */
#endif
#ifdef NFS
#ifdef BSD_SYSV
#define getdirentries _getdirentries /* package hides this system call */
#endif
extern int getdirentries(int fd, char *buf, int nbytes, long *basep);
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 )
#define GetBlock(fd, buf, n) getdirentries(fd, buf, (unsigned)n, &dummy)
#else /* UFS || BFS */
#ifdef BSD_SYSV
#define read _read /* avoid emulation overhead */
#endif
extern int read();
#define GetBlock( fd, buf, n ) read( fd, buf, (unsigned)n )
#define GetBlock(fd, buf, n) read(fd, buf, (unsigned)n)
#endif
#ifdef UNK
extern int _getdents(); /* actual system call */
#endif
extern int _fstat(int fd, struct stat *buf);
extern int _fstat(int fd, struct stat* buf);
extern off_t _lseek(int d, int offset, int whence);
#ifndef DIRBLKSIZ
@ -113,7 +114,7 @@ extern off_t _lseek(int d, int offset, int whence);
#endif
#ifndef S_ISDIR /* macro to test for directory file */
#define S_ISDIR( mode ) (((mode) & S_IFMT) == S_IFDIR)
#define S_ISDIR(mode) (((mode)&S_IFMT) == S_IFDIR)
#endif
#ifdef UFS
@ -124,13 +125,13 @@ extern off_t _lseek(int d, int offset, int whence);
*/
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) */
for (s = &name[1]; /* (empty names are impossible) */
*s != '\0' /* not NUL terminator */
&& ++s < stop; /* < DIRSIZ characters scanned */
)
@ -141,13 +142,16 @@ NameLen( char name[] ) /* return # chars in embedded name */
#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
@ -157,8 +161,7 @@ sig_catch(int sig) /* sig must be SIGSYS */
}
#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 */
@ -172,57 +175,58 @@ getdents(int fildes, char *buf, unsigned nbyte) /* returns # bytes read;
/* 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[.] */
register struct direct* dp; /* -> u.dblk[.] */
register struct dirent* bp; /* -> buf[.] */
#ifdef UNK
switch ( state )
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 );
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 );
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;
}
/* 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 */
#endif
) {
)
{
errno = EFAULT; /* invalid pointer */
return -1;
}
if ( _fstat( fildes, &statb ) != 0 )
if (_fstat(fildes, &statb) != 0)
return -1; /* errno set by fstat() */
if ( !S_ISDIR( statb.st_mode ) )
if (!S_ISDIR(statb.st_mode))
{
errno = ENOTDIR; /* not a directory */
return -1;
}
if ( (offset = _lseek( fildes, (off_t)0, SEEK_CUR )) < 0 )
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 )
if ((unsigned long)offset % DIRBLKSIZ != 0)
{
errno = ENOENT; /* file pointer probably misaligned */
return -1;
@ -231,52 +235,51 @@ getdents(int fildes, char *buf, unsigned nbyte) /* returns # bytes read;
serrno = errno; /* save entry errno */
for ( bp = (struct dirent *)buf; bp == (struct dirent *)buf; )
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 )
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 )
if (dp->d_reclen <= 0)
{
errno = EIO; /* corrupted directory */
return -1;
}
#endif
if ( dp->d_fileno != 0 )
if (dp->d_fileno != 0)
{ /* non-empty; copy to user buffer */
register int reclen =
DIRENTSIZ( NameLen( dp->d_name ) );
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 */
}
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] )
if ((char*)dp > &u.dblk[size])
{
errno = EIO; /* corrupted directory */
return -1;
@ -285,5 +288,5 @@ getdents(int fildes, char *buf, unsigned nbyte) /* returns # bytes read;
}
errno = serrno; /* restore entry errno */
return (char *)bp - buf; /* return # bytes read */
return (char*)bp - buf; /* return # bytes read */
}

View file

@ -11,7 +11,7 @@
#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) */
@ -20,21 +20,20 @@ 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
static char _gr_file[] = "/etc/group";
static char _grbuf[256];
static char _buffer[RBUFSIZE];
static char *_pnt;
static char *_buf;
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);
@ -45,8 +44,7 @@ setgrent(void)
return _gfd;
}
void
endgrent(void)
void endgrent(void)
{
if (_gfd >= 0)
_close(_gfd);
@ -55,7 +53,6 @@ endgrent(void)
_bufcnt = 0;
}
static int
getline(void)
{
@ -63,8 +60,10 @@ getline(void)
return 0;
_buf = _grbuf;
do {
if (--_bufcnt <= 0){
do
{
if (--_bufcnt <= 0)
{
if ((_bufcnt = _read(_gfd, _buffer, RBUFSIZE)) <= 0)
return 0;
else
@ -87,7 +86,7 @@ skip_period(void)
*_buf++ = '\0';
}
struct group *
struct group*
getgrent(void)
{
if (getline() == 0)
@ -102,14 +101,14 @@ getgrent(void)
return &grp;
}
struct group *
getgrnam(const char *name)
struct group*
getgrnam(const char* name)
{
struct group *g;
struct group* g;
setgrent();
while ((g = getgrent()) != 0)
if (!strcmp(g -> gr_name, name))
if (!strcmp(g->gr_name, name))
break;
endgrent();
if (g != 0)
@ -118,14 +117,14 @@ getgrnam(const char *name)
return 0;
}
struct group *
struct group*
getgrgid(int gid)
{
struct group *g;
struct group* g;
setgrent();
while ((g = getgrent()) != 0)
if (g -> gr_gid == gid)
if (g->gr_gid == gid)
break;
endgrent();
if (g != 0)

View file

@ -6,53 +6,63 @@
#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;
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++;
}

View file

@ -9,16 +9,15 @@
#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;
@ -26,7 +25,8 @@ getpass(const char *prompt)
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);
@ -39,7 +39,8 @@ getpass(const char *prompt)
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);
}

View file

@ -5,15 +5,17 @@
#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;
}

View file

@ -3,28 +3,32 @@
/* 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 char* p;
pid = getpid(); /* get process id as semi-unique number */
p = template;
while (*p) p++; /* find end of string */
while (*p)
p++; /* find end of string */
/* Replace XXXXXX at end of template with pid. */
while (*--p == 'X') {
while (*--p == 'X')
{
*p = '0' + (pid % 10);
pid /= 10;
}
p++;
for (k = 'a'; k <= 'z'; k++) {
for (k = 'a'; k <= 'z'; k++)
{
*p = k;
if (access(template, 0) < 0) {
if (access(template, 0) < 0)
{
return template;
}
}
return("/");
return ("/");
}

View file

@ -11,11 +11,11 @@
#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
@ -26,36 +26,35 @@ extern int _fstat(int fd, struct stat *buf);
#endif
#ifndef S_ISDIR /* macro to test for directory file */
#define S_ISDIR( mode ) (((mode) & S_IFMT) == S_IFDIR)
#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 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 )
if ((fd = _open(dirname, O_RDONLY, 0)) < 0)
return NULL; /* errno set by open() */
if ( _fstat( fd, &sbuf ) != 0 || !S_ISDIR( sbuf.st_mode ) )
if (_fstat(fd, &sbuf) != 0 || !S_ISDIR(sbuf.st_mode))
{
(void)_close( fd );
(void)_close(fd);
errno = ENOTDIR;
return NULL; /* not a directory */
}
if ( (dirp = (DIR *)malloc( sizeof(DIR) )) == NULL
|| (dirp->dd_buf = (char *)malloc( (unsigned)DIRBUF )) == NULL
) {
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 */
}

View file

@ -20,37 +20,39 @@ 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 (Xtype == 2 || _pipe(piped) < 0 || (pid = _fork()) < 0)
return 0;
if (pid == 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);
_execl("/bin/sh", "sh", "-c", command, (char*)0);
_exit(127); /* like system() ??? */
}
@ -65,8 +67,7 @@ popen(const char *command, const char *type)
#define ret_val status
#endif
int
pclose(FILE *stream)
int pclose(FILE* stream)
{
int fd = fileno(stream);
wait_arg status;
@ -75,10 +76,13 @@ pclose(FILE *stream)
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;
@ -95,13 +99,18 @@ _dup2(int oldd, int newd)
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;

View file

@ -5,15 +5,16 @@
#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;
}

View file

@ -10,38 +10,35 @@
#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
#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 */
}
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
)
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;
}

View file

@ -23,15 +23,14 @@ extern off_t _lseek(int d, int offset, int whence);
#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 */
}
dirp->dd_loc = dirp->dd_size = 0; /* invalidate buffer */
(void)_lseek( dirp->dd_fd, (off_t)0, SEEK_SET ); /* may set errno */
(void)_lseek(dirp->dd_fd, (off_t)0, SEEK_SET); /* may set errno */
}

View file

@ -29,13 +29,12 @@ 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 */
if ( dirp == NULL || dirp->dd_buf == NULL )
if (dirp == NULL || dirp->dd_buf == NULL)
{
errno = EFAULT;
return; /* invalid pointer */
@ -52,34 +51,33 @@ seekdir(register DIR *dirp, register off_t loc)
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
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; ; )
for (rewind = true;;)
{
register struct dirent *dp;
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 */
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
&& (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 )
{
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;
dirp->dd_loc = (char*)dp - dirp->dd_buf;
return;
}
@ -87,22 +85,22 @@ seekdir(register DIR *dirp, register off_t loc)
dirp->dd_loc = dirp->dd_size; /* set end of buffer */
}
else /* whole buffer past matching entry */
if ( !rewind )
if (!rewind)
{ /* no point in searching further */
errno = EINVAL;
return; /* no entry at specified loc */
}
else { /* rewind directory and start over */
else
{ /* rewind directory and start over */
rewind = false; /* but only once! */
dirp->dd_loc = dirp->dd_size = 0;
if ( _lseek( dirp->dd_fd, (off_t)0, SEEK_SET )
!= 0
)
if (_lseek(dirp->dd_fd, (off_t)0, SEEK_SET)
!= 0)
return; /* errno already set (EBADF) */
if ( loc == 0 )
if (loc == 0)
return; /* save time */
}
}

View file

@ -17,15 +17,16 @@ alfun(int sig)
longjmp(setjmpbuf, 1);
} /* 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;
@ -33,14 +34,17 @@ sleep(int n)
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();
}

View file

@ -18,17 +18,16 @@ extern off_t _lseek(int d, int offset, int whence);
#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 */
}
if ( dirp->dd_loc < dirp->dd_size ) /* valid index */
return ((struct dirent *)&dirp->dd_buf[dirp->dd_loc])->d_off;
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 );
return _lseek(dirp->dd_fd, (off_t)0, SEEK_CUR);
}

View file

@ -13,26 +13,27 @@
#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) {
switch (0)
{
case 0:
case sizeof(sigset_t) <= sizeof(long): break;
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);
}

View file

@ -9,8 +9,7 @@
#endif
#include <signal.h>
int
raise(int sig)
int raise(int sig)
{
if (sig < 0 || sig > _NSIG)
return -1;

View file

@ -5,8 +5,7 @@
#include <stdio.h>
void
(clearerr)(FILE *stream)
void(clearerr)(FILE* stream)
{
clearerr(stream);
}

View file

@ -7,20 +7,20 @@
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,

View file

@ -10,18 +10,22 @@
#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;
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;
@ -39,7 +43,8 @@ gnum(register const char *f, int *ip, va_list *app)
#endif
#define PUTC(c) \
do { \
do \
{ \
int i = putc(c, stream); \
if (i == EOF) \
{ \
@ -49,71 +54,100 @@ gnum(register const char *f, int *ip, va_list *app)
} 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)) {
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);
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) {
if (is_signed)
{
signed_val = va_arg(*ap, long);
} else {
}
else
{
unsigned_val = va_arg(*ap, unsigned long);
}
break;
default:
if (is_signed) {
if (is_signed)
{
signed_val = va_arg(*ap, int);
} else {
}
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 ((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;
switch (c)
{
case 'b':
base = 2;
break;
case 'o':
base = 8;
break;
case 'd':
case 'i':
case 'u': base = 10; break;
case 'u':
base = 10;
break;
case 'x':
case 'X':
case 'p': base = 16; break;
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++;
}
@ -121,20 +155,22 @@ o_print(va_list *ap, int flags, char *s, char c, int precision, int is_signed)
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 char* s;
register int j;
int i, c, width, precision, zfill, flags, between_fill;
int nrchars=0;
const char *oldfmt;
int nrchars = 0;
const char* oldfmt;
char *s1, buf[1025];
while (c = *fmt++) {
if (c != '%') {
while (c = *fmt++)
{
if (c != '%')
{
#ifdef CPM
if (c == '\n') {
if (c == '\n')
{
PUTC('\r');
}
#endif
@ -143,51 +179,84 @@ _doprnt(register const char *fmt, va_list ap, FILE *stream)
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_WIDTHSPEC))
width = 0;
if (flags & FL_SIGN) flags &= ~FL_SPACE;
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++) {
switch (c = *fmt++)
{
default:
#ifdef CPM
if (c == '\n') {
if (c == '\n')
{
PUTC('\r');
nrchars++;
}
@ -197,18 +266,19 @@ _doprnt(register const char *fmt, va_list ap, FILE *stream)
continue;
case 'n':
if (flags & FL_SHORT)
*va_arg(ap, short *) = (short) nrchars;
*va_arg(ap, short*) = (short)nrchars;
else if (flags & FL_LONG)
*va_arg(ap, long *) = (long) nrchars;
*va_arg(ap, long*) = (long)nrchars;
else
*va_arg(ap, int *) = (int) nrchars;
*va_arg(ap, int*) = (int)nrchars;
continue;
case 's':
s1 = va_arg(ap, char *);
s1 = va_arg(ap, char*);
if (s1 == NULL)
s1 = "(null)";
s = s1;
while (precision || !(flags & FL_PRECSPEC)) {
while (precision || !(flags & FL_PRECSPEC))
{
if (*s == '\0')
break;
s++;
@ -223,15 +293,19 @@ _doprnt(register const char *fmt, va_list ap, FILE *stream)
case 'u':
case 'x':
case 'X':
if (!(flags & FL_PRECSPEC)) precision = 1;
else if (c != 'p') flags &= ~FL_ZEROFILL;
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;
if (!(flags & FL_PRECSPEC))
precision = 1;
else
flags &= ~FL_ZEROFILL;
s = o_print(&ap, flags, s, c, precision, 1);
break;
case 'c':
@ -257,11 +331,12 @@ _doprnt(register const char *fmt, va_list ap, FILE *stream)
#endif /* ACKCONF_NO_STDIO_FLOAT */
case 'r':
ap = va_arg(ap, va_list);
fmt = va_arg(ap, char *);
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:
@ -276,33 +351,43 @@ _doprnt(register const char *fmt, va_list ap, FILE *stream)
&& (((c == 'x' || c == 'X') && (flags & FL_ALT))
|| (c == 'p')
|| ((flags & FL_SIGNEDCONV)
&& ( *s1 == '+' || *s1 == '-' || *s1 == ' '))))
&& (*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++;
if (between_fill)
{
if (flags & FL_SIGNEDCONV)
{
j--;
nrchars++;
PUTC(*s1++);
} else {
j -= 2; nrchars += 2;
}
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);
}

View file

@ -30,59 +30,79 @@ static char inp_buf[NUMLEN];
* 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) {
switch (type)
{
case 'i': /* i means octal, decimal or hexadecimal */
case 'p':
case 'x':
case 'X': base = 16; break;
case 'X':
base = 16;
break;
case 'd':
case 'u': base = 10; break;
case 'o': base = 8; break;
case 'b': base = 2; break;
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);
}
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;
@ -97,29 +117,33 @@ o_collect(register int c, register FILE *stream, char type,
* 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)
@ -127,54 +151,61 @@ f_collect(register int c, register FILE *stream, register int 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 */
/*
* 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 */
register char* str; /* temporary pointer */
char* tmp_string; /* ditto */
unsigned width; /* width of field */
int flags; /* some flags */
int reverse; /* reverse the checking in [...] */
@ -184,84 +215,116 @@ _doscan(register FILE *stream, const char *format, va_list ap)
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 */
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 */
}
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) {
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_NOASSIGN))
{ /* silly, though */
if (flags & FL_SHORT)
*va_arg(ap, short *) = (short) nrchars;
*va_arg(ap, short*) = (short)nrchars;
else if (flags & FL_LONG)
*va_arg(ap, long *) = (long) nrchars;
*va_arg(ap, long*) = (long)nrchars;
else
*va_arg(ap, int *) = (int) nrchars;
*va_arg(ap, int*) = (int)nrchars;
}
break;
case 'p': /* pointer */
@ -276,13 +339,15 @@ _doscan(register FILE *stream, const char *format, va_list ap)
case 'X': /* ditto */
if (!(flags & FL_WIDTHSPEC) || width > NUMLEN)
width = NUMLEN;
if (!width) return done;
if (!width)
return done;
str = o_collect(ic, stream, kind, width, &base);
if (str < inp_buf
|| (str == inp_buf
&& (*str == '-'
|| *str == '+'))) return done;
|| *str == '+')))
return done;
/*
* Although the length of the number is str-inp_buf+1
@ -290,37 +355,43 @@ _doscan(register FILE *stream, const char *format, va_list ap)
*/
nrchars += str - inp_buf;
if (!(flags & FL_NOASSIGN)) {
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;
*va_arg(ap, unsigned long*) = (unsigned long)val;
else if (flags & FL_SHORT)
*va_arg(ap, unsigned short *) = (unsigned short) val;
*va_arg(ap, unsigned short*) = (unsigned short)val;
else
*va_arg(ap, unsigned *) = (unsigned) val;
*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;
str = va_arg(ap, char*);
if (!width)
return done;
while (width && ic != EOF) {
while (width && ic != EOF)
{
if (!(flags & FL_NOASSIGN))
*str++ = (char) ic;
if (--width) {
*str++ = (char)ic;
if (--width)
{
ic = getc(stream);
nrchars++;
}
}
if (width) {
if (ic != EOF) ungetc(ic,stream);
if (width)
{
if (ic != EOF)
ungetc(ic, stream);
nrchars--;
}
break;
@ -328,13 +399,16 @@ _doscan(register FILE *stream, const char *format, va_list ap)
if (!(flags & FL_WIDTHSPEC))
width = 0xffff;
if (!(flags & FL_NOASSIGN))
str = va_arg(ap, char *);
if (!width) return done;
str = va_arg(ap, char*);
if (!width)
return done;
while (width && ic != EOF && !isspace(ic)) {
while (width && ic != EOF && !isspace(ic))
{
if (!(flags & FL_NOASSIGN))
*str++ = (char) ic;
if (--width) {
*str++ = (char)ic;
if (--width)
{
ic = getc(stream);
nrchars++;
}
@ -342,67 +416,82 @@ _doscan(register FILE *stream, const char *format, va_list ap)
/* terminate the string */
if (!(flags & FL_NOASSIGN))
*str = '\0';
if (width) {
if (ic != EOF) ungetc(ic,stream);
if (width)
{
if (ic != EOF)
ungetc(ic, stream);
nrchars--;
}
break;
case '[':
if (!(flags & FL_WIDTHSPEC))
width = 0xffff;
if (!width) return done;
if (!width)
return done;
if ( *++format == '^' ) {
if (*++format == '^')
{
reverse = 1;
format++;
} else
}
else
reverse = 0;
for (str = Xtable; str < &Xtable[NR_CHARS]
; str++)
for (str = Xtable; str < &Xtable[NR_CHARS]; str++)
*str = 0;
if (*format == ']') Xtable[*format++] = 1;
while (*format && *format != ']') {
if (*format == ']')
Xtable[*format++] = 1;
if (*format == '-') {
while (*format && *format != ']')
{
Xtable[*format++] = 1;
if (*format == '-')
{
format++;
if (*format
&& *format != ']'
&& *(format) >= *(format -2)) {
&& *(format) >= *(format - 2))
{
int c;
for( c = *(format -2) + 1
; c <= *format ; 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);
if (!*format || !(Xtable[ic] ^ reverse))
{
if (ic != EOF)
ungetc(ic, stream);
return done;
}
if (!(flags & FL_NOASSIGN))
str = va_arg(ap, char *);
str = va_arg(ap, char*);
do {
do
{
if (!(flags & FL_NOASSIGN))
*str++ = (char) ic;
if (--width) {
*str++ = (char)ic;
if (--width)
{
ic = getc(stream);
nrchars++;
}
} while (width && ic != EOF && (Xtable[ic] ^ reverse));
if (width) {
if (ic != EOF) ungetc(ic, stream);
if (width)
{
if (ic != EOF)
ungetc(ic, stream);
nrchars--;
}
if (!(flags & FL_NOASSIGN)) { /* terminate string */
if (!(flags & FL_NOASSIGN))
{ /* terminate string */
*str = '\0';
}
break;
@ -415,13 +504,15 @@ _doscan(register FILE *stream, const char *format, va_list ap)
if (!(flags & FL_WIDTHSPEC) || width > NUMLEN)
width = NUMLEN;
if (!width) return done;
if (!width)
return done;
str = f_collect(ic, stream, width);
if (str < inp_buf
|| (str == inp_buf
&& (*str == '-'
|| *str == '+'))) return done;
|| *str == '+')))
return done;
/*
* Although the length of the number is str-inp_buf+1
@ -429,21 +520,22 @@ _doscan(register FILE *stream, const char *format, va_list ap)
*/
nrchars += str - inp_buf;
if (!(flags & FL_NOASSIGN)) {
if (!(flags & FL_NOASSIGN))
{
ld_val = strtod(inp_buf, &tmp_string);
if (flags & FL_LONGDOUBLE)
*va_arg(ap, long double *) = (long double) ld_val;
*va_arg(ap, long double*) = (long double)ld_val;
else if (flags & FL_LONG)
*va_arg(ap, double*) = (double)ld_val;
else
if (flags & FL_LONG)
*va_arg(ap, double *) = (double) ld_val;
else
*va_arg(ap, float *) = (float) ld_val;
*va_arg(ap, float*) = (float)ld_val;
}
break;
#endif
} /* end switch */
conv++;
if (!(flags & FL_NOASSIGN) && kind != 'n') done++;
if (!(flags & FL_NOASSIGN) && kind != 'n')
done++;
format++;
}
return conv || (ic != EOF) ? done : EOF;

View file

@ -5,11 +5,11 @@
#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);
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;
@ -17,15 +17,13 @@ cvt(long double value, int ndigit, int *decpt, int *sign, int ecvtflag)
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);
}

View file

@ -8,23 +8,25 @@
#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;
}

View file

@ -7,19 +7,20 @@
#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++) {
switch (*mode++)
{
case 'r':
flags |= _IOREAD | _IOREADING;
break;
@ -29,10 +30,12 @@ fdopen(int fd, const char *mode)
flags |= _IOWRITE | _IOWRITING;
break;
default:
return (FILE *)NULL;
return (FILE*)NULL;
}
while(*mode) {
switch(*mode++) {
while (*mode)
{
switch (*mode++)
{
case 'b':
continue;
case '+':
@ -45,8 +48,9 @@ fdopen(int fd, const char *mode)
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))

View file

@ -5,8 +5,7 @@
#include <stdio.h>
int
(feof)(FILE *stream)
int(feof)(FILE* stream)
{
return feof(stream);
}

View file

@ -5,8 +5,7 @@
#include <stdio.h>
int
(ferror)(FILE *stream)
int(ferror)(FILE* stream)
{
return ferror(stream);
}

View file

@ -8,13 +8,13 @@
#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 (!stream)
{
for (i = 0; i < FOPEN_MAX; i++)
if (__iotab[i] && fflush(__iotab[i]))
retval = EOF;
return retval;
@ -24,18 +24,21 @@ fflush(FILE *stream)
|| (!io_testflag(stream, _IOREADING)
&& !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 */
stream->_flags &= ~_IOWRITING;
@ -43,32 +46,33 @@ fflush(FILE *stream)
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;
}
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]);
}

View file

@ -5,8 +5,7 @@
#include <stdio.h>
int
fgetc(FILE *stream)
int fgetc(FILE* stream)
{
return getc(stream);
}

View file

@ -5,10 +5,10 @@
#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;
}

View file

@ -5,22 +5,27 @@
#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;

View file

@ -5,8 +5,7 @@
#include <stdio.h>
int
(fileno)(FILE *stream)
int(fileno)(FILE* stream)
{
return stream->_fd;
}

View file

@ -8,20 +8,23 @@
#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;
}
@ -29,33 +32,40 @@ __fillbuf(register FILE *stream)
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

View file

@ -9,10 +9,10 @@
#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;
@ -24,29 +24,34 @@ _pfloat(long double r, register char *s, int n, int flags)
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;
register char* s1;
s1 = _ecvt(r, n + 1, &dp, &sign);
if (sign)
@ -60,21 +65,29 @@ _pscien(long double r, register char *s, int n, int flags)
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;
}
if (dp >= 100) {
else
{
*s++ = '+';
}
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;
}
@ -82,8 +95,8 @@ _pscien(long double r, register char *s, int n, int flags)
#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;
@ -92,7 +105,8 @@ _gcvt(long double value, int ndigit, char *s, int flags)
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)
@ -102,67 +116,83 @@ _gcvt(long double value, int ndigit, char *s, int flags)
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) {
while (i++ <= dp) *s2++ = '0';
if (i == dp)
*s2++ = '.';
}
if ((s2[-1]=='.') && !(flags & FL_ALT)) s2--;
if (i <= dp)
{
while (i++ <= dp)
*s2++ = '0';
*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);
if (flags & FL_LONGDOUBLE)
ld_val = va_arg(*ap, long double);
else
ld_val = (long double)va_arg(*ap, double);
switch(c) {
switch (c)
{
case 'f':
s = _pfloat(ld_val, s, precision, flags);
break;
case 'e':
case 'E':
s = _pscien(ld_val, s, precision , flags);
s = _pscien(ld_val, s, precision, flags);
break;
case 'g':
case 'G':
@ -170,9 +200,12 @@ _f_print(va_list *ap, int flags, char *s, char c, int precision)
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;
}

View file

@ -11,107 +11,136 @@
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->_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;
@ -119,5 +148,5 @@ __flushbuf(int c, FILE * stream)
}
*(stream->_buf) = c;
}
return (unsigned char) c;
return (unsigned char)c;
}

View file

@ -31,19 +31,19 @@
* 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++) {
switch (*mode++)
{
case 'r':
flags |= _IOREAD | _IOREADING;
rwmode = O_RDONLY;
@ -59,11 +59,13 @@ fopen(const char *name, const char *mode)
rwflags |= O_APPEND | O_CREAT;
break;
default:
return (FILE *)NULL;
return (FILE*)NULL;
}
while (*mode) {
switch(*mode++) {
while (*mode)
{
switch (*mode++)
{
case 'b':
continue;
case '+':
@ -82,19 +84,22 @@ fopen(const char *name, const char *mode)
*/
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))

View file

@ -7,15 +7,14 @@
#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);

View file

@ -5,8 +5,7 @@
#include <stdio.h>
int
fputc(int c, FILE *stream)
int fputc(int c, FILE* stream)
{
return putc(c, stream);
}

View file

@ -5,14 +5,15 @@
#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++;
if (putc(*s++, stream) == EOF)
return EOF;
else
i++;
return i;
}

View file

@ -6,17 +6,19 @@
#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

View file

@ -15,17 +15,17 @@
* 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++) {
switch (*mode++)
{
case 'r':
flags |= _IOREAD;
rwmode = O_RDONLY;
@ -41,11 +41,13 @@ freopen(const char *name, const char *mode, FILE *stream)
rwflags |= O_APPEND | O_CREAT;
break;
default:
return (FILE *)NULL;
return (FILE*)NULL;
}
while (*mode) {
switch(*mode++) {
while (*mode)
{
switch (*mode++)
{
case 'b':
continue;
case '+':
@ -61,23 +63,28 @@ freopen(const char *name, const char *mode, FILE *stream)
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;

View file

@ -7,8 +7,7 @@
#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;

View file

@ -8,8 +8,7 @@
#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;
@ -17,16 +16,20 @@ fseek(FILE *stream, long int offset, int whence)
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))

View file

@ -5,8 +5,7 @@
#include <stdio.h>
int
fsetpos(FILE *stream, fpos_t *pos)
int fsetpos(FILE* stream, fpos_t* pos)
{
return fseek(stream, *pos, SEEK_SET);
}

View file

@ -8,24 +8,25 @@
#include <unistd.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)
else if (io_testflag(stream, _IOWRITING)
&& stream->_buf
&& !io_testflag(stream,_IONBF))
&& !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;
}

View file

@ -6,23 +6,24 @@
#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)
return ndone;
cp++;
}
while (--s);
} while (--s);
ndone++;
}
return ndone;

View file

@ -5,8 +5,7 @@
#include <stdio.h>
int
(getc)(FILE *stream)
int(getc)(FILE* stream)
{
return getc(stream);
}

View file

@ -5,8 +5,7 @@
#include <stdio.h>
int
(getchar)(void)
int(getchar)(void)
{
return getchar();
}

View file

@ -5,21 +5,25 @@
#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';

View file

@ -7,15 +7,14 @@
/* 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;
}

View file

@ -3,7 +3,7 @@
*/
/* $Id$ */
int _gtty(int d, char *buf);
int _gtty(int d, char* buf);
int _isatty(int d)
{

View file

@ -7,13 +7,13 @@
#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);
}

View file

@ -7,8 +7,7 @@
#include <stdarg.h>
#include "loc_incl.h"
int
printf(const char *format, ...)
int printf(const char* format, ...)
{
va_list ap;
int retval;

View file

@ -5,8 +5,7 @@
#include <stdio.h>
int
(putc)(int c, FILE *stream)
int(putc)(int c, FILE* stream)
{
return putc(c, stream);
}

View file

@ -5,8 +5,7 @@
#include <stdio.h>
int
(putchar)(int c)
int(putchar)(int c)
{
return putchar(c);
}

View file

@ -5,16 +5,19 @@
#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;
}

View file

@ -7,7 +7,7 @@
#include <stdio.h>
#include <unistd.h>
int
remove(const char *filename) {
int remove(const char* filename)
{
return unlink(filename);
}

View file

@ -6,9 +6,8 @@
#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);
}

View file

@ -7,8 +7,7 @@
#include <stdarg.h>
#include "loc_incl.h"
int
scanf(const char *format, ...)
int scanf(const char* format, ...)
{
va_list ap;
int retval;
@ -21,5 +20,3 @@ scanf(const char *format, ...)
return retval;
}

View file

@ -6,8 +6,7 @@
#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);
}

View file

@ -9,8 +9,7 @@
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;
@ -18,29 +17,37 @@ setvbuf(register FILE *stream, char *buf, int mode, size_t size)
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;
} else {
if (!buf && (mode != _IONBF))
{
if (size <= 0 || (buf = (char*)malloc(size)) == NULL)
{
retval = EOF;
}
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;
}

View file

@ -7,8 +7,7 @@
#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;
@ -18,12 +17,12 @@ snprintf(char * s, size_t len, const char *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._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);

View file

@ -7,8 +7,7 @@
#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;
@ -18,12 +17,12 @@ sprintf(char * s, const char *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._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);

View file

@ -8,7 +8,7 @@
#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;
@ -18,8 +18,8 @@ int sscanf(const char *s, const char *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._buf = (unsigned char*)s;
tmp_stream._ptr = (unsigned char*)s;
tmp_stream._count = strlen(s);
retval = _doscan(&tmp_stream, format, ap);

View file

@ -9,20 +9,22 @@
#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;
}

View file

@ -9,20 +9,24 @@
#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;
}

View file

@ -6,21 +6,22 @@
#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 !!! */
/* 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;
}

View file

@ -7,8 +7,7 @@
#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);
}

View file

@ -7,8 +7,7 @@
#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);
}

View file

@ -7,20 +7,19 @@
#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._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;
}

View file

@ -7,20 +7,19 @@
#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._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;
}

View file

@ -12,10 +12,9 @@
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);
}

View file

@ -6,8 +6,7 @@
#include <stdlib.h>
int
abs(register int i)
int abs(register int i)
{
return i >= 0 ? i : -i;
}

View file

@ -7,8 +7,7 @@
extern void (*__functab[NEXITS])(void);
extern int __funccnt;
int
atexit(void (*func)(void))
int atexit(void (*func)(void))
{
if (__funccnt >= NEXITS)
return 1;

View file

@ -7,13 +7,12 @@
#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;
}

Some files were not shown because too many files have changed in this diff Show more