Usermode - Switched to the POSIX read()/write() argument order
authorJohn Hodge <[email protected]>
Mon, 8 Aug 2011 08:52:15 +0000 (16:52 +0800)
committerJohn Hodge <[email protected]>
Mon, 8 Aug 2011 08:52:15 +0000 (16:52 +0800)
16 files changed:
Usermode/Applications/CLIShell_src/main.c
Usermode/Applications/axwin2_src/WM/input.c
Usermode/Applications/axwin2_src/WM/messages.c
Usermode/Applications/axwin2_src/WM/video.c
Usermode/Applications/cat_src/main.c
Usermode/Applications/irc_src/main.c
Usermode/Applications/pcidump_src/main.c
Usermode/Applications/telnet_src/main.c
Usermode/Libraries/ld-acess.so_src/common.h
Usermode/Libraries/libc.so_src/fileIO.c
Usermode/Libraries/libgcc.so_src/libgcc.c
Usermode/Libraries/libreadline.so_src/main.c
Usermode/include/acess/sys.h
Usermode/include/stdint.h
Usermode/include/stdio.h
Usermode/include/sys/sys.h

index af81782..807527b 100644 (file)
@@ -77,8 +77,7 @@ int main(int argc, char *argv[], char *envp[])
                }\r
        }       \r
        \r
-       write(_stdout, 22, "Acess Shell Version 3\n");\r
-       write(_stdout,  2, "\n");\r
+       printf("Acess Shell Version 3\n\n");\r
        for(;;)\r
        {\r
                // Free last command & arguments\r
@@ -88,8 +87,7 @@ int main(int argc, char *argv[], char *envp[])
                bCached = 0;\r
                #endif\r
                \r
-               write(_stdout, strlen(gsCurrentDirectory), gsCurrentDirectory);\r
-               write(_stdout, 2, "$ ");\r
+               printf("%s$ ", gsCurrentDirectory);\r
                \r
                // Read Command line\r
                #if USE_READLINE\r
@@ -100,7 +98,7 @@ int main(int argc, char *argv[], char *envp[])
                sCommandStr = ReadCommandLine( &length );\r
                \r
                if(!sCommandStr) {\r
-                       write(_stdout, 25, "PANIC: Out of heap space\n");\r
+                       printf("PANIC: Out of heap space\n");\r
                        return -1;\r
                }\r
                \r
@@ -147,6 +145,7 @@ int main(int argc, char *argv[], char *envp[])
        }\r
 }\r
 \r
+#if USE_READLINE\r
 /**\r
  * \fn char *ReadCommandLine(int *Length)\r
  * \brief Read from the command line\r
@@ -167,21 +166,20 @@ char *ReadCommandLine(int *Length)
                \r
        // Read In Command Line\r
        do {\r
-               read(_stdin, 1, &ch);   // Read Character from stdin (read is a blocking call)\r
-               \r
+               ch = getchar(); // Read Character from stdin (read is a blocking call)\r
                if(ch == '\n')  break;\r
                \r
                switch(ch)\r
                {\r
                // Control characters\r
                case '\x1B':\r
-                       read(_stdin, 1, &ch);   // Read control character\r
+                       ch = getchar(); // Read control character\r
                        switch(ch)\r
                        {\r
                        //case 'D':     if(pos) pos--;  break;\r
                        //case 'C':     if(pos<len)     pos++;  break;\r
                        case '[':\r
-                               read(_stdin, 1, &ch);   // Read control character\r
+                               ch = getchar(); // Read control character\r
                                switch(ch)\r
                                {\r
                                #if 0\r
@@ -194,7 +192,7 @@ char *ReadCommandLine(int *Length)
                                                ret = strdup( gasCommandHistory[--scrollbackPos] );\r
                                                \r
                                                len = strlen(ret);\r
-                                               while(pos--)    write(_stdout, 3, "\x1B[D");\r
+                                               while(pos--)    printf("\x1B[D");\r
                                                write(_stdout, len, ret);       pos = len;\r
                                                while(pos++ < oldLen)   write(_stdout, 1, " ");\r
                                        }\r
@@ -217,12 +215,12 @@ char *ReadCommandLine(int *Length)
                                case 'D':       // Left\r
                                        if(pos == 0)    break;\r
                                        pos --;\r
-                                       write(_stdout, 3, "\x1B[D");\r
+                                       printf("\x1B[D");\r
                                        break;\r
                                case 'C':       // Right\r
                                        if(pos == len)  break;\r
                                        pos++;\r
-                                       write(_stdout, 3, "\x1B[C");\r
+                                       printf("\x1B[C");\r
                                        break;\r
                                }\r
                        }\r
@@ -231,19 +229,14 @@ char *ReadCommandLine(int *Length)
                // Backspace\r
                case '\b':\r
                        if(len <= 0)            break;  // Protect against underflows\r
-                       write(_stdout, 1, &ch);\r
+                       putchar(ch);\r
                        if(pos == len) {        // Simple case of end of string\r
                                len --;\r
                                pos--;\r
                        }\r
                        else {\r
-                               char    buf[7] = "\x1B[000D";\r
-                               buf[2] += ((len-pos+1)/100) % 10;\r
-                               buf[3] += ((len-pos+1)/10) % 10;\r
-                               buf[4] += (len-pos+1) % 10;\r
-                               write(_stdout, len-pos, &ret[pos]);     // Move Text\r
-                               ch = ' ';       write(_stdout, 1, &ch); ch = '\b';      // Clear deleted character\r
-                               write(_stdout, 7, buf); // Update Cursor\r
+                               printf("%.*s ", len-pos, &ret[pos]);    // Move Text\r
+                               printf("\x1B[%iD", len-pos+1);\r
                                // Alter Buffer\r
                                memmove(&ret[pos-1], &ret[pos], len-pos);\r
                                pos --;\r
@@ -267,17 +260,13 @@ char *ReadCommandLine(int *Length)
                        \r
                        // Editing inside the buffer\r
                        if(pos != len) {\r
-                               char    buf[7] = "\x1B[000D";\r
-                               buf[2] += ((len-pos)/100) % 10;\r
-                               buf[3] += ((len-pos)/10) % 10;\r
-                               buf[4] += (len-pos) % 10;\r
-                               write(_stdout, 1, &ch); // Print new character\r
-                               write(_stdout, len-pos, &ret[pos]);     // Move Text\r
-                               write(_stdout, 7, buf); // Update Cursor\r
+                               putchar(ch);    // Print new character\r
+                               printf("%.*s", len-pos, &ret[pos]);     // Move Text\r
+                               printf("\x1B[%iD", len-pos);\r
                                memmove( &ret[pos+1], &ret[pos], len-pos );\r
                        }\r
                        else {\r
-                               write(_stdout, 1, &ch);\r
+                               putchar(ch);\r
                        }\r
                        ret[pos++] = ch;\r
                        len ++;\r
@@ -294,6 +283,7 @@ char *ReadCommandLine(int *Length)
        \r
        return ret;\r
 }\r
+#endif\r
 \r
 /**\r
  * \fn void Parse_Args(char *str, char **dest)\r
@@ -306,7 +296,7 @@ void Parse_Args(char *str, char **dest)
        \r
        if(buf == NULL) {\r
                dest[0] = NULL;\r
-               Print("Parse_Args: Out of heap space!\n");\r
+               printf("Parse_Args: Out of heap space!\n");\r
                return ;\r
        }\r
        \r
@@ -360,7 +350,7 @@ void CallCommand(char **Args)
                // Check file existence\r
                fd = open(sTmpBuffer, OPENFLAG_EXEC);\r
                if(fd == -1) {\r
-                       Print("Unknown Command: `");Print(Args[0]);Print("'\n");        // Error Message\r
+                       printf("Unknown Command: `%s'\n", Args[0]);     // Error Message\r
                        return ;\r
                }\r
                \r
@@ -370,8 +360,7 @@ void CallCommand(char **Args)
                \r
                // Check if the file is a directory\r
                if(info.flags & FILEFLAG_DIRECTORY) {\r
-                       Print("`");Print(sTmpBuffer);   // Error Message\r
-                       Print("' is a directory.\n");\r
+                       printf("`%s' is a directory.\n", sTmpBuffer);\r
                        return ;\r
                }\r
        }\r
@@ -394,7 +383,7 @@ void CallCommand(char **Args)
                \r
                // Exhausted path directories\r
                if( i == giNumPathDirs ) {\r
-                       Print("Unknown Command: `");Print(exefile);Print("'\n");\r
+                       printf("Unknown Command: `%s'\n", exefile);\r
                        return ;\r
                }\r
        }\r
@@ -405,7 +394,7 @@ void CallCommand(char **Args)
        if(pid == 0)\r
                execve(sTmpBuffer, Args, gasEnvironment);\r
        if(pid <= 0) {\r
-               Print("Unablt to create process: `");Print(sTmpBuffer);Print("'\n");    // Error Message\r
+               printf("Unable to create process: `%s'\n", sTmpBuffer); // Error Message\r
        }\r
        else {\r
                 int    status;\r
@@ -428,17 +417,16 @@ void Command_Logout(int argc, char **argv)
  */\r
 void Command_Help(int argc, char **argv)\r
 {\r
-       Print("Acess 2 Command Line Interface\n");\r
-       Print(" By John Hodge (thePowersGang / [TPG])\n");\r
-       Print("\n");\r
-       Print("Builtin Commands:\n");\r
-       Print(" logout: Return to the login prompt\n");\r
-       Print(" exit:   Same\n");\r
-       Print(" help:   Display this message\n");\r
-       Print(" clear:  Clear the screen\n");\r
-       Print(" cd:     Change the current directory\n");\r
-       Print(" dir:    Print the contents of the current directory\n");\r
-       //Print("\n");\r
+       printf( "Acess 2 Command Line Interface\n"\r
+               " By John Hodge (thePowersGang / [TPG])\n"\r
+               "\n"\r
+               "Builtin Commands:\n"\r
+               " logout: Return to the login prompt\n"\r
+               " exit:   Same\n"\r
+               " help:   Display this message\n"\r
+               " clear:  Clear the screen\n"\r
+               " cd:     Change the current directory\n"\r
+               " dir:    Print the contents of the current directory\n");\r
        return;\r
 }\r
 \r
@@ -448,7 +436,7 @@ void Command_Help(int argc, char **argv)
  */\r
 void Command_Clear(int argc, char **argv)\r
 {\r
-       write(_stdout, 4, "\x1B[2J");   //Clear Screen\r
+       write(_stdout, "\x1B[2J", 4);   //Clear Screen\r
 }\r
 \r
 /**\r
@@ -463,7 +451,7 @@ void Command_Cd(int argc, char **argv)
        \r
        if(argc < 2)\r
        {\r
-               Print(gsCurrentDirectory);Print("\n");\r
+               printf("%s\n", gsCurrentDirectory);\r
                return;\r
        }\r
        \r
@@ -471,14 +459,14 @@ void Command_Cd(int argc, char **argv)
        \r
        fp = open(tmpPath, 0);\r
        if(fp == -1) {\r
-               write(_stdout, 26, "Directory does not exist\n");\r
+               printf("Directory does not exist\n");\r
                return;\r
        }\r
        finfo(fp, &stats, 0);\r
        close(fp);\r
        \r
        if( !(stats.flags & FILEFLAG_DIRECTORY) ) {\r
-               write(_stdout, 17, "Not a Directory\n");\r
+               printf("Not a Directory\n");\r
                return;\r
        }\r
        \r
@@ -524,16 +512,14 @@ void Command_Dir(int argc, char **argv)
        if( finfo(dp, &info, 0) == -1 )\r
        {\r
                close(dp);\r
-               write(_stdout, 34, "stat Failed, Bad File Descriptor\n");\r
+               printf("stat Failed, Bad File Descriptor\n");\r
                return;\r
        }\r
        // Check if it's a directory\r
        if(!(info.flags & FILEFLAG_DIRECTORY))\r
        {\r
                close(dp);\r
-               write(_stdout, 27, "Unable to open directory `");\r
-               write(_stdout, strlen(tmpPath)+1, tmpPath);\r
-               write(_stdout, 20, "', Not a directory\n");\r
+               printf("Unable to open directory `%s', Not a directory\n", tmpPath);\r
                return;\r
        }\r
        \r
@@ -551,7 +537,7 @@ void Command_Dir(int argc, char **argv)
                if(fp < 0)\r
                {\r
                        if(fp == -3)\r
-                               write(_stdout, 42, "Invalid Permissions to traverse directory\n");\r
+                               printf("Invalid Permissions to traverse directory\n");\r
                        break;\r
                }\r
                // Open File\r
@@ -561,9 +547,9 @@ void Command_Dir(int argc, char **argv)
                finfo(fp, &info, 0);\r
                \r
                if(info.flags & FILEFLAG_DIRECTORY)\r
-                       write(_stdout, 1, "d");\r
+                       printf("d");\r
                else\r
-                       write(_stdout, 1, "-");\r
+                       printf("-");\r
                \r
                // Print Mode\r
                // - Owner\r
@@ -584,26 +570,26 @@ void Command_Dir(int argc, char **argv)
                if(acl.perms & 1)       modeStr[6] = 'r';       else    modeStr[6] = '-';\r
                if(acl.perms & 2)       modeStr[7] = 'w';       else    modeStr[7] = '-';\r
                if(acl.perms & 8)       modeStr[8] = 'x';       else    modeStr[8] = '-';\r
-               write(_stdout, 10, modeStr);\r
+               printf(modeStr);\r
                close(fp);\r
                \r
                // Colour Code\r
                if(info.flags & FILEFLAG_DIRECTORY)     // Directory: Green\r
-                       write(_stdout, 6, "\x1B[32m");\r
+                       printf("\x1B[32m");\r
                // Default: White\r
                \r
                // Print Name\r
-               write(_stdout, strlen(fileName), fileName);\r
+               printf("%s", fileName);\r
                \r
                // Print slash if applicable\r
                if(info.flags & FILEFLAG_DIRECTORY)\r
-                       write(_stdout, 1, "/");\r
+                       printf("/");\r
                \r
                // Revert Colour\r
-               write(_stdout, 6, "\x1B[37m");\r
+               printf("\x1B[37m");\r
                \r
                // Newline!\r
-               write(_stdout, 1, "\n");\r
+               printf("\n");\r
        }\r
        // Close Directory\r
        close(dp);\r
index 85c649d..a9728f7 100644 (file)
@@ -40,7 +40,7 @@ void Input_HandleSelect(fd_set *set)
        if(FD_ISSET(giTerminalFD, set))
        {
                uint32_t        codepoint;
-               if( read(giTerminalFD, sizeof(codepoint), &codepoint) != sizeof(codepoint) )
+               if( read(giTerminalFD, &codepoint, sizeof(codepoint)) != sizeof(codepoint) )
                {
                        // oops, error
                }
@@ -63,7 +63,7 @@ void Input_HandleSelect(fd_set *set)
                _SysDebug("Cursor event");
 
                seek(giMouseFD, 0, SEEK_SET);   
-               if( read(giMouseFD, sizeof(mouseinfo), &mouseinfo) != sizeof(mouseinfo) )
+               if( read(giMouseFD, &mouseinfo, sizeof(mouseinfo)) != sizeof(mouseinfo) )
                {
                        // Not a 3 button mouse, oops
                        return ;
index 6fd01c5..f25e1c4 100644 (file)
@@ -64,7 +64,7 @@ void IPC_HandleSelect(fd_set *set)
                 int    readlen, identlen;
                char    *msg;
 
-               readlen = read(giNetworkFileHandle, sizeof(staticBuf), staticBuf);
+               readlen = read(giNetworkFileHandle, staticBuf, sizeof(staticBuf));
                
                identlen = 4 + Net_GetAddressSize( ((uint16_t*)staticBuf)[1] );
                msg = staticBuf + identlen;
@@ -208,7 +208,7 @@ void IPC_Type_Datagram_Send(void *Ident, size_t Length, void *Data)
        memcpy(tmpbuf, Ident, identlen);        // Header
        memcpy(tmpbuf + identlen, Data, Length);        // Data
        // TODO: Handle fragmented packets
-       write(giNetworkFileHandle, sizeof(tmpbuf), tmpbuf);
+       write(giNetworkFileHandle, tmpbuf, sizeof(tmpbuf));
 }
 
 int IPC_Type_Sys_GetSize(void *Ident)
index 7b3eb2f..b57b8c7 100644 (file)
@@ -67,7 +67,7 @@ void Video_Update(void)
 {
        //seek(giTerminalFD, 0, SEEK_SET);
        seek(giTerminalFD, 0, 1);
-       write(giTerminalFD, giScreenWidth*giScreenHeight*4, gpScreenBuffer);
+       write(giTerminalFD, gpScreenBuffer, giScreenWidth*giScreenHeight*4);
 }
 
 void Video_FillRect(short X, short Y, short W, short H, uint32_t Color)
index 8fc8463..e63a97c 100644 (file)
@@ -29,7 +29,7 @@ int main(int argc, char *argv[])
        }
 
        do {
-               num = read(fd, BUF_SIZE, buf);
+               num = read(fd, buf, BUF_SIZE);
                buf[num] = '\0';
                printf("%s", buf);
        } while(num == BUF_SIZE);
index 952da4e..a08553a 100644 (file)
@@ -578,6 +578,10 @@ void ParseServerLine(tServer *Server, char *Line)
                                break;\r
                        }\r
                }\r
+               else if( strcmp(cmd, "PING") == 0 )\r
+               {\r
+                       writef(Server->FD, "PONG %s\n", gsHostname);\r
+               }\r
                else if( strcmp(cmd, "NOTICE") == 0 )\r
                {\r
                        char    *class, *message;\r
@@ -643,7 +647,7 @@ int ProcessIncoming(tServer *Server)
        {\r
        #endif\r
                // Read data\r
-               len = read(Server->FD, BUFSIZ - Server->ReadPos, &Server->InBuf[Server->ReadPos]);\r
+               len = read(Server->FD, &Server->InBuf[Server->ReadPos], BUFSIZ - Server->ReadPos);\r
                if( len == -1 ) {\r
                        return -1;\r
                }\r
@@ -697,7 +701,7 @@ int writef(int FD, const char *Format, ...)
                vsnprintf(buf, len+1, Format, args);\r
                va_end(args);\r
                \r
-               return write(FD, len, buf);\r
+               return write(FD, buf, len);\r
        }\r
 }\r
 \r
index 919d5a6..2bae2c9 100644 (file)
@@ -63,25 +63,25 @@ int main(int argc, char *argv[], char *envp[])
                fp = open(tmpPath, OPENFLAG_READ);\r
                if(fp == -1)    continue;\r
                \r
-               read(fp, 2, &vendor);   read(fp, 2, &device);\r
+               read(fp, &vendor, 2);   read(fp, &device, 2);\r
                printf(" Vendor 0x%04x, Device 0x%04x\n", vendor, device);\r
                printf(" %s - %s\n", GetVendorName(vendor), GetDeviceName(vendor, device));\r
                \r
                // Reuse vendor and device\r
                seek(fp, 0x8, SEEK_SET);\r
-               read(fp, 2, &vendor);   read(fp, 2, &device);\r
+               read(fp, &vendor, 2);   read(fp, &device, 2);\r
                printf(" Revision 0x%04x, Class 0x%04x ()\n", vendor, device);\r
                \r
                // Read File\r
                #if DUMP_BARS\r
                seek(fp, 0x10, SEEK_SET);\r
                printf("Base Address Registers (BARs):\n");\r
-               read(fp, 4, &tmp32);    printf(" 0x%08x", tmp32);\r
-               read(fp, 4, &tmp32);    printf(" 0x%08x", tmp32);\r
-               read(fp, 4, &tmp32);    printf(" 0x%08x", tmp32);\r
-               read(fp, 4, &tmp32);    printf(" 0x%08x", tmp32);\r
-               read(fp, 4, &tmp32);    printf(" 0x%08x", tmp32);\r
-               read(fp, 4, &tmp32);    printf(" 0x%08x", tmp32);\r
+               read(fp, &tmp32, 4);    printf(" 0x%08x", tmp32);\r
+               read(fp, &tmp32, 4);    printf(" 0x%08x", tmp32);\r
+               read(fp, &tmp32, 4);    printf(" 0x%08x", tmp32);\r
+               read(fp, &tmp32, 4);    printf(" 0x%08x", tmp32);\r
+               read(fp, &tmp32, 4);    printf(" 0x%08x", tmp32);\r
+               read(fp, &tmp32, 4);    printf(" 0x%08x", tmp32);\r
                printf("\n");\r
                #endif\r
                printf("\n");\r
index 0d12c1c..7733805 100644 (file)
@@ -64,8 +64,8 @@ int main(int argc, char *argv[], char *envp[])
                        // Read from server, and write to stdout\r
                        do\r
                        {\r
-                               len = read(server_fd, BUFSIZ, buffer);\r
-                               write(1, len, buffer);\r
+                               len = read(server_fd, buffer, BUFSIZ);\r
+                               write(1, buffer, len);\r
                        } while( len == BUFSIZ );\r
                }\r
                \r
@@ -78,17 +78,17 @@ int main(int argc, char *argv[], char *envp[])
                                char    *line = Readline_NonBlock(readline_info);\r
                                if( line )\r
                                {\r
-                                       write(server_fd, strlen(line), line);\r
-                                       write(server_fd, 1, "\n");\r
+                                       write(server_fd, line, strlen(line));\r
+                                       write(server_fd, "\n", 1);\r
                                }\r
                        }\r
                        else\r
                        {\r
                                do\r
                                {\r
-                                       len = read(0, BUFSIZ, buffer);\r
-                                       write(server_fd, len, buffer);\r
-                                       write(1, len, buffer);\r
+                                       len = read(0, buffer, BUFSIZ);\r
+                                       write(server_fd, buffer, len);\r
+                                       write(1, buffer, len);\r
                                } while( len == BUFSIZ );\r
                        }\r
                }\r
index 3eef946..ec254bf 100644 (file)
@@ -60,7 +60,7 @@ extern void   *SysLoadBin(const char *path, void **entry);
 extern int     SysUnloadBin(void *Base);
 extern void    SysSetFaultHandler(int (*Hanlder)(int));
 extern int     open(const char *filename, int flags);
-extern void    close(int fd);
+extern int     close(int fd);
 
 // === ELF Loader ===
 extern int     ElfGetSymbol(void *Base, char *name, void **ret);
index b588f24..60def89 100644 (file)
@@ -10,6 +10,8 @@
 #include "lib.h"\r
 #include "stdio_int.h"\r
 \r
+#define WRITE_STR(_fd, _str)   write(_fd, _str, sizeof(_str))\r
+\r
 #define DEBUG_BUILD    0\r
 \r
 // === CONSTANTS ===\r
@@ -116,10 +118,12 @@ EXPORT FILE *fopen(const char *file, const char *mode)
        return freopen(file, mode, retFile);\r
 }\r
 \r
-EXPORT void fclose(FILE *fp)\r
+EXPORT int fclose(FILE *fp)\r
 {\r
        close(fp->FD);\r
-       free(fp);\r
+       fp->Flags = 0;\r
+       fp->FD = -1;\r
+       return 0;\r
 }\r
 \r
 EXPORT void fflush(FILE *fp)\r
@@ -152,20 +156,18 @@ EXPORT int vfprintf(FILE *fp, const char *format, va_list args)
         int    size;\r
        char    sbuf[1024];\r
        char    *buf = sbuf;\r
\r
-\r
 \r
        if(!fp || !format)      return -1;\r
 \r
        va_copy(tmpList, args);\r
        \r
-       size = vsnprintf(sbuf, 1024, (char*)format, tmpList);\r
+       size = vsnprintf(sbuf, sizeof(sbuf), (char*)format, tmpList);\r
        \r
-       if( size >= 1024 )\r
+       if( size >= sizeof(sbuf) )\r
        {\r
                buf = (char*)malloc(size+1);\r
                if(!buf) {\r
-                       write(_stdout, 31, "vfprintf ERROR: malloc() failed");\r
+                       WRITE_STR(_stdout, "vfprintf ERROR: malloc() failed");\r
                        return 0;\r
                }\r
                buf[size] = '\0';\r
@@ -175,7 +177,7 @@ EXPORT int vfprintf(FILE *fp, const char *format, va_list args)
        }\r
        \r
        // Write to stream\r
-       write(fp->FD, size, buf);\r
+       write(fp->FD, buf, size);\r
        \r
        // Free buffer\r
        free(buf);\r
@@ -210,7 +212,7 @@ EXPORT size_t fwrite(void *ptr, size_t size, size_t num, FILE *fp)
         int    ret;\r
        if(!fp || !fp->FD)      return -1;\r
        \r
-       ret = write(fp->FD, size*num, ptr);\r
+       ret = write(fp->FD, ptr, size*num);\r
        \r
        return ret;\r
 }\r
@@ -224,7 +226,7 @@ EXPORT size_t fread(void *ptr, size_t size, size_t num, FILE *fp)
         int    ret;\r
        if(!fp || !fp->FD)      return -1;\r
        \r
-       ret = read(fp->FD, size*num, ptr);\r
+       ret = read(fp->FD, ptr, size*num);\r
        \r
        return ret;\r
 }\r
@@ -236,7 +238,13 @@ EXPORT size_t fread(void *ptr, size_t size, size_t num, FILE *fp)
 EXPORT int fputc(int c, FILE *fp)\r
 {\r
        if(!fp || !fp->FD)      return -1;\r
-       return write(fp->FD, 1, &c);\r
+       return write(fp->FD, &c, 1);\r
+}\r
+\r
+EXPORT int putchar(int c)\r
+{\r
+       c &= 0xFF;\r
+       return write(_stdout, &c, 1);\r
 }\r
 \r
 /**\r
@@ -247,7 +255,14 @@ EXPORT int fgetc(FILE *fp)
 {\r
        char    ret = 0;\r
        if(!fp) return -1;\r
-       if(read(fp->FD, 1, &ret) == -1) return -1;\r
+       if(read(fp->FD, &ret, 1) == -1) return -1;\r
+       return ret;\r
+}\r
+\r
+EXPORT int getchar(void)\r
+{\r
+       char    ret = 0;\r
+       if(read(_stdin, &ret, 1) != 1)  return -1;\r
        return ret;\r
 }\r
 \r
@@ -266,20 +281,15 @@ FILE *get_file_struct()
        return NULL;\r
 }\r
 \r
-EXPORT int putchar(int ch)\r
-{\r
-       return write(_stdout, 1, (char*)&ch);\r
-}\r
-\r
-EXPORT int     puts(const char *str)\r
+EXPORT int puts(const char *str)\r
 {\r
         int    len;\r
        \r
        if(!str)        return 0;\r
        len = strlen(str);\r
        \r
-       len = write(_stdout, len, (char*)str);\r
-       write(_stdout, 1, "\n");\r
+       len = write(_stdout, str, len);\r
+       write(_stdout, "\n", 1);\r
        return len;\r
 }\r
 \r
@@ -546,7 +556,7 @@ EXPORT int printf(const char *format, ...)
                // Allocate buffer\r
                buf = (char*)malloc(size+1);\r
                if(buf) {\r
-                       write(_stdout, 29, "PRINTF ERROR: malloc() failed");\r
+                       WRITE_STR(_stdout, "PRINTF ERROR: malloc() failed\n");\r
                        return 0;\r
                }\r
                buf[size] = '\0';\r
@@ -558,7 +568,7 @@ EXPORT int printf(const char *format, ...)
        }\r
        \r
        // Send to stdout\r
-       write(_stdout, size+1, buf);\r
+       write(_stdout, buf, size+1);\r
        \r
        // Free buffer\r
        free(buf);\r
index 8f6021f..8c5c13a 100644 (file)
@@ -13,7 +13,7 @@ int SoMain()
 // --- Errors ---
 void __stack_chk_fail()
 {
-       write(2, 32, "FATAL ERROR: Stack Check Failed\n");
+       write(2, "FATAL ERROR: Stack Check Failed\n", 32);
        _exit(-1);
        for(;;);
 }
index 58bcb43..1408eef 100644 (file)
@@ -80,7 +80,7 @@ char *Readline_NonBlock(tReadline *Info)
         int    len, i;
        
        // Read as much as possible (appending to remaining data)
-       len = read(STDIN_FD, READ_BUFFER_SIZE - 1 - Info->ReadBufferLen, Info->ReadBuffer);
+       len = read(STDIN_FD, Info->ReadBuffer, READ_BUFFER_SIZE - 1 - Info->ReadBufferLen);
        if( len <= 0 )  return NULL;
        Info->ReadBuffer[Info->ReadBufferLen + len] = '\0';
        
@@ -204,21 +204,21 @@ int Readline_int_ParseCharacter(tReadline *Info, char *Input)
                                        
                                        // Move to the beginning of the line
                                        pos = oldLen;
-                                       while(pos--)    write(STDOUT_FD, 3, "\x1B[D");
+                                       while(pos--)    write(STDOUT_FD, "\x1B[D", 3);
                                        
                                        // Update state
                                        Info->CurBuffer = Info->History[--Info->HistoryPos];
                                        Info->BufferSize = Info->BufferUsed = strlen(Info->CurBuffer);
                                        
-                                       write(STDOUT_FD, Info->BufferUsed, Info->CurBuffer);
+                                       write(STDOUT_FD, Info->CurBuffer, Info->BufferUsed);
                                        Info->BufferWritePos = Info->BufferUsed;
                                        
                                        // Clear old characters (if needed)
                                        if( oldLen > Info->BufferWritePos ) {
                                                pos = oldLen - Info->BufferWritePos;
-                                               while(pos--)    write(STDOUT_FD, 1, " ");
+                                               while(pos--)    write(STDOUT_FD, " ", 1);
                                                pos = oldLen - Info->BufferWritePos;
-                                               while(pos--)    write(STDOUT_FD, 3, "\x1B[D");
+                                               while(pos--)    write(STDOUT_FD, "\x1B[D", 3);
                                        }
                                }
                                break;
@@ -230,34 +230,34 @@ int Readline_int_ParseCharacter(tReadline *Info, char *Input)
                                        
                                        // Move to the beginning of the line
                                        pos = oldLen;
-                                       while(pos--)    write(STDOUT_FD, 3, "\x1B[D");
+                                       while(pos--)    write(STDOUT_FD, "\x1B[D", 3);
                                        
                                        // Update state
                                        Info->CurBuffer = Info->History[Info->HistoryPos++];
                                        Info->BufferSize = Info->BufferUsed = strlen(Info->CurBuffer);
                                        
                                        // Write new line
-                                       write(STDOUT_FD, Info->BufferUsed, Info->CurBuffer);
+                                       write(STDOUT_FD, Info->CurBuffer, Info->BufferUsed);
                                        Info->BufferWritePos = Info->BufferUsed;
                                        
                                        // Clear old characters (if needed)
                                        if( oldLen > Info->BufferWritePos ) {
                                                pos = oldLen - Info->BufferWritePos;
-                                               while(pos--)    write(STDOUT_FD, 1, " ");
+                                               while(pos--)    write(STDOUT_FD, " ", 1);
                                                pos = oldLen - Info->BufferWritePos;
-                                               while(pos--)    write(STDOUT_FD, 3, "\x1B[D");
+                                               while(pos--)    write(STDOUT_FD, "\x1B[D", 3);
                                        }
                                }
                                break;
                        case 'D':       // Left
                                if(Info->BufferWritePos == 0)   break;
                                Info->BufferWritePos --;
-                               write(STDOUT_FD, 3, "\x1B[D");
+                               write(STDOUT_FD, "\x1B[D", 3);
                                break;
                        case 'C':       // Right
                                if(Info->BufferWritePos == Info->BufferUsed)    break;
                                Info->BufferWritePos ++;
-                               write(STDOUT_FD, 3, "\x1B[C");
+                               write(STDOUT_FD, "\x1B[C", 3);
                                break;
                        }
                }
@@ -267,7 +267,7 @@ int Readline_int_ParseCharacter(tReadline *Info, char *Input)
        case '\b':
                if(Info->BufferWritePos <= 0)   break;  // Protect against underflows
                // Write the backsapce
-               write(STDOUT_FD, 1, &ch);
+               write(STDOUT_FD, &ch, 1);
                if(Info->BufferWritePos == Info->BufferUsed)    // Simple case: End of string
                {
                        Info->BufferUsed --;
@@ -283,11 +283,11 @@ int Readline_int_ParseCharacter(tReadline *Info, char *Input)
                        buf[4] += (delta) % 10;
                        // Write everything save for the deleted character
                        write(STDOUT_FD,
-                               Info->BufferUsed - Info->BufferWritePos,
-                               &Info->CurBuffer[Info->BufferWritePos]
+                               &Info->CurBuffer[Info->BufferWritePos],
+                               Info->BufferUsed - Info->BufferWritePos
                                );
-                       ch = ' ';       write(STDOUT_FD, 1, &ch);       ch = '\b';      // Clear old last character
-                       write(STDOUT_FD, 7, buf);       // Update Cursor
+                       ch = ' ';       write(STDOUT_FD, &ch, 1);       ch = '\b';      // Clear old last character
+                       write(STDOUT_FD, buf, 7);       // Update Cursor
                        // Alter Buffer
                        memmove(&Info->CurBuffer[Info->BufferWritePos-1],
                                &Info->CurBuffer[Info->BufferWritePos],
@@ -321,12 +321,12 @@ int Readline_int_ParseCharacter(tReadline *Info, char *Input)
                        buf[2] += (delta/100) % 10;
                        buf[3] += (delta/10) % 10;
                        buf[4] += (delta) % 10;
-                       write(STDOUT_FD, 1, &ch);       // Print new character
+                       write(STDOUT_FD, &ch, 1);       // Print new character
                        write(STDOUT_FD,
-                               Info->BufferUsed - Info->BufferWritePos,
-                               &Info->CurBuffer[Info->BufferWritePos]
+                               &Info->CurBuffer[Info->BufferWritePos],
+                               Info->BufferUsed - Info->BufferWritePos
                                );
-                       write(STDOUT_FD, 7, buf);       // Update Cursor
+                       write(STDOUT_FD, buf, 7);       // Update Cursor
                        // Move buffer right
                        memmove(
                                &Info->CurBuffer[Info->BufferWritePos+1],
@@ -336,7 +336,7 @@ int Readline_int_ParseCharacter(tReadline *Info, char *Input)
                }
                // Simple append
                else {
-                       write(STDOUT_FD, 1, &ch);
+                       write(STDOUT_FD, &ch, 1);
                }
                Info->CurBuffer[ Info->BufferWritePos ++ ] = ch;
                Info->BufferUsed ++;
index c26cec1..6d7751b 100644 (file)
@@ -58,9 +58,9 @@ extern void   setgid(int id);
 extern int     chdir(const char *dir);
 extern int     open(const char *path, int flags);
 extern int     reopen(int fd, const char *path, int flags);
-extern void    close(int fd);
-extern uint    read(int fd, uint length, void *buffer);
-extern uint    write(int fd, uint length, void *buffer);
+extern int     close(int fd);
+extern uint    read(int fd, void *buffer, uint length);
+extern uint    write(int fd, const void *buffer, uint length);
 extern int     seek(int fd, int64_t offset, int whence);
 extern uint64_t        tell(int fd);
 extern int     ioctl(int fd, int id, void *data);
@@ -72,7 +72,7 @@ extern int    _SysMount(const char *Device, const char *Directory, const char *Type
 extern int     select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errfds, time_t *timeout);
 
 // --- IPC ---
-extern int     SysSendMessage(pid_t dest, uint length, void *Data);
+extern int     SysSendMessage(pid_t dest, uint length, const void *Data);
 extern int     SysGetMessage(pid_t *src, void *Data);
 
 // --- MEMORY ---
index adfb101..0e43363 100644 (file)
@@ -17,12 +17,15 @@ typedef signed long long    int64_t;
 #ifdef __LP64__
 typedef uint64_t       intptr_t;
 typedef uint64_t       uintptr_t;
+typedef int64_t        ptrdiff_t;
 #else
 typedef uint32_t       intptr_t;
 typedef uint32_t       uintptr_t;
+typedef int32_t        ptrdiff_t;
 #endif
 #if 0
 # error "Unknown pointer size"
 #endif
 
+
 #endif
index ce42a15..552cd4f 100644 (file)
@@ -1,45 +1,47 @@
-/*\r
- * AcessOS LibC\r
- * stdlib.h\r
- */\r
-#ifndef __STDIO_H\r
+/*
+ * AcessOS LibC
+ * stdlib.h
+ */
+#ifndef __STDIO_H
 #define __STDIO_H
-\r
-#include <stdlib.h>\r
-#include <stdarg.h>\r
-\r
+
+#include <stdlib.h>
+#include <stdarg.h>
+
 // === Types ===
 typedef struct sFILE   FILE;
-\r
-// === CONSTANTS ===\r
-#define EOF    (-1)\r
-\r
-// --- Standard IO ---\r
-extern int     printf(const char *format, ...);\r
-extern int     vsnprintf(char *buf, size_t __maxlen, const char *format, va_list args);\r
-extern int     vsprintf(char *buf, const char *format, va_list args);\r
-extern int     sprintf(char *buf, const char *format, ...);\r
-extern int snprintf(char *buf, size_t maxlen, const char *format, ...);\r
-\r
-extern FILE    *fopen(const char *file, const char *mode);\r
-extern FILE    *freopen(const char *file, const char *mode, FILE *fp);\r
+
+// === CONSTANTS ===
+#define EOF    (-1)
+
+// --- Standard IO ---
+extern int     printf(const char *format, ...);
+extern int     vsnprintf(char *buf, size_t __maxlen, const char *format, va_list args);
+extern int     vsprintf(char *buf, const char *format, va_list args);
+extern int     sprintf(char *buf, const char *format, ...);
+extern int     snprintf(char *buf, size_t maxlen, const char *format, ...);
+
+extern FILE    *fopen(const char *file, const char *mode);
+extern FILE    *freopen(const char *file, const char *mode, FILE *fp);
 extern FILE    *fdopen(int fd, const char *modes);
-extern void fclose(FILE *fp);\r
-extern void fflush(FILE *fp);\r
-extern long int        ftell(FILE *fp);\r
-extern int     fseek(FILE *fp, long int amt, int whence);\r
-\r
-extern size_t  fread(void *buf, size_t size, size_t n, FILE *fp);\r
-extern size_t  fwrite(void *buf, size_t size, size_t n, FILE *fp);\r
-extern int     fgetc(FILE *fp);\r
-extern int     fputc(int ch, FILE *fp);\r
-\r
-extern int     fprintf(FILE *fp, const char *format, ...);\r
-extern int     vfprintf(FILE *fp, const char *format, va_list args);\r
-\r
-extern FILE    *stdin;\r
-extern FILE    *stdout;\r
-extern FILE    *stderr;\r
-
-#endif\r
+extern int     fclose(FILE *fp);
+extern void    fflush(FILE *fp);
+extern long int        ftell(FILE *fp);
+extern int     fseek(FILE *fp, long int amt, int whence);
+
+extern size_t  fread(void *buf, size_t size, size_t n, FILE *fp);
+extern size_t  fwrite(void *buf, size_t size, size_t n, FILE *fp);
+extern int     fgetc(FILE *fp);
+extern int     fputc(int ch, FILE *fp);
+extern int     getchar(void);
+extern int     putchar(int ch);
+
+extern int     fprintf(FILE *fp, const char *format, ...);
+extern int     vfprintf(FILE *fp, const char *format, va_list args);
+
+extern FILE    *stdin;
+extern FILE    *stdout;
+extern FILE    *stderr;
+
+#endif
 
index a934f75..08bf31e 100644 (file)
@@ -4,8 +4,18 @@
 #ifndef _SYS_SYS_H_\r
 #define _SYS_SYS_H_\r
 \r
+#include <acess/sys.h>\r
+\r
 #include <sys/types.h>\r
 \r
+#define O_RDONLY       OPENFLAG_READ\r
+#define O_WRONLY       OPENFLAG_WRITE\r
+#define O_CREAT        (OPENFLAG_CREATE|OPENFLAG_WRITE)\r
+#define O_TRUNC        OPENFLAG_WRITE\r
+#define O_APPEND       OPENFLAG_WRITE\r
+\r
+\r
+#if 0\r
 #define        OPEN_FLAG_READ  1\r
 #define        OPEN_FLAG_WRITE 2\r
 #define        OPEN_FLAG_EXEC  4\r
@@ -41,5 +51,6 @@ extern int    getpid();       // Get Process ID
 extern int     sendmsg(int dest, unsigned int *Data);\r
 extern int     pollmsg(int *src, unsigned int *Data);\r
 extern int     getmsg(int *src, unsigned int *Data);\r
+#endif\r
 \r
 #endif\r

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