Little bugfixes to userland
authorJohn Hodge <[email protected]>
Sun, 20 May 2012 08:52:11 +0000 (16:52 +0800)
committerJohn Hodge <[email protected]>
Sun, 20 May 2012 08:52:11 +0000 (16:52 +0800)
Usermode/Applications/cat_src/main.c
Usermode/Libraries/libc.so_src/fileIO.c
Usermode/Libraries/libreadline.so_src/main.c

index a389c10..443a5de 100644 (file)
@@ -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 <file>\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);
index 441e72e..776a2de 100644 (file)
@@ -154,27 +154,14 @@ EXPORT int vfprintf(FILE *fp, const char *format, va_list args)
 {\r
        va_list tmpList;\r
         int    size;\r
-       char    sbuf[1024];\r
-       char    *buf = sbuf;\r
 \r
        if(!fp || !format)      return -1;\r
 \r
        va_copy(tmpList, args);\r
        \r
-       size = vsnprintf(sbuf, sizeof(sbuf), (char*)format, tmpList);\r
-       \r
-       if( size >= sizeof(sbuf) )\r
-       {\r
-               buf = (char*)malloc(size+1);\r
-               if(!buf) {\r
-                       WRITE_STR(_stdout, "vfprintf ERROR: malloc() failed");\r
-                       return 0;\r
-               }\r
-               buf[size] = '\0';\r
-       \r
-               // Print\r
-               vsnprintf(buf, size+1, (char*)format, args);\r
-       }\r
+       size = vsnprintf(NULL, 0, (char*)format, tmpList);\r
+       char    buf[size+1];\r
+       vsnprintf(buf, size+1, (char*)format, args);\r
        \r
        // Write to stream\r
        write(fp->FD, buf, size);\r
@@ -543,29 +530,17 @@ EXPORT int printf(const char *format, ...)
 {\r
        #if 1\r
         int    size;\r
-       char    sbuf[1024];\r
-       char    *buf = sbuf;\r
        va_list args;\r
        \r
        // Get final size\r
        va_start(args, format);\r
-       size = vsnprintf(sbuf, 1024, (char*)format, args);\r
+       size = vsnprintf(NULL, 0, (char*)format, args);\r
+       va_end(args);\r
+       char buf[size+1];\r
+       // Fill Buffer\r
+       va_start(args, format);\r
+       vsnprintf(buf, size+1, (char*)format, args);\r
        va_end(args);\r
-       \r
-       if( size >= 1024 ) {\r
-               // Allocate buffer\r
-               buf = (char*)malloc(size+1);\r
-               if(buf) {\r
-                       WRITE_STR(_stdout, "PRINTF ERROR: malloc() failed\n");\r
-                       return 0;\r
-               }\r
-               buf[size] = '\0';\r
-       \r
-               // Fill Buffer\r
-               va_start(args, format);\r
-               vsnprintf(buf, size+1, (char*)format, args);\r
-               va_end(args);\r
-       }\r
        \r
        // Send to stdout\r
        write(_stdout, buf, size+1);\r
index 1408eef..719667d 100644 (file)
@@ -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;
        

UCC git Repository :: git.ucc.asn.au