From: John Hodge Date: Sun, 20 May 2012 08:52:11 +0000 (+0800) Subject: Little bugfixes to userland X-Git-Tag: rel0.15~611^2~81 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=64b23ba9b7febed7769c573eeae56357adccc498;p=tpg%2Facess2.git Little bugfixes to userland --- diff --git a/Usermode/Applications/cat_src/main.c b/Usermode/Applications/cat_src/main.c index a389c108..443a5dee 100644 --- a/Usermode/Applications/cat_src/main.c +++ b/Usermode/Applications/cat_src/main.c @@ -15,7 +15,7 @@ int main(int argc, char *argv[]) { int fd; int num; - char buf[BUF_SIZE+1]; + char buf[BUF_SIZE]; if(argc < 2) { printf("Usage: cat \n"); @@ -31,8 +31,7 @@ int main(int argc, char *argv[]) do { num = read(fd, buf, BUF_SIZE); if(num < 0) break; - buf[num] = '\0'; - printf("%s", buf); + write(1, buf, num); } while(num == BUF_SIZE); close(fd); diff --git a/Usermode/Libraries/libc.so_src/fileIO.c b/Usermode/Libraries/libc.so_src/fileIO.c index 441e72e0..776a2def 100644 --- a/Usermode/Libraries/libc.so_src/fileIO.c +++ b/Usermode/Libraries/libc.so_src/fileIO.c @@ -154,27 +154,14 @@ EXPORT int vfprintf(FILE *fp, const char *format, va_list args) { va_list tmpList; int size; - char sbuf[1024]; - char *buf = sbuf; if(!fp || !format) return -1; va_copy(tmpList, args); - size = vsnprintf(sbuf, sizeof(sbuf), (char*)format, tmpList); - - if( size >= sizeof(sbuf) ) - { - buf = (char*)malloc(size+1); - if(!buf) { - WRITE_STR(_stdout, "vfprintf ERROR: malloc() failed"); - return 0; - } - buf[size] = '\0'; - - // Print - vsnprintf(buf, size+1, (char*)format, args); - } + size = vsnprintf(NULL, 0, (char*)format, tmpList); + char buf[size+1]; + vsnprintf(buf, size+1, (char*)format, args); // Write to stream write(fp->FD, buf, size); @@ -543,29 +530,17 @@ EXPORT int printf(const char *format, ...) { #if 1 int size; - char sbuf[1024]; - char *buf = sbuf; va_list args; // Get final size va_start(args, format); - size = vsnprintf(sbuf, 1024, (char*)format, args); + size = vsnprintf(NULL, 0, (char*)format, args); + va_end(args); + char buf[size+1]; + // Fill Buffer + va_start(args, format); + vsnprintf(buf, size+1, (char*)format, args); va_end(args); - - if( size >= 1024 ) { - // Allocate buffer - buf = (char*)malloc(size+1); - if(buf) { - WRITE_STR(_stdout, "PRINTF ERROR: malloc() failed\n"); - return 0; - } - buf[size] = '\0'; - - // Fill Buffer - va_start(args, format); - vsnprintf(buf, size+1, (char*)format, args); - va_end(args); - } // Send to stdout write(_stdout, buf, size+1); diff --git a/Usermode/Libraries/libreadline.so_src/main.c b/Usermode/Libraries/libreadline.so_src/main.c index 1408eef7..719667d7 100644 --- a/Usermode/Libraries/libreadline.so_src/main.c +++ b/Usermode/Libraries/libreadline.so_src/main.c @@ -260,6 +260,10 @@ int Readline_int_ParseCharacter(tReadline *Info, char *Input) write(STDOUT_FD, "\x1B[C", 3); break; } + break; + case '\0': + ofs --; + break; } break;