From b4335679cb7e7f9ab5631864da47e78273dfd5bc Mon Sep 17 00:00:00 2001 From: Ben Gras Date: Wed, 1 Jun 2005 09:36:07 +0000 Subject: [PATCH] Added sys_physzero library call for corresponding system call; modified system-printf() so it returns number of characters printed (for use in smart formatting) --- lib/other/asynchio.c | 2 +- lib/syslib/Makefile | 4 ++++ lib/syslib/kprintf.c | 22 ++++++++++++---------- lib/syslib/sys_physzero.c | 16 ++++++++++++++++ 4 files changed, 33 insertions(+), 11 deletions(-) create mode 100644 lib/syslib/sys_physzero.c diff --git a/lib/other/asynchio.c b/lib/other/asynchio.c index aed3ecb1d..77141080d 100755 --- a/lib/other/asynchio.c +++ b/lib/other/asynchio.c @@ -14,12 +14,12 @@ #define time _time #define write _write #include +#include #include #include #include #include #include -#include #include #define IDLE 0 diff --git a/lib/syslib/Makefile b/lib/syslib/Makefile index ff51fe076..d6bc2ae18 100755 --- a/lib/syslib/Makefile +++ b/lib/syslib/Makefile @@ -45,6 +45,7 @@ OBJECTS = \ $(LIBSYS)(sys_signalrm.o) \ $(LIBSYS)(sys_flagalrm.o) \ $(LIBSYS)(sys_syncalrm.o) \ + $(LIBSYS)(sys_physzero.o) \ $(LIBSYS)(taskcall.o) \ $(LIBSYS): $(OBJECTS) @@ -165,6 +166,9 @@ $(LIBSYS)(sys_flagalrm.o): sys_flagalrm.c $(LIBSYS)(sys_syncalrm.o): sys_syncalrm.c $(CC1) sys_syncalrm.c +$(LIBSYS)(sys_physzero.o): sys_physcp.c + $(CC1) sys_physzero.c + $(LIBSYS)(taskcall.o): taskcall.c $(CC1) taskcall.c diff --git a/lib/syslib/kprintf.c b/lib/syslib/kprintf.c index 5428b75d8..8341474e9 100755 --- a/lib/syslib/kprintf.c +++ b/lib/syslib/kprintf.c @@ -17,10 +17,12 @@ int printf(fmt) char *fmt; /* Printf() uses kputc() to print characters. */ void kputc(int c); +#define count_kputc(c) do { charcount++; kputc(c); } while(0) + int printf(const char *fmt, ...) #endif { - int c; + int c, charcount = 0; enum { LEFT, RIGHT } adjust; enum { LONG, INT } intsize; int fill; @@ -40,7 +42,7 @@ int printf(const char *fmt, ...) while ((c= *fmt++) != 0) { if (c != '%') { /* Ordinary character. */ - kputc(c); + count_kputc(c); continue; } @@ -162,26 +164,26 @@ int printf(const char *fmt, ...) string_print: width -= len; if (i < 0) width--; - if (fill == '0' && i < 0) kputc('-'); + if (fill == '0' && i < 0) count_kputc('-'); if (adjust == RIGHT) { - while (width > 0) { kputc(fill); width--; } + while (width > 0) { count_kputc(fill); width--; } } - if (fill == ' ' && i < 0) kputc('-'); - while (len > 0) { kputc((unsigned char) *p++); len--; } - while (width > 0) { kputc(fill); width--; } + if (fill == ' ' && i < 0) count_kputc('-'); + while (len > 0) { count_kputc((unsigned char) *p++); len--; } + while (width > 0) { count_kputc(fill); width--; } break; /* Unrecognized format key, echo it back. */ default: - kputc('%'); - kputc(c); + count_kputc('%'); + count_kputc(c); } } /* Mark the end with a null (should be something else, like -1). */ kputc(0); va_end(argp); - return 0; + return charcount; } /* diff --git a/lib/syslib/sys_physzero.c b/lib/syslib/sys_physzero.c new file mode 100644 index 000000000..ef542e5ec --- /dev/null +++ b/lib/syslib/sys_physzero.c @@ -0,0 +1,16 @@ +#include "syslib.h" + +PUBLIC int sys_physzero(phys_bytes base, phys_bytes bytes) +{ +/* Zero a block of data. */ + + message mess; + + if (bytes == 0L) return(OK); + + mess.PZ_MEM_PTR = (char *) base; + mess.PZ_COUNT = bytes; + + return(_taskcall(SYSTASK, SYS_PHYSZERO, &mess)); +} + -- 2.44.0