diff --git a/modules/src/print/doprnt.c b/modules/src/print/doprnt.c index a5f6d9384..dd7092232 100644 --- a/modules/src/print/doprnt.c +++ b/modules/src/print/doprnt.c @@ -5,14 +5,15 @@ /* $Header$ */ #include +#include #include "param.h" doprnt(fp, fmt, argp) File *fp; char *fmt; - int argp[]; + va_list argp; { char buf[SSIZE]; - sys_write(fp, buf, _format(buf, fmt, (char *)argp)); + sys_write(fp, buf, _format(buf, fmt, argp)); } diff --git a/modules/src/print/format.c b/modules/src/print/format.c index 6faf5d46e..34aabbb02 100644 --- a/modules/src/print/format.c +++ b/modules/src/print/format.c @@ -4,6 +4,8 @@ */ /* $Header$ */ +#include + char *long2str(); static int @@ -27,9 +29,9 @@ integral(c) int _format(buf, fmt, argp) char *buf, *fmt; - char *argp; + register va_list argp; { - register char *pf = fmt, *pa = argp; + register char *pf = fmt; register char *pb = buf; while (*pf) { @@ -52,24 +54,20 @@ _format(buf, fmt, argp) while (*pf >= '0' && *pf <= '9') width = 10 * width + *pf++ - '0'; - /* get text and move pa */ if (*pf == 's') { - arg = *(char **)pa; - pa += sizeof(char *); + arg = va_arg(argp, char *); } else if (*pf == 'c') { - cbuf[0] = * (int *) pa; + cbuf[0] = va_arg(argp, int); cbuf[1] = '\0'; - pa += sizeof(int); arg = &cbuf[0]; } else if (*pf == 'l') { /* alignment ??? */ if (base = integral(*++pf)) { - arg = long2str(*(long *)pa, base); - pa += sizeof(long); + arg = long2str(va_arg(argp,long), base); } else { pf--; @@ -78,8 +76,7 @@ _format(buf, fmt, argp) } else if (base = integral(*pf)) { - arg = long2str((long)*(int *)pa, base); - pa += sizeof(int); + arg = long2str((long)va_arg(argp,int), base); } else if (*pf == '%') diff --git a/modules/src/print/fprint.c b/modules/src/print/fprint.c index 3624bdb83..51d472fdb 100644 --- a/modules/src/print/fprint.c +++ b/modules/src/print/fprint.c @@ -4,16 +4,23 @@ */ /* $Header$ */ +#include #include #include "param.h" /*VARARGS1*/ -fprint(fp, fmt, args) +fprint(va_alist) + va_dcl +{ File *fp; char *fmt; - int args; -{ + va_list args; + char buf[SSIZE]; - sys_write(fp, buf, _format(buf, fmt, &args)); + va_start(args); + fp = va_arg(args, File *); + fmt = va_arg(args, char *); + sys_write(fp, buf, _format(buf, fmt, args)); + va_end(args); } diff --git a/modules/src/print/print.3 b/modules/src/print/print.3 index 95cdf7190..fe6e57a0e 100644 --- a/modules/src/print/print.3 +++ b/modules/src/print/print.3 @@ -5,6 +5,7 @@ print, fprint, sprint, doprnt -- very simple formatted-output routines .SH SYNOPSIS .nf .B #include +.B #include .PP .B print(format [, arg] ... ) .B char *format; @@ -19,7 +20,7 @@ print, fprint, sprint, doprnt -- very simple formatted-output routines .B doprnt(filep, format, args) .B File *filep; .B char *format; -.B int args[]; +.B va_list args; .fi .SH DESCRIPTION .I Print diff --git a/modules/src/print/print.c b/modules/src/print/print.c index 089d2b023..44c969e2a 100644 --- a/modules/src/print/print.c +++ b/modules/src/print/print.c @@ -4,15 +4,20 @@ */ /* $Header$ */ +#include #include #include "param.h" /*VARARGS1*/ -print(fmt, args) - char *fmt; - int args; +print(va_alist) + va_dcl { + char *fmt; + va_list args; char buf[SSIZE]; - sys_write(STDOUT, buf, _format(buf, fmt, &args)); + va_start(args); + fmt = va_arg(args, char *); + sys_write(STDOUT, buf, _format(buf, fmt, args)); + va_end(args); } diff --git a/modules/src/print/sprint.c b/modules/src/print/sprint.c index 97ad7e0d5..4bee99b57 100644 --- a/modules/src/print/sprint.c +++ b/modules/src/print/sprint.c @@ -4,15 +4,22 @@ */ /* $Header$ */ +#include #include #include "param.h" /*VARARGS1*/ char * -sprint(buf, fmt, args) - char *buf, *fmt; - int args; +sprint(va_alist) + va_dcl { - buf[_format(buf, fmt, &args)] = '\0'; + char *buf, *fmt; + va_list args; + + va_start(args); + buf = va_arg(args, char *); + fmt = va_arg(args, char *); + buf[_format(buf, fmt, args)] = '\0'; + va_end(args); return buf; }