Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 4972 → Rev 4973

/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/Makefile
0,0 → 1,11
THIS_SRCS = allocfil.c clearerr.c doprnt.c doscan.c fclose.c feof.c \
ferror.c fflush.c fgetc.c fgetpos.c fgets.c filbuf.c flsbuf.c \
fopen.c fprintf.c fputc.c fputs.c fread.c freopen.c frlist.c \
fscanf.c fseek.c fsetpos.c ftell.c fwalk.c fwrite.c getc.c getchar.c \
gets.c getw.c perror.c printf.c putc.c putchar.c puts.c putw.c \
remove.c _rename.c rename.c rewind.c scanf.c setbuf.c setbuffe.c \
setlineb.c setvbuf.c sprintf.c sscanf.c stdaux.c stderr.c stdin.c \
stdiohk.c stdout.c stdprn.c tmpfile.c tmpnam.c ungetc.c vfprintf.c \
vprintf.c vsprintf.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/_rename.c
0,0 → 1,11
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdio.h>
#include <errno.h>
#include <libc/dosio.h>
#include<assert.h>
 
int _rename(const char *old, const char *new)
{
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/allocfil.c
0,0 → 1,49
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <libc/file.h>
#include <libc/local.h>
#include <libc/stdiohk.h>
 
FILE *__alloc_file(void)
{
__file_rec *fr = __file_rec_list;
__file_rec **last_fr = &__file_rec_list;
FILE *rv=0;
int i;
 
/* Try to find an empty slot */
while (fr)
{
last_fr = &(fr->next);
 
/* If one of the existing slots is available, return it */
for (i=0; i<fr->count; i++)
if (fr->files[i]->_flag == 0)
return fr->files[i];
 
/* If this one is full, go to the next */
if (fr->count == __FILE_REC_MAX)
fr = fr->next;
else
/* it isn't full, we can add to it */
break;
}
if (!fr)
{
/* add another one to the end, make it empty */
fr = *last_fr = (__file_rec *)malloc(sizeof(__file_rec));
if (fr == 0)
return 0;
fr->next = 0;
fr->count = 0;
}
/* fr is a pointer to a rec with empty slots in it */
rv = fr->files[fr->count] = (FILE *)malloc(sizeof(FILE));
if (rv == 0)
return 0;
memset(rv, 0, sizeof(FILE));
fr->count ++;
return rv;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/clearerr.c
0,0 → 1,10
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
#undef clearerr
void
clearerr(FILE *f)
{
f->_flag &= ~(_IOERR|_IOEOF);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/doprnt.c
0,0 → 1,840
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <sys/types.h>
#include <stdarg.h>
#include <stdio.h>
#include <ctype.h>
#include <locale.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <libc/file.h>
#include <libc/stdiohk.h>
#include <libc/local.h>
 
static char decimal = '.';
 
/* 11-bit exponent (VAX G floating point) is 308 decimal digits */
#define MAXEXP 308
#define MAXEXPLD 4952 /* this includes subnormal numbers */
/* 128 bit fraction takes up 39 decimal digits; max reasonable precision */
#define MAXFRACT 39
 
#define DEFPREC 6
#define DEFLPREC 6
 
#define BUF (MAXEXPLD+MAXFRACT+1) /* + decimal point */
 
#define PUTC(ch) (void) putc(ch, fp)
 
#define ARG(basetype) \
_ulong = flags&LONGINT ? va_arg(argp, long basetype) : \
flags&SHORTINT ? (short basetype)va_arg(argp, int) : \
va_arg(argp, int)
 
static int nan2 = 0;
 
static __inline__ int todigit(char c)
{
if (c<='0') return 0;
if (c>='9') return 9;
return c-'0';
}
static __inline__ char tochar(int n)
{
if (n>=9) return '9';
if (n<=0) return '0';
return n+'0';
}
 
/* have to deal with the negative buffer count kludge */
 
#define LONGINT 0x01 /* long integer */
#define LONGDBL 0x02 /* long double */
#define SHORTINT 0x04 /* short integer */
#define ALT 0x08 /* alternate form */
#define LADJUST 0x10 /* left adjustment */
#define ZEROPAD 0x20 /* zero (as opposed to blank) pad */
#define HEXPREFIX 0x40 /* add 0x or 0X prefix */
 
static cvtl(long double number, int prec, int flags, char *signp,
unsigned char fmtch, char *startp, char *endp);
static char *roundl(long double fract, int *expv, char *start, char *end,
char ch, char *signp);
static char *exponentl(char *p, int expv, unsigned char fmtch);
static int isspeciall(long double d, char *bufp);
 
static char NULL_REP[] = "(null)";
 
int
_doprnt(const char *fmt0, va_list argp, FILE *fp)
{
const char *fmt; /* format string */
int ch; /* character from fmt */
int cnt; /* return value accumulator */
int n; /* random handy integer */
char *t; /* buffer pointer */
long double _ldouble; /* double and long double precision arguments
%L.[eEfgG] */
unsigned long _ulong; /* integer arguments %[diouxX] */
int base; /* base for [diouxX] conversion */
int dprec; /* decimal precision in [diouxX] */
int fieldsz; /* field size expanded by sign, etc */
int flags; /* flags as above */
int fpprec; /* `extra' floating precision in [eEfgG] */
int prec; /* precision from format (%.3d), or -1 */
int realsz; /* field size expanded by decimal precision */
int size; /* size of converted field or string */
int width; /* width from format (%8d), or 0 */
char sign; /* sign prefix (' ', '+', '-', or \0) */
char softsign; /* temporary negative sign for floats */
const char *digs; /* digits for [diouxX] conversion */
char buf[BUF]; /* space for %c, %[diouxX], %[eEfgG] */
 
decimal = localeconv()->decimal_point[0];
 
if (fp->_flag & _IORW)
{
fp->_flag |= _IOWRT;
fp->_flag &= ~(_IOEOF|_IOREAD);
}
if ((fp->_flag & _IOWRT) == 0)
return (EOF);
 
fmt = fmt0;
digs = "0123456789abcdef";
for (cnt = 0;; ++fmt)
{
n = fp->_cnt;
for (t = (char *)fp->_ptr; (ch = *fmt) && ch != '%';
++cnt, ++fmt)
if ((--n < 0
&& (!(fp->_flag & _IOLBF) || -n >= fp->_bufsiz))
|| (ch == '\n' && fp->_flag & _IOLBF))
{
fp->_cnt = n;
fp->_ptr = t;
(void) _flsbuf((unsigned char)ch, fp);
n = fp->_cnt;
t = (char *)fp->_ptr;
}
else
*t++ = ch;
fp->_cnt = n;
fp->_ptr = t;
if (!ch)
return cnt;
flags = 0; dprec = 0; fpprec = 0; width = 0;
prec = -1;
sign = '\0';
rflag:
switch (*++fmt)
{
case ' ':
/*
* ``If the space and + flags both appear, the space
* flag will be ignored.''
* -- ANSI X3J11
*/
if (!sign)
sign = ' ';
goto rflag;
case '#':
flags |= ALT;
goto rflag;
case '*':
/*
* ``A negative field width argument is taken as a
* - flag followed by a positive field width.''
* -- ANSI X3J11
* They don't exclude field widths read from args.
*/
if ((width = va_arg(argp, int)) >= 0)
goto rflag;
width = -width;
/* FALLTHROUGH */
case '-':
flags |= LADJUST;
goto rflag;
case '+':
sign = '+';
goto rflag;
case '.':
if (*++fmt == '*')
n = va_arg(argp, int);
else
{
n = 0;
while (isascii(*fmt) && isdigit(*fmt))
n = 10 * n + todigit(*fmt++);
--fmt;
}
prec = n < 0 ? -1 : n;
goto rflag;
case '0':
/*
* ``Note that 0 is taken as a flag, not as the
* beginning of a field width.''
* -- ANSI X3J11
*/
flags |= ZEROPAD;
goto rflag;
case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
n = 0;
do {
n = 10 * n + todigit(*fmt);
} while (isascii(*++fmt) && isdigit(*fmt));
width = n;
--fmt;
goto rflag;
case 'L':
flags |= LONGDBL;
goto rflag;
case 'h':
flags |= SHORTINT;
goto rflag;
case 'l':
flags |= LONGINT;
goto rflag;
case 'c':
*(t = buf) = va_arg(argp, int);
size = 1;
sign = '\0';
goto pforw;
case 'D':
flags |= LONGINT;
/*FALLTHROUGH*/
case 'd':
case 'i':
ARG(int);
if ((long)_ulong < 0)
{
_ulong = -_ulong;
sign = '-';
}
base = 10;
goto number;
case 'e':
case 'E':
case 'f':
case 'g':
case 'G':
if (flags & LONGDBL)
_ldouble = va_arg(argp, long double);
else
_ldouble = (long double)va_arg(argp, double);
/*
* don't do unrealistic precision; just pad it with
* zeroes later, so buffer size stays rational.
*/
if (prec > MAXFRACT)
{
if (*fmt != 'g' && (*fmt != 'G' || (flags&ALT)))
fpprec = prec - MAXFRACT;
prec = MAXFRACT;
}
else if (prec == -1)
{
if (flags&LONGINT)
prec = DEFLPREC;
else
prec = DEFPREC;
}
/*
* softsign avoids negative 0 if _double is < 0 and
* no significant digits will be shown
*/
if (_ldouble < 0)
{
softsign = '-';
_ldouble = -_ldouble;
}
else
softsign = 0;
/*
* cvt may have to round up past the "start" of the
* buffer, i.e. ``intf("%.2f", (double)9.999);'';
* if the first char isn't NULL, it did.
*/
*buf = NULL;
size = cvtl(_ldouble, prec, flags, &softsign, *fmt, buf,
buf + sizeof(buf));
if (softsign && !nan2)
sign = '-';
nan2 = 0;
t = *buf ? buf : buf + 1;
goto pforw;
case 'n':
if (flags & LONGINT)
*va_arg(argp, long *) = cnt;
else if (flags & SHORTINT)
*va_arg(argp, short *) = cnt;
else
*va_arg(argp, int *) = cnt;
break;
case 'O':
flags |= LONGINT;
/*FALLTHROUGH*/
case 'o':
ARG(unsigned);
base = 8;
goto nosign;
case 'p':
/*
* ``The argument shall be a pointer to void. The
* value of the pointer is converted to a sequence
* of printable characters, in an implementation-
* defined manner.''
* -- ANSI X3J11
*/
/* NOSTRICT */
_ulong = (unsigned long)va_arg(argp, void *);
base = 16;
goto nosign;
case 's':
if (!(t = va_arg(argp, char *)))
t = NULL_REP;
if (prec >= 0)
{
/*
* can't use strlen; can only look for the
* NUL in the first `prec' characters, and
* strlen() will go further.
*/
char *p /*, *memchr() */;
 
if ((p = memchr(t, 0, prec)))
{
size = p - t;
if (size > prec)
size = prec;
}
else
size = prec;
}
else
size = strlen(t);
sign = '\0';
goto pforw;
case 'U':
flags |= LONGINT;
/*FALLTHROUGH*/
case 'u':
ARG(unsigned);
base = 10;
goto nosign;
case 'X':
digs = "0123456789ABCDEF";
/* FALLTHROUGH */
case 'x':
ARG(unsigned);
base = 16;
/* leading 0x/X only if non-zero */
if (flags & ALT && _ulong != 0)
flags |= HEXPREFIX;
 
/* unsigned conversions */
nosign: sign = '\0';
/*
* ``... diouXx conversions ... if a precision is
* specified, the 0 flag will be ignored.''
* -- ANSI X3J11
*/
number: if ((dprec = prec) >= 0)
flags &= ~ZEROPAD;
 
/*
* ``The result of converting a zero value with an
* explicit precision of zero is no characters.''
* -- ANSI X3J11
*/
t = buf + BUF;
if (_ulong != 0 || prec != 0)
{
do {
*--t = digs[_ulong % base];
_ulong /= base;
} while (_ulong);
digs = "0123456789abcdef";
if (flags & ALT && base == 8 && *t != '0')
*--t = '0'; /* octal leading 0 */
}
size = buf + BUF - t;
 
pforw:
/*
* All reasonable formats wind up here. At this point,
* `t' points to a string which (if not flags&LADJUST)
* should be padded out to `width' places. If
* flags&ZEROPAD, it should first be prefixed by any
* sign or other prefix; otherwise, it should be blank
* padded before the prefix is emitted. After any
* left-hand padding and prefixing, emit zeroes
* required by a decimal [diouxX] precision, then print
* the string proper, then emit zeroes required by any
* leftover floating precision; finally, if LADJUST,
* pad with blanks.
*/
 
/*
* compute actual size, so we know how much to pad
* fieldsz excludes decimal prec; realsz includes it
*/
fieldsz = size + fpprec;
realsz = dprec > fieldsz ? dprec : fieldsz;
if (sign)
realsz++;
if (flags & HEXPREFIX)
realsz += 2;
 
/* right-adjusting blank padding */
if ((flags & (LADJUST|ZEROPAD)) == 0 && width)
for (n = realsz; n < width; n++)
PUTC(' ');
/* prefix */
if (sign)
PUTC(sign);
if (flags & HEXPREFIX)
{
PUTC('0');
PUTC((char)*fmt);
}
/* right-adjusting zero padding */
if ((flags & (LADJUST|ZEROPAD)) == ZEROPAD)
for (n = realsz; n < width; n++)
PUTC('0');
/* leading zeroes from decimal precision */
for (n = fieldsz; n < dprec; n++)
PUTC('0');
 
/* the string or number proper */
n = size;
if (fp->_cnt - n >= 0 && (fp->_flag & _IOLBF) == 0)
{
fp->_cnt -= n;
memcpy((char *)fp->_ptr, t, n);
fp->_ptr += n;
}
else
while (--n >= 0)
PUTC(*t++);
/* trailing f.p. zeroes */
while (--fpprec >= 0)
PUTC('0');
/* left-adjusting padding (always blank) */
if (flags & LADJUST)
for (n = realsz; n < width; n++)
PUTC(' ');
/* finally, adjust cnt */
cnt += width > realsz ? width : realsz;
break;
case '\0': /* "%?" prints ?, unless ? is NULL */
return cnt;
default:
PUTC((char)*fmt);
cnt++;
}
}
/* NOTREACHED */
}
 
static long double pten[] =
{
1e1L, 1e2L, 1e4L, 1e8L, 1e16L, 1e32L, 1e64L, 1e128L, 1e256L,
1e512L, 1e1024L, 1e2048L, 1e4096L
};
 
static long double ptenneg[] =
{
1e-1L, 1e-2L, 1e-4L, 1e-8L, 1e-16L, 1e-32L, 1e-64L, 1e-128L, 1e-256L,
1e-512L, 1e-1024L, 1e-2048L, 1e-4096L
};
 
#define MAXP 4096
#define NP 12
#define P (4294967296.0L * 4294967296.0L * 2.0L) /* 2^65 */
static long double INVPREC = P;
static long double PREC = 1.0L/P;
#undef P
/*
* Defining FAST_LDOUBLE_CONVERSION results in a little bit faster
* version, which might be less accurate (about 1 bit) for long
* double. For 'normal' double it doesn't matter.
*/
/* #define FAST_LDOUBLE_CONVERSION */
 
static int
cvtl(long double number, int prec, int flags, char *signp, unsigned char fmtch,
char *startp, char *endp)
{
char *p, *t;
long double fract;
int dotrim, expcnt, gformat;
long double integer, tmp;
 
if ((expcnt = isspeciall(number, startp)))
return(expcnt);
 
dotrim = expcnt = gformat = 0;
/* fract = modfl(number, &integer); */
integer = number;
 
/* get an extra slot for rounding. */
t = ++startp;
 
p = endp - 1;
if (integer)
{
int i, lp=NP, pt=MAXP;
#ifndef FAST_LDOUBLE_CONVERSION
long double oint = integer, dd=1.0L;
#endif
if (integer > INVPREC)
{
integer *= PREC;
while(lp >= 0) {
if (integer >= pten[lp])
{
expcnt += pt;
integer *= ptenneg[lp];
#ifndef FAST_LDOUBLE_CONVERSION
dd *= pten[lp];
#endif
}
pt >>= 1;
lp--;
}
#ifndef FAST_LDOUBLE_CONVERSION
integer = oint/dd;
#else
integer *= INVPREC;
#endif
}
/*
* Do we really need this ?
*/
for (i = 0; i < expcnt; i++)
*p-- = '0';
}
number = integer;
fract = modfl(number, &integer);
/*
* get integer portion of number; put into the end of the buffer; the
* .01 is added for modf(356.0 / 10, &integer) returning .59999999...
*/
for (; integer; ++expcnt)
{
tmp = modfl(integer * 0.1L , &integer);
*p-- = tochar((int)((tmp + .01L) * 10));
}
switch(fmtch)
{
case 'f':
/* reverse integer into beginning of buffer */
if (expcnt)
for (; ++p < endp; *t++ = *p);
else
*t++ = '0';
/*
* if precision required or alternate flag set, add in a
* decimal point.
*/
if (prec || flags&ALT)
*t++ = decimal;
/* if requires more precision and some fraction left */
if (fract)
{
if (prec)
do {
fract = modfl(fract * 10.0L, &tmp);
*t++ = tochar((int)tmp);
} while (--prec && fract);
if (fract)
startp = roundl(fract, (int *)NULL, startp,
t - 1, (char)0, signp);
}
for (; prec--; *t++ = '0');
break;
case 'e':
case 'E':
eformat:
if (expcnt)
{
*t++ = *++p;
if (prec || flags&ALT)
*t++ = decimal;
/* if requires more precision and some integer left */
for (; prec && ++p < endp; --prec)
*t++ = *p;
/*
* if done precision and more of the integer component,
* round using it; adjust fract so we don't re-round
* later.
*/
if (!prec && ++p < endp)
{
fract = 0;
startp = roundl((long double)0.0L, &expcnt,
startp, t - 1, *p, signp);
}
/* adjust expcnt for digit in front of decimal */
--expcnt;
}
/* until first fractional digit, decrement exponent */
else if (fract)
{
int lp=NP, pt=MAXP;
#ifndef FAST_LDOUBLE_CONVERSION
long double ofract = fract, dd=1.0L;
#endif
expcnt = -1;
if (fract < PREC)
{
fract *= INVPREC;
while(lp >= 0)
{
if (fract <= ptenneg[lp])
{
expcnt -= pt;
fract *= pten[lp];
#ifndef FAST_LDOUBLE_CONVERSION
dd *= pten[lp];
#endif
}
pt >>= 1;
lp--;
}
#ifndef FAST_LDOUBLE_CONVERSION
fract = ofract*dd;
#else
fract *= PREC;
#endif
}
/* adjust expcnt for digit in front of decimal */
for ( /* expcnt = -1 */ ;; --expcnt)
{
fract = modfl(fract * 10.0L, &tmp);
if (tmp)
break;
}
*t++ = tochar((int)tmp);
if (prec || flags&ALT)
*t++ = decimal;
}
else
{
*t++ = '0';
if (prec || flags&ALT)
*t++ = decimal;
}
/* if requires more precision and some fraction left */
if (fract)
{
if (prec)
do {
fract = modfl(fract * 10.0L, &tmp);
*t++ = tochar((int)tmp);
} while (--prec && fract);
if (fract)
startp = roundl(fract, &expcnt, startp,
t - 1, (char)0, signp);
}
/* if requires more precision */
for (; prec--; *t++ = '0');
 
/* unless alternate flag, trim any g/G format trailing 0's */
if (gformat && !(flags&ALT))
{
while (t > startp && *--t == '0');
if (*t == decimal)
--t;
++t;
}
t = exponentl(t, expcnt, fmtch);
break;
case 'g':
case 'G':
/* a precision of 0 is treated as a precision of 1. */
if (!prec)
++prec;
/*
* ``The style used depends on the value converted; style e
* will be used only if the exponent resulting from the
* conversion is less than -4 or greater than the precision.''
* -- ANSI X3J11
*/
if (expcnt > prec || (!expcnt && fract && fract < .0001))
{
/*
* g/G format counts "significant digits, not digits of
* precision; for the e/E format, this just causes an
* off-by-one problem, i.e. g/G considers the digit
* before the decimal point significant and e/E doesn't
* count it as precision.
*/
--prec;
fmtch -= 2; /* G->E, g->e */
gformat = 1;
goto eformat;
}
/*
* reverse integer into beginning of buffer,
* note, decrement precision
*/
if (expcnt)
for (; ++p < endp; *t++ = *p, --prec);
else
*t++ = '0';
/*
* if precision required or alternate flag set, add in a
* decimal point. If no digits yet, add in leading 0.
*/
if (prec || flags&ALT)
{
dotrim = 1;
*t++ = decimal;
}
else
dotrim = 0;
/* if requires more precision and some fraction left */
while (prec && fract)
{
fract = modfl(fract * 10.0L, &tmp);
*t++ = tochar((int)tmp);
prec--;
}
if (fract)
startp = roundl(fract, (int *)NULL, startp, t - 1,
(char)0, signp);
/* alternate format, adds 0's for precision, else trim 0's */
if (flags&ALT)
for (; prec--; *t++ = '0');
else if (dotrim)
{
while (t > startp && *--t == '0');
if (*t != decimal)
++t;
}
}
return t - startp;
}
 
static char *
roundl(long double fract, int *expv, char *start, char *end, char ch,
char *signp)
{
long double tmp;
 
if (fract)
{
if (fract == 0.5L)
{
char *e = end;
if (*e == '.')
e--;
if (*e == '0' || *e == '2' || *e == '4'
|| *e == '6' || *e == '8')
{
tmp = 3.0;
goto start;
}
}
(void)modfl(fract * 10.0L, &tmp);
}
else
tmp = todigit(ch);
start:
if (tmp > 4)
for (;; --end)
{
if (*end == decimal)
--end;
if (++*end <= '9')
break;
*end = '0';
if (end == start)
{
if (expv)
{ /* e/E; increment exponent */
*end = '1';
++*expv;
}
else
{ /* f; add extra digit */
*--end = '1';
--start;
}
break;
}
}
/* ``"%.3f", (double)-0.0004'' gives you a negative 0. */
else if (*signp == '-')
for (;; --end)
{
if (*end == decimal)
--end;
if (*end != '0')
break;
if (end == start)
*signp = 0;
}
return start;
}
 
static char *
exponentl(char *p, int expv, unsigned char fmtch)
{
char *t;
char expbuf[MAXEXPLD];
 
*p++ = fmtch;
if (expv < 0)
{
expv = -expv;
*p++ = '-';
}
else
*p++ = '+';
t = expbuf + MAXEXPLD;
if (expv > 9)
{
do {
*--t = tochar(expv % 10);
} while ((expv /= 10) > 9);
*--t = tochar(expv);
for (; t < expbuf + MAXEXPLD; *p++ = *t++);
}
else
{
*p++ = '0';
*p++ = tochar(expv);
}
return p;
}
 
static int
isspeciall(long double d, char *bufp)
{
struct IEEExp {
unsigned manl:32;
unsigned manh:32;
unsigned exp:15;
unsigned sign:1;
} *ip = (struct IEEExp *)&d;
 
nan2 = 0; /* don't assume the static is 0 (emacs) */
if (ip->exp != 0x7fff)
return(0);
if ((ip->manh & 0x7fffffff) || ip->manl)
{
strcpy(bufp, "NaN");
nan2 = 1; /* kludge: we don't need the sign, it's not nice
but it should work */
}
else
(void)strcpy(bufp, "Inf");
return(3);
}
 
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/doscan.c
0,0 → 1,360
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <libc/file.h>
#include <libc/local.h>
#include <stdarg.h>
 
#define SPC 01
#define STP 02
 
#define SHORT 0
#define REGULAR 1
#define LONG 2
#define LONGDOUBLE 4
#define INT 0
#define FLOAT 1
 
static int _innum(void *ptr, int type, int len, int size, FILE *iop,
int (*scan_getc)(FILE *), int (*scan_ungetc)(int, FILE *),
int *eofptr);
static int _instr(char *ptr, int type, int len, FILE *iop,
int (*scan_getc)(FILE *), int (*scan_ungetc)(int, FILE *),
int *eofptr);
static const char *_getccl(const unsigned char *s);
 
static char _sctab[256] = {
0,0,0,0,0,0,0,0,
0,SPC,SPC,SPC,SPC,SPC,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
SPC,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,
};
 
static int nchars = 0;
 
int
_doscan(FILE *iop, const char *fmt, va_list argp)
{
return(_doscan_low(iop, fgetc, ungetc, fmt, argp));
}
 
int
_doscan_low(FILE *iop, int (*scan_getc)(FILE *), int (*scan_ungetc)(int, FILE *),
const char *fmt, va_list argp)
{
register int ch;
int nmatch, len, ch1;
void* ptr;
int fileended, size;
 
nchars = 0;
nmatch = 0;
fileended = 0;
for (;;) switch (ch = *fmt++) {
case '\0':
return (nmatch);
case '%':
if ((ch = *fmt++) == '%')
goto def;
if (ch == 'n')
{
int* arg = va_arg(argp, int*);
*arg = nchars;
break;
}
if (fileended)
return(nmatch? nmatch: -1);
ptr = 0;
if (ch != '*')
ptr = va_arg(argp, void*);
else
ch = *fmt++;
len = 0;
size = REGULAR;
while (isdigit(ch)) {
len = len*10 + ch - '0';
ch = *fmt++;
}
if (len == 0)
len = 30000;
if (ch=='l') {
size = LONG;
ch = *fmt++;
} else if (ch=='h') {
size = SHORT;
ch = *fmt++;
} else if (ch=='L') {
size = LONGDOUBLE;
ch = *fmt++;
} else if (ch=='[')
fmt = _getccl((const unsigned char *)fmt);
if (isupper(ch)) {
/* ch = tolower(ch);
gcc gives warning: ANSI C forbids braced
groups within expressions */
ch += 'a' - 'A';
size = LONG;
}
if (ch == '\0')
return(-1);
if (_innum(ptr, ch, len, size, iop, scan_getc, scan_ungetc,
&fileended) && ptr)
nmatch++;
/* breaks %n */
/* if (fileended) {
return(nmatch? nmatch: -1);
} */
break;
case ' ':
case '\n':
case '\t':
case '\r':
case '\f':
case '\v':
while (((nchars++, ch1 = scan_getc(iop))!=EOF) && (_sctab[ch1] & SPC))
;
if (ch1 != EOF)
{
scan_ungetc(ch1, iop);
}
nchars--;
break;
 
default:
def:
ch1 = scan_getc(iop);
if (ch1 != EOF) nchars++;
if (ch1 != ch) {
if (ch1==EOF)
return(-1);
scan_ungetc(ch1, iop);
nchars--;
return(nmatch);
}
}
}
 
static int
_innum(void *ptr, int type, int len, int size, FILE *iop,
int (*scan_getc)(FILE *), int (*scan_ungetc)(int, FILE *), int *eofptr)
{
register char *np;
char numbuf[64];
register c, base;
int expseen, scale, negflg, c1, ndigit;
long lcval;
int cpos;
 
if (type=='c' || type=='s' || type=='[')
return(_instr(ptr, type, len,
iop, scan_getc, scan_ungetc, eofptr));
lcval = 0;
ndigit = 0;
scale = INT;
if (type=='e'||type=='f'||type=='g')
scale = FLOAT;
base = 10;
if (type=='o')
base = 8;
else if (type=='x')
base = 16;
np = numbuf;
expseen = 0;
negflg = 0;
while (((nchars++, c = scan_getc(iop)) != EOF) && (_sctab[c] & SPC))
;
if (c == EOF) nchars--;
if (c=='-') {
negflg++;
*np++ = c;
c = scan_getc(iop);
nchars++;
len--;
} else if (c=='+') {
len--;
c = scan_getc(iop);
nchars++;
}
cpos = 0;
for ( ; --len>=0; *np++ = c, c = scan_getc(iop), nchars++) {
cpos++;
if (c == '0' && cpos == 1 && type == 'i')
base = 8;
if ((c == 'x' || c == 'X') && (type == 'i' || type == 'x')
&& cpos == 2 && lcval == 0)
{
base = 16;
continue;
}
if (isdigit(c)
|| (base==16 && (('a'<=c && c<='f') || ('A'<=c && c<='F')))) {
ndigit++;
if (base==8)
lcval <<=3;
else if (base==10)
lcval = ((lcval<<2) + lcval)<<1;
else
lcval <<= 4;
c1 = c;
if (isdigit(c))
c -= '0';
else if ('a'<=c && c<='f')
c -= 'a'-10;
else
c -= 'A'-10;
lcval += c;
c = c1;
continue;
} else if (c=='.') {
if (base!=10 || scale==INT)
break;
ndigit++;
continue;
} else if ((c=='e'||c=='E') && expseen==0) {
if (base!=10 || scale==INT || ndigit==0)
break;
expseen++;
*np++ = c;
c = scan_getc(iop);
nchars++;
if (c!='+'&&c!='-'&&('0'>c||c>'9'))
break;
} else
break;
}
if (negflg)
lcval = -lcval;
if (c != EOF) {
scan_ungetc(c, iop);
*eofptr = 0;
} else
*eofptr = 1;
nchars--;
if (ptr==NULL || np==numbuf || (negflg && np==numbuf+1) ) /* gene dykes*/
return(0);
*np++ = 0;
switch((scale<<4) | size) {
 
case (FLOAT<<4) | SHORT:
case (FLOAT<<4) | REGULAR:
*(float *)ptr = atof(numbuf);
break;
 
case (FLOAT<<4) | LONG:
*(double *)ptr = atof(numbuf);
break;
 
case (FLOAT<<4) | LONGDOUBLE:
*(long double *)ptr = _atold(numbuf);
break;
 
case (INT<<4) | SHORT:
*(short *)ptr = (short)lcval;
break;
 
case (INT<<4) | REGULAR:
*(int *)ptr = (int)lcval;
break;
 
case (INT<<4) | LONG:
case (INT<<4) | LONGDOUBLE:
*(long *)ptr = lcval;
break;
}
return(1);
}
 
static int
_instr(char *ptr, int type, int len, FILE *iop,
int (*scan_getc)(FILE *), int (*scan_ungetc)(int, FILE *), int *eofptr)
{
register ch;
register char *optr;
int ignstp;
 
*eofptr = 0;
optr = ptr;
if (type=='c' && len==30000)
len = 1;
ignstp = 0;
if (type=='s')
ignstp = SPC;
while ((nchars++, ch = scan_getc(iop)) != EOF && _sctab[ch] & ignstp)
;
ignstp = SPC;
if (type=='c')
ignstp = 0;
else if (type=='[')
ignstp = STP;
while (ch!=EOF && (_sctab[ch]&ignstp)==0) {
if (ptr)
*ptr++ = ch;
if (--len <= 0)
break;
ch = scan_getc(iop);
nchars++;
}
if (ch != EOF) {
if (len > 0)
{
scan_ungetc(ch, iop);
nchars--;
}
*eofptr = 0;
} else
{
nchars--;
*eofptr = 1;
}
if (ptr && ptr!=optr) {
if (type!='c')
*ptr++ = '\0';
return(1);
}
return(0);
}
 
static const char *
_getccl(const unsigned char *s)
{
register c, t;
 
t = 0;
if (*s == '^') {
t++;
s++;
}
for (c = 0; c < (sizeof _sctab / sizeof _sctab[0]); c++)
if (t)
_sctab[c] &= ~STP;
else
_sctab[c] |= STP;
if ((c = *s) == ']' || c == '-') { /* first char is special */
if (t)
_sctab[c] |= STP;
else
_sctab[c] &= ~STP;
s++;
}
while ((c = *s++) != ']') {
if (c==0)
return((const char *)--s);
else if (c == '-' && *s != ']' && s[-2] < *s) {
for (c = s[-2] + 1; c < *s; c++)
if (t)
_sctab[c] |= STP;
else
_sctab[c] &= ~STP;
} else if (t)
_sctab[c] |= STP;
else
_sctab[c] &= ~STP;
}
return((const char *)s);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/fclose.c
0,0 → 1,39
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>
#include <libc/file.h>
 
int fclose(FILE *f)
{
int r;
 
r = EOF;
if (!f)
return r;
if (f->_flag & (_IOREAD|_IOWRT|_IORW)
&& !(f->_flag&_IOSTRG))
{
r = fflush(f);
if (close(fileno(f)) < 0)
r = EOF;
if (f->_flag&_IOMYBUF)
free(f->_base);
}
if (f->_flag & _IORMONCL && f->_name_to_remove)
{
remove(f->_name_to_remove);
free(f->_name_to_remove);
f->_name_to_remove = 0;
}
f->_cnt = 0;
f->_base = 0;
f->_ptr = 0;
f->_bufsiz = 0;
f->_flag = 0;
f->_file = -1;
return r;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/feof.c
0,0 → 1,10
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
#undef feof
int
feof(FILE *stream)
{
return stream->_flag & _IOEOF;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/ferror.c
0,0 → 1,9
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
#undef ferror
int ferror(FILE *stream)
{
return stream->_flag & _IOERR;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/fflush.c
0,0 → 1,41
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <unistd.h>
#include <libc/file.h>
 
int fflush(FILE *f)
{
char *base;
int n, rn;
if(!f) return 0;
if(f->std_ops && STM_OP(f,flush))
return STM_OP(f,flush)(f);
if ((f->_flag&(_IONBF|_IOWRT))==_IOWRT
&& (base = f->_base) != NULL
&& (rn = n = f->_ptr - base) > 0)
{
f->_ptr = base;
f->_cnt = (f->_flag&(_IOLBF|_IONBF)) ? 0 : f->_bufsiz;
do {
n = write(fileno(f), base, rn);
if (n <= 0) {
f->_flag |= _IOERR;
return EOF;
}
rn -= n;
base += n;
} while (rn > 0);
_dosemu_flush(fileno(f));
}
if (f->_flag & _IORW)
{
f->_cnt = 0;
f->_flag &= ~(_IOWRT|_IOREAD);
f->_ptr = f->_base;
}
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/fgetc.c
0,0 → 1,8
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
int fgetc(FILE *f)
{
return __getc(f);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/fgetpos.c
0,0 → 1,14
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <errno.h>
 
int fgetpos(FILE *stream, fpos_t *pos)
{
if (stream && pos)
{
*pos = (fpos_t)ftell(stream);
return 0;
}
errno = EFAULT;
return 1;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/fgets.c
0,0 → 1,18
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
char * fgets(char *s, int n, FILE *f)
{
int c=0;
char *cs;
cs = s;
while (--n>0 && (c = __getc(f)) != EOF)
{
*cs++ = c;
if (c == '\n') break;
}
if (c == EOF && cs == s) return NULL;
*cs++ = '\0';
return s;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/filbuf.c
0,0 → 1,62
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
#include <libc/file.h>
#include <libc/stdiohk.h>
 
int _filbuf(FILE *f)
{
int size;
char c;
 
if (f->_flag & _IORW)
f->_flag |= _IOREAD;
 
if ((f->_flag&_IOREAD) == 0)
return EOF;
if (f->_flag&(_IOSTRG|_IOEOF))
return EOF;
tryagain:
if (f->_base==NULL) {
if (f->_flag&_IONBF) {
f->_base = &c;
goto tryagain;
}
size = 512;
if ((f->_base = malloc(size)) == NULL) {
f->_flag |= _IONBF;
goto tryagain;
}
f->_flag |= _IOMYBUF;
f->_bufsiz = size;
}
if (f == stdin) {
if (stdout->_flag&_IOLBF)
fflush(stdout);
if (stderr->_flag&_IOLBF)
fflush(stderr);
}
if(f->std_ops && STM_OP(f,read))
{
f->_cnt=STM_OP(f,read)(f,f->_base,f->_flag & _IONBF ? 1 : f->_bufsiz);
} else {
f->_cnt = read(fileno(f), f->_base,f->_flag & _IONBF ? 1 : f->_bufsiz);
}
f->_ptr = f->_base;
if (f->_flag & _IONBF && f->_base == &c)
f->_base = NULL;
if (--f->_cnt < 0) {
if (f->_cnt == -1) {
f->_flag |= _IOEOF;
if (f->_flag & _IORW)
f->_flag &= ~_IOREAD;
} else
f->_flag |= _IOERR;
f->_cnt = 0;
return EOF;
}
return *f->_ptr++ & 0377;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/flsbuf.c
0,0 → 1,98
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdio.h>
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
#include <libc/file.h>
 
int
_flsbuf(int c, FILE *f)
{
char *base;
int n, rn;
char c1;
int size;
 
if (f->_flag & _IORW)
{
f->_flag |= _IOWRT;
f->_flag &= ~(_IOEOF|_IOREAD);
}
 
if ((f->_flag&_IOWRT)==0)
return EOF;
 
tryagain:
if (f->_flag&_IOLBF)
{
base = f->_base;
*f->_ptr++ = c;
if ((rn = f->_ptr - base) >= f->_bufsiz || c == '\n')
{
f->_ptr = base;
f->_cnt = 0;
}
else
{
/* we got here because _cnt is wrong, so fix it */
f->_cnt = -rn;
rn = n = 0;
}
}
else
if (f->_flag&_IONBF)
{
c1 = c;
rn = 1;
base = &c1;
f->_cnt = 0;
}
else
{
if ((base=f->_base)==NULL)
{
size = 512;
if ((f->_base=base=malloc(size)) == NULL)
{
f->_flag |= _IONBF;
goto tryagain;
}
f->_flag |= _IOMYBUF;
f->_bufsiz = size;
if (f==stdout)
{
f->_flag |= _IOLBF;
f->_ptr = base;
goto tryagain;
}
rn = n = 0;
}
else
rn = f->_ptr - base;
f->_ptr = base;
f->_cnt = f->_bufsiz;
}
while (rn > 0)
{
if(f->std_ops && STM_OP(f,write))
{
n=STM_OP(f,write)(f,base,rn);
} else {
n = write(fileno(f), base, rn);
}
if (n <= 0)
{
f->_flag |= _IOERR;
return EOF;
}
rn -= n;
base += n;
}
if ((f->_flag&(_IOLBF|_IONBF)) == 0)
{
f->_cnt--;
*f->_ptr++ = c;
}
return c;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/fopen.c
0,0 → 1,74
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <sys/types.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <libc/file.h>
#include <libc/local.h>
#include <libc/dosio.h>
 
FILE * fopen(const char *file, const char *mode)
{
FILE *f;
int fd, rw, oflags = 0;
char tbchar;
 
if (file == 0)
return 0;
if (mode == 0)
return 0;
 
f = __alloc_file();
if (f == NULL)
return NULL;
 
rw = (mode[1] == '+') || (mode[1] && (mode[2] == '+'));
 
switch (*mode)
{
case 'a':
oflags = O_CREAT | (rw ? O_RDWR : O_WRONLY);
break;
case 'r':
oflags = rw ? O_RDWR : O_RDONLY;
break;
case 'w':
oflags = O_TRUNC | O_CREAT | (rw ? O_RDWR : O_WRONLY);
break;
default:
return (NULL);
}
if (mode[1] == '+')
tbchar = mode[2];
else
tbchar = mode[1];
if (tbchar == 't')
oflags |= O_TEXT;
else if (tbchar == 'b')
oflags |= O_BINARY;
else
oflags |= (_fmode & (O_TEXT|O_BINARY));
 
fd = open(file, oflags, 0666);
if (fd < 0)
return NULL;
 
if (*mode == 'a')
lseek(fd, 0, SEEK_END);
 
f->_cnt = 0;
f->_file = fd;
f->_bufsiz = 0;
if (rw)
f->_flag = _IORW;
else if (*mode == 'r')
f->_flag = _IOREAD;
else
f->_flag = _IOWRT;
 
f->_base = f->_ptr = NULL;
f->std_ops=NULL;
// __libclog_printf("fopen: return=%x\n",f);
return f;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/fprintf.c
0,0 → 1,28
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
int
fprintf(register FILE *iop, const char *fmt, ...)
{
int len;
char localbuf[BUFSIZ];
va_list va;
va_start(va, fmt);
if (iop->_flag & _IONBF)
{
iop->_flag &= ~_IONBF;
iop->_ptr = iop->_base = localbuf;
iop->_bufsiz = BUFSIZ;
len = _doprnt(fmt, va, iop);
fflush(iop);
iop->_flag |= _IONBF;
iop->_base = NULL;
iop->_bufsiz = NULL;
iop->_cnt = 0;
}
else
len = _doprnt(fmt, va, iop);
va_end(va);
return ferror(iop) ? EOF : len;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/fputc.c
0,0 → 1,8
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
int fputc(int c, FILE *fp)
{
return __putc(c, fp);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/fputs.c
0,0 → 1,34
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
int
fputs(const char *s, FILE *f)
{
int r = 0;
int c;
int unbuffered;
char localbuf[BUFSIZ];
 
unbuffered = f->_flag & _IONBF;
if (unbuffered)
{
f->_flag &= ~_IONBF;
f->_ptr = f->_base = localbuf;
f->_bufsiz = BUFSIZ;
}
 
while ((c = *s++))
r = __putc(c, f);
 
if (unbuffered)
{
fflush(f);
f->_flag |= _IONBF;
f->_base = NULL;
f->_bufsiz = NULL;
f->_cnt = 0;
}
 
return(r);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/fread.c
0,0 → 1,39
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <stdlib.h>
#include <libc/file.h>
 
size_t fread(void *vptr, size_t size, size_t count, FILE *iop)
{
char *ptr = (char *)vptr;
int s;
int c;
 
// __libclog_printf("fread(%x,%u,%u,%x)\n",vptr,size,count,iop);
 
s = size * count;
while (s > 0) {
if (iop->_cnt < s) {
if (iop->_cnt > 0) {
memcpy(ptr, iop->_ptr, iop->_cnt);
ptr += iop->_cnt;
s -= iop->_cnt;
}
/*
* filbuf clobbers _cnt & _ptr,
* so don't waste time setting them.
*/
if ((c = _filbuf(iop)) == EOF)
break;
*ptr++ = c;
s--;
}
if (iop->_cnt >= s) {
memcpy(ptr, iop->_ptr, s);
iop->_ptr += s;
iop->_cnt -= s;
return count;
}
}
return size != 0 ? count - ((s + size - 1) / size) : 0;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/freopen.c
0,0 → 1,66
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <sys/types.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <libc/file.h>
#include <libc/dosio.h>
 
FILE *
freopen(const char *file, const char *mode, FILE *f)
{
int fd, rw, oflags=0;
char tbchar;
 
if (file == 0 || mode == 0 || f == 0)
return 0;
 
rw = (mode[1] == '+');
 
fclose(f);
 
switch (*mode) {
case 'a':
oflags = O_CREAT | (rw ? O_RDWR : O_WRONLY);
break;
case 'r':
oflags = rw ? O_RDWR : O_RDONLY;
break;
case 'w':
oflags = O_TRUNC | O_CREAT | (rw ? O_RDWR : O_WRONLY);
break;
default:
return NULL;
}
if (mode[1] == '+')
tbchar = mode[2];
else
tbchar = mode[1];
if (tbchar == 't')
oflags |= O_TEXT;
else if (tbchar == 'b')
oflags |= O_BINARY;
else
oflags |= (_fmode & (O_TEXT|O_BINARY));
 
fd = open(file, oflags, 0666);
if (fd < 0)
return NULL;
 
if (*mode == 'a')
lseek(fd, 0, SEEK_END);
 
f->_cnt = 0;
f->_file = fd;
f->_bufsiz = 0;
if (rw)
f->_flag = _IORW;
else if (*mode == 'r')
f->_flag = _IOREAD;
else
f->_flag = _IOWRT;
 
f->_base = f->_ptr = NULL;
return f;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/frlist.c
0,0 → 1,11
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/local.h>
 
static __file_rec __initial_file_rec = {
0,
3,
{ stdin, stdout, stderr }
};
 
__file_rec *__file_rec_list = &__initial_file_rec;
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/fscanf.c
0,0 → 1,15
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <stdarg.h>
#include <libc/file.h>
 
int
fscanf(FILE *f, const char *fmt, ...)
{
int r;
va_list a=0;
va_start(a, fmt);
r = _doscan(f, fmt, a);
va_end(a);
return r;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/fseek.c
0,0 → 1,40
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdio.h>
#include <unistd.h>
#include <libc/file.h>
#include <fcntl.h>
#include <libc/dosio.h>
 
int
fseek(FILE *f, long offset, int ptrname)
{
long p = -1; /* can't happen? */
if(f && f->std_ops && STM_OP(f,seek))
return STM_OP(f,seek)(f,offset,ptrname);
f->_flag &= ~_IOEOF;
if (f->_flag & _IOREAD)
{
if ((ptrname == SEEK_CUR) && f->_base && !(f->_flag & _IONBF))
{
offset += ftell(f);
ptrname = SEEK_SET;
}
 
if (f->_flag & _IORW)
{
f->_ptr = f->_base;
f->_flag &= ~_IOREAD;
}
p = lseek(fileno(f), offset, ptrname);
f->_cnt = 0;
f->_ptr = f->_base;
}
else if (f->_flag & (_IOWRT|_IORW))
{
p = fflush(f);
return lseek(fileno(f), offset, ptrname) == -1 || p == EOF ?
-1 : 0;
}
return p==-1 ? -1 : 0;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/fsetpos.c
0,0 → 1,15
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <errno.h>
 
int
fsetpos(FILE *stream, const fpos_t *pos)
{
if (stream && pos)
{
fseek(stream, (long)(*pos), SEEK_SET);
return 0;
}
errno = EFAULT;
return 1;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/ftell.c
0,0 → 1,67
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdio.h>
#include <unistd.h>
#include <libc/file.h>
#include <fcntl.h>
#include <libc/dosio.h>
 
long
ftell(FILE *f)
{
long tres;
int adjust=0;
int idx;
 
if (f->_cnt < 0)
f->_cnt = 0;
if (f->_flag&_IOREAD)
{
/* When reading files, the file position known by `lseek' is
at the end of the buffered portion of the file. So `adjust'
is negative (current buf position is BEFORE the one returned
by `lseek') and, for TEXT files, it gets decremented (larger
in absolute value) for every NL from current pos to the end
of the buffer, to account for stripped CR characters. */
adjust = - f->_cnt;
 
if (__file_handle_modes[f->_file] & O_TEXT) /* if a text file */
{
if (f->_cnt)
{
char *cp;
 
/* For every char in buf AFTER current pos... */
for (cp=f->_ptr + f->_cnt - 1; cp >= f->_ptr; cp--)
if (*cp == '\n') /* ...if it's LF... */
adjust--; /* ...there was a CR also */
}
}
}
else if (f->_flag&(_IOWRT|_IORW))
{
/* When writing a file, the current file position known by `lseek'
is at the beginning of the buffered portion of the file. We
have to adjust it by our offset from the beginning of the buffer,
and account for the CR characters which will be added by `write'. */
if (f->_flag&_IOWRT && f->_base && (f->_flag&_IONBF)==0)
{
int lastidx = adjust = f->_ptr - f->_base;
 
if (__file_handle_modes[f->_file] & O_TEXT)
for (idx=0; idx < lastidx; idx++)
if (f->_base[idx] == '\n')
adjust++;
}
}
else
return -1;
if(f && f->std_ops && STM_OP(f,seek))
tres=STM_OP(f,seek)(f,0,1);
else
tres = lseek(fileno(f), 0L, 1);
if (tres<0)
return tres;
tres += adjust;
return tres;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/fwalk.c
0,0 → 1,16
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
#include <libc/local.h>
 
void
_fwalk(void (*func)(FILE *))
{
__file_rec *fr;
int i;
 
for (fr=__file_rec_list; fr; fr=fr->next)
for (i=0; i<fr->count; i++)
if (fr->files[i]->_flag)
func(fr->files[i]);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/fwrite.c
0,0 → 1,45
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libc/file.h>
 
size_t
fwrite(const void *vptr, size_t size, size_t count, FILE *f)
{
const char *ptr = (const char *)vptr;
register int s;
 
s = size * count;
 
// __libclog_printf("fwrite(%x,%u,%u,%u)\n",vptr,size,count,f->_file);
 
if (f->_flag & _IOLBF)
while (s > 0) {
if (--f->_cnt > -f->_bufsiz && *(const char *)ptr != '\n')
*f->_ptr++ = *(const char *)ptr++;
else if (_flsbuf(*(const char *)ptr++, f) == EOF)
break;
s--;
}
else while (s > 0) {
if (f->_cnt < s) {
if (f->_cnt > 0) {
memcpy(f->_ptr, ptr, f->_cnt);
ptr += f->_cnt;
f->_ptr += f->_cnt;
s -= f->_cnt;
}
if (_flsbuf(*(const unsigned char *)ptr++, f) == EOF)
break;
s--;
}
if (f->_cnt >= s) {
memcpy(f->_ptr, ptr, s);
f->_ptr += s;
f->_cnt -= s;
return count;
}
}
return size != 0 ? count - ((s + size - 1) / size) : 0;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/getc.c
0,0 → 1,8
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
int getc(FILE *f)
{
return fgetc(f);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/getchar.c
0,0 → 1,9
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
#undef getchar
int getchar(void)
{
return fgetc(stdin);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/gets.c
0,0 → 1,17
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
 
char *
gets(char *s)
{
int c;
char *cs;
 
cs = s;
while ((c = getchar()) != '\n' && c != EOF)
*cs++ = c;
if (c == EOF && cs==s)
return NULL;
*cs++ = '\0';
return s;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/getw.c
0,0 → 1,18
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
int
getw(FILE *f)
{
int i;
char *p;
int w;
 
p = (char *)&w;
for (i=sizeof(int); --i>=0;)
*p++ = getc(f);
if (feof(f))
return EOF;
return w;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/perror.c
0,0 → 1,10
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <string.h>
#include <errno.h>
 
void
perror(const char *s)
{
fprintf(stderr, "%s: %s\n", s, strerror(errno));
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/printf.c
0,0 → 1,15
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
int
printf(const char *fmt, ...)
{
int len;
va_list va;
va_start(va, fmt);
 
len = _doprnt(fmt, va, stdout);
va_end(va);
return ferror(stdout) ? EOF : len;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/putc.c
0,0 → 1,8
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
int putc(int c, FILE *fp)
{
return fputc(c, fp);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/putchar.c
0,0 → 1,10
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
#undef putchar
int
putchar(int c)
{
return fputc(c, stdout);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/puts.c
0,0 → 1,12
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
 
int
puts(const char *s)
{
int c;
 
while ((c = *s++))
putchar(c);
return putchar('\n');
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/putw.c
0,0 → 1,15
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
int
putw(int w, FILE *f)
{
char *p;
int i;
 
p = (char *)&w;
for (i=sizeof(int); --i>=0;)
putc(*p++, f);
return ferror(f);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/remove.c
0,0 → 1,22
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <io.h>
#include <stdio.h>
#include <errno.h>
#include <libc/dosio.h>
#include <menuet/os.h>
 
int remove(const char *fn)
{
struct systree_info2 inf;
int res;
_fixpath(fn,inf.name);
inf.command = 8;
inf.file_offset_low = inf.file_offset_high = 0;
inf.size = inf.data_pointer = 0;
res = __kolibri__system_tree_access2(&inf);
if (res == 0) return 0;
if (res == 5) errno = ENOENT;
else errno = EACCES;
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/rename.c
0,0 → 1,74
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/* ------------------------- rename() for DJGPP -------------------------- */
 
/*
* An implementation of rename() which can move both files AND
* directories on the same filesystem (in the DOS world this means
* the same logical drive). Most cases are simply passed to the
* DOS Int 21h/AH=56h function. Special treatment is required for
* renaming (moving) directories which don't share their parent
* directory, because DOS won't allow this. This is called ``Prune
* and graft'' operation. Most of the code below handles this
* special case. It recursively creates subdirectories at the
* target path, moves regular files there, then deletes the (empty)
* directories at the source.
*
* An alternative (and much faster) implementation would be to access
* the parent directories of the source and the target at the disk
* sector level and rewrite them with BIOS calls. However, this won't
* work for networked drives and will leave the file system in an
* inconsistent state, should the machine crash before the operation
* is completed. (A hybrid approach which uses the fast method when
* possible and the slow one otherwise, is left as an exercise for the
* ambitious readers. ;-)
*/
 
#include <libc/stubs.h>
#include <libc/bss.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
#include <io.h>
#include <sys/stat.h>
#include <dir.h>
#include <fcntl.h>
 
// \begin{diamond}[23.02.2007]
// this is the only solution allowed by existing Kolibri system functions
// it is better than nothing :)
// But renaming of large files will be time-consuming operation...
// and renaming of directories is impossible...
 
int rename(const char *old, const char *new)
{
int f1,f2;
char* data;
int bytes;
f1 = dosemu_open(old,O_RDONLY);
if (f1 < 0) {errno = ENOENT; return -1;}
f2 = dosemu_open(new,O_WRONLY|O_CREAT|O_EXCL);
if (f2 < 0) {dosemu_close(f1); errno = EACCES; return -1;}
data = malloc(32768);
if (!data) {dosemu_close(f2); dosemu_close(f1); errno = ENOMEM; return -1;}
do
{
bytes = dosemu_read(f1, data, 32768);
if (bytes >= 0)
bytes = dosemu_write(f2, data, bytes);
} while (bytes == 32768);
free(data);
dosemu_close(f2);
dosemu_close(f1);
if (bytes == -1)
{
errno = EACCES;
return -1;
}
remove(old);
return 0;
}
 
// \end{diamond}[23.02.2007]
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/rewind.c
0,0 → 1,16
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdio.h>
#include <unistd.h>
#include <libc/file.h>
 
void rewind(FILE *f)
{
fflush(f);
lseek(fileno(f), 0L, SEEK_SET);
f->_cnt = 0;
f->_ptr = f->_base;
f->_flag &= ~(_IOERR|_IOEOF);
if (f->_flag & _IORW)
f->_flag &= ~(_IOREAD|_IOWRT);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/scanf.c
0,0 → 1,15
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <stdarg.h>
#include <libc/file.h>
 
int
scanf(const char *fmt, ...)
{
int r;
va_list a=0;
va_start(a, fmt);
r = _doscan(stdin, fmt, a);
va_end(a);
return r;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/setbuf.c
0,0 → 1,13
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <stdlib.h>
#include <libc/file.h>
 
void
setbuf(FILE *f, char *buf)
{
if (buf)
setvbuf(f, buf, _IOFBF, BUFSIZ);
else
setvbuf(f, 0, _IONBF, BUFSIZ);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/setbuffe.c
0,0 → 1,12
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdio.h>
#include <stdlib.h>
 
void setbuffer(FILE *f, void *buf, int size)
{
if (buf)
setvbuf(f, buf, _IOFBF, size);
else
setvbuf(f, 0, _IONBF, 0);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/setlineb.c
0,0 → 1,7
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
 
void setlinebuf(FILE *f)
{
setvbuf(f, 0, _IOLBF, BUFSIZ);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/setvbuf.c
0,0 → 1,48
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <stdlib.h>
#include <libc/file.h>
 
int setvbuf(FILE *f, char *buf, int type, size_t len)
{
int mine=0;
if (!f)
return -1;
fflush(f);
switch (type)
{
case _IOFBF:
case _IOLBF:
if (len <= 0)
return -1;
if (buf == 0)
{
buf = (char *)malloc(len);
if (buf == 0)
return -1;
mine = 1;
}
case _IONBF:
if (f->_base != NULL && f->_flag & _IOMYBUF)
free(f->_base);
f->_cnt = 0;
 
f->_flag &= ~(_IONBF|_IOFBF|_IOLBF);
f->_flag |= type;
if (type != _IONBF)
{
if (mine)
f->_flag |= _IOMYBUF;
f->_ptr = f->_base = buf;
f->_bufsiz = len;
}
else
{
f->_base = 0;
f->_bufsiz = 0;
}
return 0;
default:
return -1;
}
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/sprintf.c
0,0 → 1,21
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <limits.h>
#include <libc/file.h>
 
int
sprintf(char *str, const char *fmt, ...)
{
FILE _strbuf;
int len;
va_list va;
va_start(va, fmt);
 
_strbuf._flag = _IOWRT|_IOSTRG;
_strbuf._ptr = str;
_strbuf._cnt = INT_MAX;
len = _doprnt(fmt, va, &_strbuf);
va_end(va);
*_strbuf._ptr = 0;
return len;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/sscanf.c
0,0 → 1,25
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <stdarg.h>
#include <libc/file.h>
#include <libc/unconst.h>
 
int
sscanf(const char *str, const char *fmt, ...)
{
int r;
va_list a=0;
FILE _strbuf;
 
va_start(a, fmt);
 
_strbuf._flag = _IOREAD|_IOSTRG;
_strbuf._ptr = _strbuf._base = unconst(str, char *);
_strbuf._cnt = 0;
while (*str++)
_strbuf._cnt++;
_strbuf._bufsiz = _strbuf._cnt;
r = _doscan(&_strbuf, fmt, a);
va_end(a);
return r;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/stdaux.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
#include <libc/stdiohk.h>
 
FILE __dj_stdaux = {
0, 0, 0, 0,
_IORW | _IONBF,
4
};
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/stderr.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
#include <libc/stdiohk.h>
 
FILE __dj_stderr = {
0, 0, 0, 0,
_IOWRT | _IONBF,
2
};
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/stdin.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
#include <libc/stdiohk.h>
 
FILE __dj_stdin = {
0, 0, 0, 0,
_IOREAD | _IOLBF,
0
};
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/stdiohk.c
0,0 → 1,18
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
#include <libc/local.h>
 
static void fcloseall_helper(FILE *f)
{
fflush(f);
if (fileno(f) > 2)
fclose(f);
}
 
void __stdio_cleanup_proc(void)
{
_fwalk(fcloseall_helper);
}
 
void (*__stdio_cleanup_hook)(void) = __stdio_cleanup_proc;
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/stdout.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
#include <libc/stdiohk.h>
 
FILE __dj_stdout = {
0, 0, 0, 0,
_IOWRT | _IOFBF,
1
};
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/stdprn.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
#include <libc/stdiohk.h>
 
FILE __dj_stdprn = {
0, 0, 0, 0,
_IOWRT | _IOLBF,
3
};
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/tmpfile.c
0,0 → 1,32
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <libc/file.h>
 
FILE *
tmpfile(void)
{
FILE *f;
char *temp_name;
char *n_t_r;
 
temp_name = tmpnam(0);
if (temp_name == 0)
return 0;
 
n_t_r = (char *)malloc(strlen(temp_name)+1);
if (!n_t_r)
return 0;
 
f = fopen(temp_name, (_fmode & O_TEXT) ? "wt+" : "wb+");
if (f)
{
f->_flag |= _IORMONCL;
f->_name_to_remove = n_t_r;
strcpy(f->_name_to_remove, temp_name);
}
return f;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/tmpnam.c
0,0 → 1,71
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <libc/bss.h>
 
static char *tmp_dir;
static int tmp_len;
static int tmp_bss_count = -1;
 
static void
try(const char *var)
{
static char buf[L_tmpnam];
 
char *t = getenv(var);
if (t == 0)
return;
 
tmp_len = strlen(t);
strcpy(buf, t);
if (buf[tmp_len - 1] != '/' && buf[tmp_len - 1] != '\\')
buf[tmp_len++] = '/', buf[tmp_len] = 0;
 
if (access(buf, D_OK))
return;
 
tmp_dir = buf;
}
 
char *
tmpnam(char *s)
{
static char static_buf[L_tmpnam];
static char tmpcount[] = "dj000000";
int i;
 
if (tmp_bss_count != __bss_count)
{
tmp_bss_count = __bss_count;
 
if (tmp_dir == 0) try("TMPDIR");
if (tmp_dir == 0) try("TEMP");
if (tmp_dir == 0) try("TMP");
if (tmp_dir == 0)
{
static char def[] = "c:/";
tmp_dir = def;
tmp_len = 3;
}
}
 
if (!s)
s = static_buf;
strcpy(s, tmp_dir);
 
do {
/* increment the "count" starting at the first digit (backwards order) */
for (i=2; tmpcount[i] == '9' && i < 8; tmpcount[i] = '0', i++);
if (i < 8)
tmpcount[i]++;
 
strcpy(s+tmp_len, tmpcount);
 
} while (access(s, F_OK)==0); /* until file doesn't exist */
 
return s;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/ungetc.c
0,0 → 1,26
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
int
ungetc(int c, FILE *f)
{
if (c == EOF
|| (f->_flag & (_IOREAD|_IORW)) == 0
|| f->_ptr == NULL
|| f->_base == NULL)
return EOF;
 
if (f->_ptr == f->_base)
{
if (f->_cnt == 0)
f->_ptr++;
else
return EOF;
}
 
f->_cnt++;
*--f->_ptr = c;
 
return c;
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/vfprintf.c
0,0 → 1,27
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <stdarg.h>
#include <libc/file.h>
 
int
vfprintf(FILE *f, const char *fmt, va_list ap)
{
int len;
char localbuf[BUFSIZ];
 
if (f->_flag & _IONBF)
{
f->_flag &= ~_IONBF;
f->_ptr = f->_base = localbuf;
f->_bufsiz = BUFSIZ;
len = _doprnt(fmt, ap, f);
(void)fflush(f);
f->_flag |= _IONBF;
f->_base = NULL;
f->_bufsiz = 0;
f->_cnt = 0;
}
else
len = _doprnt(fmt, ap, f);
return (ferror(f) ? EOF : len);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/vprintf.c
0,0 → 1,13
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <stdarg.h>
#include <libc/file.h>
 
int
vprintf(const char *fmt, va_list ap)
{
int len;
 
len = _doprnt(fmt, ap, stdout);
return (ferror(stdout) ? EOF : len);
}
/programs/develop/libraries/menuetlibc/src/libc/ansi/stdio/vsprintf.c
0,0 → 1,19
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <stdarg.h>
#include <limits.h>
#include <libc/file.h>
 
int
vsprintf(char *str, const char *fmt, va_list ap)
{
FILE f;
int len;
 
f._flag = _IOWRT|_IOSTRG;
f._ptr = str;
f._cnt = INT_MAX;
len = _doprnt(fmt, ap, &f);
*f._ptr = 0;
return len;
}