Usermode - Renamed VFS syscalls to _Sys* to remove POSIX collisions
authorJohn Hodge (sonata) <[email protected]>
Thu, 29 Nov 2012 16:31:40 +0000 (00:31 +0800)
committerJohn Hodge (sonata) <[email protected]>
Thu, 29 Nov 2012 16:31:40 +0000 (00:31 +0800)
50 files changed:
KernelLand/Modules/Filesystems/InitRD/files.lst
Makefile
Usermode/Applications/CLIShell_src/main.c
Usermode/Applications/Makefile.cfg
Usermode/Applications/Makefile.tpl
Usermode/Applications/axwin3_src/WM/input.c
Usermode/Applications/axwin3_src/WM/ipc.c
Usermode/Applications/axwin3_src/WM/video.c
Usermode/Applications/axwin3_src/WM/wm_render_text.c
Usermode/Applications/axwin3_src/libaxwin3.so_src/msg.c
Usermode/Applications/bomb_src/main.c
Usermode/Applications/cat_src/main.c
Usermode/Applications/dhcpclient_src/main.c
Usermode/Applications/gui_ate_src/main.c
Usermode/Applications/gui_shell_src/main.c
Usermode/Applications/init_src/main.c
Usermode/Applications/ip_src/addr.c
Usermode/Applications/ip_src/routes.c
Usermode/Applications/irc_src/main.c
Usermode/Applications/ls_src/main.c
Usermode/Applications/lspci_src/main.c
Usermode/Applications/mount_src/main.c
Usermode/Applications/ping_src/main.c
Usermode/Applications/telnet_src/main.c
Usermode/Applications/telnetd_src/main.c
Usermode/Applications/wget_src/main.c
Usermode/Libraries/ld-acess.so_src/arch/syscalls.s.h
Usermode/Libraries/ld-acess.so_src/common.h
Usermode/Libraries/ld-acess.so_src/include_exp/acess/fd_set.h [new file with mode: 0644]
Usermode/Libraries/ld-acess.so_src/include_exp/acess/sys.h
Usermode/Libraries/ld-acess.so_src/include_exp/acess/syscall_types.h
Usermode/Libraries/ld-acess.so_src/include_exp/sys/stat.h [deleted file]
Usermode/Libraries/ld-acess.so_src/include_exp/sys/types.h [deleted file]
Usermode/Libraries/ld-acess.so_src/include_exp/unistd.h [deleted file]
Usermode/Libraries/ld-acess.so_src/lib.c
Usermode/Libraries/libc.so_src/stdio.c
Usermode/Libraries/libnet.so_src/main.c
Usermode/Libraries/libnet.so_src/socket.c
Usermode/Libraries/libposix.so_src/Makefile [new file with mode: 0644]
Usermode/Libraries/libposix.so_src/include_exp/sys/select.h [new file with mode: 0644]
Usermode/Libraries/libposix.so_src/include_exp/sys/stat.h [new file with mode: 0644]
Usermode/Libraries/libposix.so_src/include_exp/sys/types.h [new file with mode: 0644]
Usermode/Libraries/libposix.so_src/include_exp/unistd.h [new file with mode: 0644]
Usermode/Libraries/libposix.so_src/main.c [new file with mode: 0644]
Usermode/Libraries/libposix.so_src/unistd.c [new file with mode: 0644]
Usermode/Libraries/libpsocket.so_src/common.h [new file with mode: 0644]
Usermode/Libraries/libpsocket.so_src/main.c
Usermode/Libraries/libpsocket.so_src/socket.c
Usermode/Libraries/libreadline.so_src/main.c
Usermode/Libraries/liburi.so_src/main.c

index a5d524d..1e7b6f8 100644 (file)
@@ -24,6 +24,7 @@ Dir "Libs" {
        File "liburi.so" "__BIN__/Libs/liburi.so"
        File "libimage_sif.so" "__BIN__/Libs/libimage_sif.so"
        File "libaxwin3.so" "__BIN__/Libs/libaxwin3.so"
+       File "libposix.so" "__BIN__/Libs/libposix.so"
 }
 Dir "Conf" {
        File "BootConf.cfg" "__FS__/Conf/BootConf.cfg"
index 0d265c4..32f1ffb 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,7 @@
 
 SUBMAKE = $(MAKE) --no-print-directory
 
-USRLIBS := crt0.o acess.ld ld-acess.so libc.so
+USRLIBS := crt0.o acess.ld ld-acess.so libc.so libposix.so
 USRLIBS += libreadline.so libnet.so liburi.so libpsocket.so
 USRLIBS += libimage_sif.so
 
index 24889fa..be621c4 100644 (file)
@@ -165,15 +165,15 @@ void CallCommand(char **Args)
        {\r
                GeneratePath(exefile, gsCurrentDirectory, sTmpBuffer);\r
                // Check file existence\r
-               fd = open(sTmpBuffer, OPENFLAG_EXEC);\r
+               fd = _SysOpen(sTmpBuffer, OPENFLAG_EXEC);\r
                if(fd == -1) {\r
                        printf("Unknown Command: `%s'\n", Args[0]);     // Error Message\r
                        return ;\r
                }\r
                \r
                // Get File info and close file\r
-               finfo( fd, &info, 0 );\r
-               close( fd );\r
+               _SysFInfo( fd, &info, 0 );\r
+               _SysClose( fd );\r
                \r
                // Check if the file is a directory\r
                if(info.flags & FILEFLAG_DIRECTORY) {\r
@@ -189,10 +189,10 @@ void CallCommand(char **Args)
                for( i = 0; i < giNumPathDirs; i++ )\r
                {\r
                        GeneratePath(exefile, gasPathDirs[i], sTmpBuffer);\r
-                       fd = open(sTmpBuffer, OPENFLAG_EXEC);\r
+                       fd = _SysOpen(sTmpBuffer, OPENFLAG_EXEC);\r
                        if(fd == -1)    continue;\r
-                       finfo( fd, &info, 0 );\r
-                       close( fd );\r
+                       _SysFInfo( fd, &info, 0 );\r
+                       _SysClose( fd );\r
                        if(info.flags & FILEFLAG_DIRECTORY)     continue;\r
                        // Woohoo! We found a valid command\r
                        break;\r
@@ -256,7 +256,7 @@ void Command_Help(int argc, char **argv)
  */\r
 void Command_Clear(int argc, char **argv)\r
 {\r
-       write(_stdout, "\x1B[2J", 4);   //Clear Screen\r
+       _SysWrite(_stdout, "\x1B[2J", 4);       //Clear Screen\r
 }\r
 \r
 /**\r
@@ -277,13 +277,13 @@ void Command_Cd(int argc, char **argv)
        \r
        GeneratePath(argv[1], gsCurrentDirectory, tmpPath);\r
        \r
-       fp = open(tmpPath, 0);\r
+       fp = _SysOpen(tmpPath, 0);\r
        if(fp == -1) {\r
                printf("Directory does not exist\n");\r
                return;\r
        }\r
-       finfo(fp, &stats, 0);\r
-       close(fp);\r
+       _SysFInfo(fp, &stats, 0);\r
+       _SysClose(fp);\r
        \r
        if( !(stats.flags & FILEFLAG_DIRECTORY) ) {\r
                printf("Not a Directory\n");\r
@@ -295,7 +295,7 @@ void Command_Cd(int argc, char **argv)
        strcpy(gsCurrentDirectory, tmpPath);\r
        \r
        // Register change with kernel\r
-       chdir( gsCurrentDirectory );\r
+       _SysChdir( gsCurrentDirectory );\r
 }\r
 \r
 /**\r
@@ -321,7 +321,7 @@ void Command_Dir(int argc, char **argv)
        dirLen = strlen(tmpPath);\r
        \r
        // Open Directory\r
-       dp = open(tmpPath, OPENFLAG_READ);\r
+       dp = _SysOpen(tmpPath, OPENFLAG_READ);\r
        // Check if file opened\r
        if(dp == -1)\r
        {\r
@@ -329,16 +329,16 @@ void Command_Dir(int argc, char **argv)
                return;\r
        }\r
        // Get File Stats\r
-       if( finfo(dp, &info, 0) == -1 )\r
+       if( _SysFInfo(dp, &info, 0) == -1 )\r
        {\r
-               close(dp);\r
+               _SysClose(dp);\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
+               _SysClose(dp);\r
                printf("Unable to open directory `%s', Not a directory\n", tmpPath);\r
                return;\r
        }\r
@@ -352,7 +352,7 @@ void Command_Dir(int argc, char **argv)
        \r
        fileName = (char*)(tmpPath+dirLen);\r
        // Read Directory Content\r
-       while( (fp = SysReadDir(dp, fileName)) )\r
+       while( (fp = _SysReadDir(dp, fileName)) )\r
        {\r
                if(fp < 0)\r
                {\r
@@ -361,10 +361,10 @@ void Command_Dir(int argc, char **argv)
                        break;\r
                }\r
                // Open File\r
-               fp = open(tmpPath, 0);\r
+               fp = _SysOpen(tmpPath, 0);\r
                if(fp == -1)    continue;\r
                // Get File Stats\r
-               finfo(fp, &info, 0);\r
+               _SysFInfo(fp, &info, 0);\r
                \r
                if(info.flags & FILEFLAG_DIRECTORY)\r
                        printf("d");\r
@@ -391,7 +391,7 @@ void Command_Dir(int argc, char **argv)
                if(acl.perms & 2)       modeStr[7] = 'w';       else    modeStr[7] = '-';\r
                if(acl.perms & 8)       modeStr[8] = 'x';       else    modeStr[8] = '-';\r
                printf(modeStr);\r
-               close(fp);\r
+               _SysClose(fp);\r
                \r
                // Colour Code\r
                if(info.flags & FILEFLAG_DIRECTORY)     // Directory: Green\r
@@ -412,5 +412,5 @@ void Command_Dir(int argc, char **argv)
                printf("\n");\r
        }\r
        // Close Directory\r
-       close(dp);\r
+       _SysClose(dp);\r
 }\r
index 0e89a7c..5314aea 100644 (file)
@@ -8,7 +8,7 @@ ASFLAGS = -felf
 CPPFLAGS = -ffreestanding -I$(ACESSUSERDIR)/include/ -DARCHDIR_is_$(ARCHDIR)
 CPPFLAGS += $(addprefix -I,$(wildcard $(ACESSUSERDIR)Libraries/*/include_exp/))
 CFLAGS   = -fno-stack-protector $(CPPFLAGS)
-LDFLAGS  = -T $(OUTPUTDIR)Libs/acess.ld -rpath-link $(OUTPUTDIR)Libs -L $(OUTPUTDIR)Libs -I /Acess/Libs/ld-acess.so -lld-acess -lc $(OUTPUTDIR)Libs/crtbegin.o $(OUTPUTDIR)Libs/crtend.o
+LDFLAGS  = -T $(OUTPUTDIR)Libs/acess.ld -rpath-link $(OUTPUTDIR)Libs -L $(OUTPUTDIR)Libs -I /Acess/Libs/ld-acess.so -lld-acess -lc $(OUTPUTDIR)Libs/crtbegin.o $(OUTPUTDIR)Libs/crtend.o -lposix
 LIBGCC_PATH = $(shell $(CC) -print-libgcc-file-name)
 
 # Extra-verbose errors!
index c1245ae..5bf963b 100644 (file)
@@ -47,7 +47,7 @@ ifneq ($(_OBJPREFIX),)
        @mkdir -p $(dir $@)
 endif
        @$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
-       @$(CC) -M -MT $@ $(CPPFLAGS) $< -o $(_OBJPREFIX)$*.dep
+       @$(CC) -M -MP -MT $@ $(CPPFLAGS) $< -o $(_OBJPREFIX)$*.dep
 
 $(OUTPUTDIR)Libs/libld-acess.so:
        @make -C $(ACESSDIR)/Usermode/Libraries/ld-acess.so_src/
index 469c08e..29ef004 100644 (file)
@@ -37,21 +37,21 @@ int Input_Init(void)
        tNumValue       num_value;
 
        // Open mouse for RW
-       giMouseFD = open(gsMouseDevice, 3);
+       giMouseFD = _SysOpen(gsMouseDevice, 3);
 
        // Set mouse limits
        // TODO: Update these if the screen resolution changes
        num_value.Num = 0;      num_value.Value = giScreenWidth;
-       ioctl(giMouseFD, JOY_IOCTL_GETSETAXISLIMIT, &num_value);
+       _SysIOCtl(giMouseFD, JOY_IOCTL_GETSETAXISLIMIT, &num_value);
        num_value.Value = giScreenWidth/2;
        giInput_MouseX = giScreenWidth/2;
-       ioctl(giMouseFD, JOY_IOCTL_GETSETAXISPOSITION, &num_value);
+       _SysIOCtl(giMouseFD, JOY_IOCTL_GETSETAXISPOSITION, &num_value);
 
        num_value.Num = 1;      num_value.Value = giScreenHeight;
-       ioctl(giMouseFD, JOY_IOCTL_GETSETAXISLIMIT, &num_value);
+       _SysIOCtl(giMouseFD, JOY_IOCTL_GETSETAXISLIMIT, &num_value);
        num_value.Value = giScreenHeight/2;
        giInput_MouseY = giScreenHeight/2;
-       ioctl(giMouseFD, JOY_IOCTL_GETSETAXISPOSITION, &num_value);
+       _SysIOCtl(giMouseFD, JOY_IOCTL_GETSETAXISPOSITION, &num_value);
 
        return 0;
 }
@@ -72,7 +72,7 @@ void Input_HandleSelect(fd_set *set)
                static uint32_t scancode;
                #define KEY_CODEPOINT_MASK      0x3FFFFFFF
                
-               size_t readlen = read(giTerminalFD_Input, &codepoint, sizeof(codepoint));
+               size_t readlen = _SysRead(giTerminalFD_Input, &codepoint, sizeof(codepoint));
                if( readlen != sizeof(codepoint) )
                {
                        // oops, error
@@ -119,8 +119,8 @@ void Input_HandleSelect(fd_set *set)
 
                mouseinfo = (void*)data;
 
-               seek(giMouseFD, 0, SEEK_SET);
-               i = read(giMouseFD, data, sizeof(data));
+               _SysSeek(giMouseFD, 0, SEEK_SET);
+               i = _SysRead(giMouseFD, data, sizeof(data));
                i -= sizeof(*mouseinfo);
                if( i < 0 ) {
                        _SysDebug("Mouse data undersized (no header)");
index 2917bc9..17956a0 100644 (file)
@@ -76,11 +76,11 @@ void IPC_Init(void)
 {
         int    tmp;
        // TODO: Check this
-       giNetworkFileHandle = open("/Devices/ip/loop/udp", OPENFLAG_READ);
+       giNetworkFileHandle = _SysOpen("/Devices/ip/loop/udp", OPENFLAG_READ);
        if( giNetworkFileHandle != -1 )
        {
                tmp = AXWIN_PORT;
-               ioctl(giNetworkFileHandle, 4, &tmp);    // TODO: Don't hard-code IOCtl number
+               _SysIOCtl(giNetworkFileHandle, 4, &tmp);        // TODO: Don't hard-code IOCtl number
        }
 }
 
@@ -103,7 +103,7 @@ void IPC_HandleSelect(fd_set *set)
                         int    readlen, identlen;
                        char    *msg;
        
-                       readlen = read(giNetworkFileHandle, staticBuf, sizeof(staticBuf));
+                       readlen = _SysRead(giNetworkFileHandle, staticBuf, sizeof(staticBuf));
                        
                        identlen = 4 + Net_GetAddressSize( ((uint16_t*)staticBuf)[1] );
                        msg = staticBuf + identlen;
@@ -114,7 +114,7 @@ void IPC_HandleSelect(fd_set *set)
        }
 
        size_t  len;
-       pid_t   tid;
+       int     tid;
        while( (len = SysGetMessage(&tid, 0, NULL)) )
        {
                char    data[len];
@@ -145,7 +145,7 @@ void IPC_Type_Datagram_Send(const void *Ident, size_t Length, const void *Data)
        memcpy(tmpbuf, Ident, identlen);        // Header
        memcpy(tmpbuf + identlen, Data, Length);        // Data
        // TODO: Handle fragmented packets
-       write(giNetworkFileHandle, tmpbuf, sizeof(tmpbuf));
+       _SysWrite(giNetworkFileHandle, tmpbuf, sizeof(tmpbuf));
 }
 
 int IPC_Type_Sys_GetSize(const void *Ident)
index d400568..60f2155 100644 (file)
@@ -38,7 +38,7 @@ void Video_Setup(void)
        
        // Open terminal
        #if 0
-       giTerminalFD = open(gsTerminalDevice, OPENFLAG_READ|OPENFLAG_WRITE);
+       giTerminalFD = _SysOpen(gsTerminalDevice, OPENFLAG_READ|OPENFLAG_WRITE);
        if( giTerminalFD == -1 )
        {
                fprintf(stderr, "ERROR: Unable to open '%s' (%i)\n", gsTerminalDevice, _errno);
@@ -48,8 +48,8 @@ void Video_Setup(void)
        giTerminalFD = 1;
        giTerminalFD_Input = 0;
        // Check that the console is a VT
-       // - ioctl(..., 0, NULL) returns the type, which should be 2
-       if( ioctl(1, 0, NULL) != 2 )
+       // - _SysIOCtl(..., 0, NULL) returns the type, which should be 2
+       if( _SysIOCtl(1, 0, NULL) != 2 )
        {
                fprintf(stderr, "stdout is not an Acess VT, can't start");
                _SysDebug("stdout is not an Acess VT, can't start");
@@ -59,22 +59,22 @@ void Video_Setup(void)
        
        // Set mode to video
        tmpInt = TERM_MODE_FB;
-       ioctl( giTerminalFD, TERM_IOCTL_MODETYPE, &tmpInt );
+       _SysIOCtl( giTerminalFD, TERM_IOCTL_MODETYPE, &tmpInt );
        
        // Get dimensions
-       giScreenWidth = ioctl( giTerminalFD, TERM_IOCTL_WIDTH, NULL );
-       giScreenHeight = ioctl( giTerminalFD, TERM_IOCTL_HEIGHT, NULL );
+       giScreenWidth = _SysIOCtl( giTerminalFD, TERM_IOCTL_WIDTH, NULL );
+       giScreenHeight = _SysIOCtl( giTerminalFD, TERM_IOCTL_HEIGHT, NULL );
 
        giVideo_LastDirtyLine = giScreenHeight;
        
        // Force VT to be shown
-       ioctl( giTerminalFD, TERM_IOCTL_FORCESHOW, NULL );
+       _SysIOCtl( giTerminalFD, TERM_IOCTL_FORCESHOW, NULL );
        
        // Create local framebuffer (back buffer)
        gpScreenBuffer = malloc( giScreenWidth*giScreenHeight*4 );
 
        // Set cursor position and bitmap
-       ioctl(giTerminalFD, TERM_IOCTL_SETCURSORBITMAP, &cCursorBitmap);
+       _SysIOCtl(giTerminalFD, TERM_IOCTL_SETCURSORBITMAP, &cCursorBitmap);
        Video_SetCursorPos( giScreenWidth/2, giScreenHeight/2 );
 }
 
@@ -87,9 +87,9 @@ void Video_Update(void)
 
        _SysDebug("Video_Update - Updating lines %i to %i (0x%x+0x%x px)",
                giVideo_FirstDirtyLine, giVideo_LastDirtyLine, ofs, size);
-       seek(giTerminalFD, ofs*4, 1);
+       _SysSeek(giTerminalFD, ofs*4, 1);
        _SysDebug("Video_Update - Sending FD %i %p 0x%x", giTerminalFD, gpScreenBuffer+ofs, size*4);
-       write(giTerminalFD, gpScreenBuffer+ofs, size*4);
+       _SysWrite(giTerminalFD, gpScreenBuffer+ofs, size*4);
        _SysDebug("Video_Update - Done");
        giVideo_FirstDirtyLine = 0;
        giVideo_LastDirtyLine = 0;
@@ -103,7 +103,7 @@ void Video_SetCursorPos(short X, short Y)
        } pos;
        pos.x = giVideo_CursorX = X;
        pos.y = giVideo_CursorY = Y;
-       ioctl(giTerminalFD, TERM_IOCTL_GETSETCURSOR, &pos);
+       _SysIOCtl(giTerminalFD, TERM_IOCTL_GETSETCURSOR, &pos);
 }
 
 void Video_FillRect(int X, int Y, int W, int H, uint32_t Colour)
@@ -136,13 +136,22 @@ void Video_Blit(uint32_t *Source, short DstX, short DstY, short W, short H)
 
        if( DstX >= giScreenWidth)      return ;
        if( DstY >= giScreenHeight)     return ;
-       // TODO: Handle -ve X/Y by clipping
-       if( DstX < 0 || DstY < 0 )      return ;
-       // TODO: Handle out of bounds by clipping too
+       // Drawing oob to left/top, clip
+       if( DstX < 0 ) {
+               Source += -DstX;
+               drawW -= -DstX;
+               DstX = 0;
+       }
+       if( DstY < 0 ) {
+               Source += (-DstY)*W;
+               H -= -DstY;
+               DstY = 0;
+       }
+       if( drawW < 0 ) return ;
+       // Drawing oob to the right, clip
        if( DstX + drawW > giScreenWidth ) {
-               int oldw = drawW;
+               //int oldw = drawW;
                drawW = giScreenWidth - DstX;
-               _SysDebug("Video_Blit: Clipped width from %i to %i", oldw, drawW);
        }
        if( DstY + H > giScreenHeight )
                H = giScreenHeight - DstY;
@@ -155,7 +164,7 @@ void Video_Blit(uint32_t *Source, short DstX, short DstY, short W, short H)
                giVideo_LastDirtyLine = DstY + H;
        
        buf = gpScreenBuffer + DstY*giScreenWidth + DstX;
-       if(drawW != giScreenWidth)
+       if(drawW != giScreenWidth || W != giScreenWidth)
        {
                while( H -- )
                {
@@ -166,6 +175,7 @@ void Video_Blit(uint32_t *Source, short DstX, short DstY, short W, short H)
        }
        else
        {
+               // Only valid if copying full scanlines on both ends
                memcpy(buf, Source, giScreenWidth*H*4);
        }
 }
index 8168c5c..6ad72be 100644 (file)
@@ -9,6 +9,7 @@
 #include <wm_internals.h>
 #include <stdlib.h>
 #include <utf8.h>
+#include <limits.h>    // INT_MAX
 
 // === TYPES ===
 typedef struct sGlyph  tGlyph;
index 6c134a3..a1f5b78 100644 (file)
@@ -107,11 +107,11 @@ void AxWin3_int_SendIPCMessage(tAxWin_IPCMessage *Msg)
                char    tmpbuf[giAxWin3_int_UDPHeaderLen + size];
                memcpy(tmpbuf, gaAxWin3_int_UDPHeader, giAxWin3_int_UDPHeaderLen);
                memcpy(tmpbuf + giAxWin3_int_UDPHeaderLen, Msg, size);
-               write(giConnectionNum, tmpbuf, sizeof(tmpbuf));
+               _SysWrite(giConnectionNum, tmpbuf, sizeof(tmpbuf));
                }
                break;
        case CONNTYPE_TCP:
-               write(giConnectionNum, Msg, size);
+               _SysWrite(giConnectionNum, Msg, size);
                break;
        default:
                break;
@@ -122,7 +122,7 @@ tAxWin_IPCMessage *AxWin3_int_GetIPCMessage(int nFD, fd_set *fds)
 {
         int    len;
        tAxWin_IPCMessage       *ret = NULL;
-       pid_t   tid;
+        int    tid;
 
        _SysSelect(nFD, fds, NULL, NULL, NULL, THREAD_EVENT_IPCMSG);
        
index af5d094..f19f462 100644 (file)
@@ -61,7 +61,7 @@ int main(int argc, char *argv[])
                        if( tid == 0 )
                        {
                                // Sleep forever (TODO: Fix up the stack so it can nuke)
-                               for(;;) sleep();
+                               for(;;) _SysWaitEvent(THREAD_EVENT_SIGNAL);
                        }
                        if( tid < 0 ) {
                                printf("Clone failed\n");
index 443a5de..3fae4c6 100644 (file)
@@ -1,7 +1,6 @@
 /*
  * Acess2 CAT command
  */
-#include <acess/sys.h>
 #include <stdlib.h>
 #include <stdio.h>
 
@@ -13,7 +12,6 @@
  */
 int main(int argc, char *argv[])
 {
-        int    fd;
         int    num;
        char    buf[BUF_SIZE];
 
@@ -22,19 +20,19 @@ int main(int argc, char *argv[])
                return -1;
        }
 
-       fd = open(argv[1], OPENFLAG_READ);
-       if(fd == -1) {
+       FILE *fp = fopen(argv[1], "r");
+       if(!fp) {
                printf("Unable to open '%s' for reading\n", argv[1]);
                return -1;
        }
 
        do {
-               num = read(fd, buf, BUF_SIZE);
+               num = fread(buf, BUF_SIZE, 1, fp);
                if(num < 0)     break;
-               write(1, buf, num);
+               fwrite(buf, num, 1, stdout);
        } while(num == BUF_SIZE);
 
-       close(fd);
+       fclose(fp);
        printf("\n");
 
        return 0;
index 8831cd6..5b122d8 100644 (file)
@@ -8,6 +8,7 @@
 #include <string.h>
 #include <stdlib.h>
 #include <net.h>
+#include <acess/sys.h>
 
 #define FILENAME_MAX   255
 // --- Translation functions ---
@@ -145,8 +146,8 @@ int main(int argc, char *argv[])
                        {
                                if( Handle_Packet( i ) )
                                {
-                                       close(i->SocketFD);
-                                       close(i->IfaceFD);
+                                       _SysClose(i->SocketFD);
+                                       _SysClose(i->IfaceFD);
                                        p->Next = i->Next;
                                        free(i);
                                        i = p;
@@ -164,14 +165,15 @@ int main(int argc, char *argv[])
 
 void Scan_Dir(tInterface **IfaceList, const char *Directory)
 {
-       int dp = open(Directory, OPENFLAG_READ);
+       int dp = _SysOpen(Directory, OPENFLAG_READ);
        char filename[FILENAME_MAX];
 
        if( dp == -1 ) {
                fprintf(stderr, "Unable to open directory '%s'\n", Directory);
+               return ;
        }
 
-       while( SysReadDir(dp, filename) )
+       while( _SysReadDir(dp, filename) )
        {
                if( filename[0] == '.' )        continue ;              
                if( strcmp(filename, "lo") == 0 )       continue ;
@@ -182,7 +184,7 @@ void Scan_Dir(tInterface **IfaceList, const char *Directory)
                new->Next = *IfaceList;
                *IfaceList = new;
        }
-       close(dp);
+       _SysClose(dp);
 }
 
 // RETURN: Client FD
@@ -198,52 +200,52 @@ int Start_Interface(tInterface *Iface)
        {
                char    path[] = "/Devices/ip/adapters/ethXXXX";
                sprintf(path, "/Devices/ip/adapters/%s", Iface->Adapter);
-               fd = open(path, 0);
+               fd = _SysOpen(path, 0);
                if(fd == -1) {
                        _SysDebug("Unable to open adapter %s", path);
                        return -1;
                }
-               ioctl(fd, 4, Iface->HWAddr);
+               _SysIOCtl(fd, 4, Iface->HWAddr);
                // TODO: Check if ioctl() failed
-               close(fd);
+               _SysClose(fd);
        }
        
        // Initialise an interface, with a dummy IP address (zero)
-       fd = open("/Devices/ip", 0);
+       fd = _SysOpen("/Devices/ip", 0);
        if( fd == -1 ) {
                fprintf(stderr, "ERROR: Unable to open '/Devices/ip'\n"); 
                return -1;
        }
-       Iface->Num = ioctl(fd, 4, (void*)Iface->Adapter);       // Create interface
+       Iface->Num = _SysIOCtl(fd, 4, (void*)Iface->Adapter);   // Create interface
        if( Iface->Num == -1 ) {
                fprintf(stderr, "ERROR: Unable to create new interface\n");
                return -1;
        }
-       close(fd);
+       _SysClose(fd);
        
        // Open new interface
        snprintf(path, sizeof(path), "/Devices/ip/%i", Iface->Num);
-       Iface->IfaceFD = fd = open(path, 0);
+       Iface->IfaceFD = fd = _SysOpen(path, 0);
        if( fd == -1 ) {
                fprintf(stderr, "ERROR: Unable to open '%s'\n", path); 
                return -1;
        }
-       tmp = 4; ioctl(fd, 4, &tmp);    // Set to IPv4
-       ioctl(fd, 6, addr);     // Set address to 0.0.0.0
-       tmp = 0; ioctl(fd, 7, &tmp);    // Set subnet mask to 0
+       tmp = 4; _SysIOCtl(fd, 4, &tmp);        // Set to IPv4
+       _SysIOCtl(fd, 6, addr); // Set address to 0.0.0.0
+       tmp = 0; _SysIOCtl(fd, 7, &tmp);        // Set subnet mask to 0
 
        // Open UDP Client
        snprintf(path, sizeof(path), "/Devices/ip/%i/udp", Iface->Num);
-       Iface->SocketFD = fd = open(path, O_RDWR);
+       Iface->SocketFD = fd = _SysOpen(path, O_RDWR);
        if( fd == -1 ) {
                fprintf(stderr, "ERROR: Unable to open '%s'\n", path); 
                return -1;
        }
-       tmp = 68; ioctl(fd, 4, &tmp);   // Local port
-       tmp = 67; ioctl(fd, 5, &tmp);   // Remote port
-       tmp = 0;        ioctl(fd, 7, &tmp);     // Remote addr mask bits - we don't care where the reply comes from
+       tmp = 68; _SysIOCtl(fd, 4, &tmp);       // Local port
+       tmp = 67; _SysIOCtl(fd, 5, &tmp);       // Remote port
+       tmp = 0;        _SysIOCtl(fd, 7, &tmp); // Remote addr mask bits - we don't care where the reply comes from
        addr[0] = addr[1] = addr[2] = addr[3] = 255;    // 255.255.255.255
-       ioctl(fd, 8, addr);     // Remote address
+       _SysIOCtl(fd, 8, addr); // Remote address
        
        return 0;
 }
@@ -292,7 +294,7 @@ void Send_DHCPDISCOVER(tInterface *Iface)
        data[2] = 4;    data[3] = 0;    // AddrType
        data[4] = 255;  data[5] = 255;  data[6] = 255;  data[7] = 255;
 
-       write(Iface->SocketFD, data, sizeof(data));
+       _SysWrite(Iface->SocketFD, data, sizeof(data));
        Update_State(Iface, STATE_DISCOVER_SENT);
 }
 
@@ -338,7 +340,7 @@ void Send_DHCPREQUEST(tInterface *Iface, void *OfferPacket, int TypeOffset)
        ((uint8_t*)OfferPacket)[6] = 255;
        ((uint8_t*)OfferPacket)[7] = 255;
        
-       write(Iface->SocketFD, OfferPacket, 8 + sizeof(*msg) + i);
+       _SysWrite(Iface->SocketFD, OfferPacket, 8 + sizeof(*msg) + i);
        Update_State(Iface, STATE_REQUEST_SENT);
 }
 
@@ -353,7 +355,7 @@ int Handle_Packet(tInterface *Iface)
        void    *subnet_mask = NULL;
        
        _SysDebug("Doing read on %i", Iface->SocketFD);
-       len = read(Iface->SocketFD, data, sizeof(data));
+       len = _SysRead(Iface->SocketFD, data, sizeof(data));
        _SysDebug("len = %i", len);
 
        _SysDebug("*msg = {");
@@ -510,8 +512,8 @@ void SetAddress(tInterface *Iface, void *Addr, void *Mask, void *Router)
                        );
        }
 
-       ioctl(Iface->IfaceFD, 6, Addr);
-       ioctl(Iface->IfaceFD, 7, &mask_bits);
+       _SysIOCtl(Iface->IfaceFD, 6, Addr);
+       _SysIOCtl(Iface->IfaceFD, 7, &mask_bits);
 
        if( Router );
        {
@@ -520,16 +522,16 @@ void SetAddress(tInterface *Iface, void *Addr, void *Mask, void *Router)
                
                // Set default route
                 int    fd;
-               fd = open("/Devices/ip/routes/4:00000000:0:0", OPENFLAG_CREATE);
+               fd = _SysOpen("/Devices/ip/routes/4:00000000:0:0", OPENFLAG_CREATE);
                if(fd == -1) {
                        fprintf(stderr, "ERROR: Unable to open default route\n");
                }
                else {
                        char ifname[snprintf(NULL,0,"%i",Iface->Num)+1];
                        sprintf(ifname, "%i", Iface->Num);
-                       ioctl(fd, ioctl(fd, 3, "set_nexthop"), Router);
-                       ioctl(fd, ioctl(fd, 3, "set_interface"), ifname);
-                       close(fd);
+                       _SysIOCtl(fd, _SysIOCtl(fd, 3, "set_nexthop"), Router);
+                       _SysIOCtl(fd, _SysIOCtl(fd, 3, "set_interface"), ifname);
+                       _SysClose(fd);
                }
        }
 }
index a6ed8aa..032a968 100644 (file)
@@ -10,6 +10,7 @@
 #include <axwin3/menu.h>
 #include <axwin3/richtext.h>
 #include <stdio.h>
+#include "strings.h"
 
 // === PROTOTYPES ===
  int   main(int argc, char *argv[]);
index f5524bc..c7aac85 100644 (file)
@@ -86,7 +86,7 @@ int main(int argc, char *argv[], const char **envp)
                        int len = read(giChildStdout, buf, sizeof(buf));
                        if( len <= 0 )  break;
                        
-                       //Term_HandleOutput(len, buf);
+                       Term_HandleOutput(len, buf);
                }
        }
 
index c18e5f8..5a4633c 100644 (file)
@@ -37,16 +37,17 @@ int main(int argc, char *argv[])
                {
                        termpath[sizeof(DEFAULT_TERMINAL)-2] = '0' + i;
                        
-                       open(termpath, OPENFLAG_READ);  // Stdin
-                       open(termpath, OPENFLAG_WRITE); // Stdout
-                       open(termpath, OPENFLAG_WRITE); // Stderr
+                       _SysOpen(termpath, OPENFLAG_READ);      // Stdin
+                       _SysOpen(termpath, OPENFLAG_WRITE);     // Stdout
+                       _SysOpen(termpath, OPENFLAG_WRITE);     // Stderr
                        execve(DEFAULT_SHELL, child_argv, NULL);
-                       for(;;) sleep();
+                       for(;;) ;
                }
        }
        
        // TODO: Implement message watching
-       for(;;) sleep();
+       for(;;)
+               _SysWaitEvent(THREAD_EVENT_IPCMSG);
        
        return 42;
 }
index cf5d5dc..2046bb0 100644 (file)
@@ -61,9 +61,9 @@ int AddInterface(const char *Device)
 {
         int    dp, ret;
        
-       dp = open(IPSTACK_ROOT, OPENFLAG_READ);
-       ret = ioctl(dp, 4, (void*)Device);
-       close(dp);
+       dp = _SysOpen(IPSTACK_ROOT, OPENFLAG_READ);
+       ret = _SysIOCtl(dp, 4, (void*)Device);
+       _SysClose(dp);
        
        if( ret < 0 ) {
                fprintf(stderr, "Unable to add '%s' as a network interface\n", Device);
@@ -94,26 +94,26 @@ int SetAddress(int IFNum, const char *Address)
        
        // Open file
        sprintf(path, IPSTACK_ROOT"/%i", IFNum);
-       fd = open(path, OPENFLAG_READ);
+       fd = _SysOpen(path, OPENFLAG_READ);
        if( fd == -1 ) {
                fprintf(stderr, "Unable to open '%s'\n", path);
                return -1;
        }
        
        tmp = type;
-       tmp = ioctl(fd, ioctl(fd, 3, "getset_type"), &tmp);
+       tmp = _SysIOCtl(fd, _SysIOCtl(fd, 3, "getset_type"), &tmp);
        if( tmp != type ) {
                fprintf(stderr, "Error in setting address type (got %i, expected %i)\n", tmp, type);
-               close(fd);
+               _SysClose(fd);
                return -1;
        }
        // Set Address
-       ioctl(fd, ioctl(fd, 3, "set_address"), addr);
+       _SysIOCtl(fd, _SysIOCtl(fd, 3, "set_address"), addr);
        
        // Set Subnet
-       ioctl(fd, ioctl(fd, 3, "getset_subnet"), &subnet);
+       _SysIOCtl(fd, _SysIOCtl(fd, 3, "getset_subnet"), &subnet);
        
-       close(fd);
+       _SysClose(fd);
        
        // Dump!
        //DumpInterface( path+sizeof(IPSTACK_ROOT)+1 );
@@ -129,15 +129,15 @@ void DumpInterfaces(void)
         int    dp;
        char    filename[FILENAME_MAX+1];
        
-       dp = open(IPSTACK_ROOT, OPENFLAG_READ);
+       dp = _SysOpen(IPSTACK_ROOT, OPENFLAG_READ);
        
-       while( SysReadDir(dp, filename) )
+       while( _SysReadDir(dp, filename) )
        {
                if(filename[0] == '.')  continue;
                DumpInterface(filename);
        }
        
-       close(dp);
+       _SysClose(dp);
 }
 
 /**
@@ -151,13 +151,13 @@ void DumpInterface(const char *Name)
        
        strcat(path, Name);
        
-       fd = open(path, OPENFLAG_READ);
+       fd = _SysOpen(path, OPENFLAG_READ);
        if(fd == -1) {
                fprintf(stderr, "Bad interface name '%s' (%s does not exist)\t", Name, path);
                return ;
        }
        
-       type = ioctl(fd, 4, NULL);
+       type = _SysIOCtl(fd, 4, NULL);
        
        // Ignore -1 values
        if( type == -1 ) {
@@ -166,10 +166,10 @@ void DumpInterface(const char *Name)
        
        printf("%s:\t", Name);
        {
-                int    call_num = ioctl(fd, 3, "get_device");
-                int    len = ioctl(fd, call_num, NULL);
+                int    call_num = _SysIOCtl(fd, 3, "get_device");
+                int    len = _SysIOCtl(fd, call_num, NULL);
                char    *buf = malloc(len+1);
-               ioctl(fd, call_num, buf);
+               _SysIOCtl(fd, call_num, buf);
                printf("'%s'\n", buf);
                free(buf);
        }
@@ -185,8 +185,8 @@ void DumpInterface(const char *Name)
                uint8_t ip[4];
                 int    subnet;
                printf("IPv4\t");
-               ioctl(fd, 5, ip);       // Get IP Address
-               subnet = ioctl(fd, 7, NULL);    // Get Subnet Bits
+               _SysIOCtl(fd, 5, ip);   // Get IP Address
+               subnet = _SysIOCtl(fd, 7, NULL);        // Get Subnet Bits
                printf("%i.%i.%i.%i/%i\n", ip[0], ip[1], ip[2], ip[3], subnet);
                }
                break;
@@ -195,8 +195,8 @@ void DumpInterface(const char *Name)
                uint16_t        ip[8];
                 int    subnet;
                printf("IPv6\t");
-               ioctl(fd, 5, ip);       // Get IP Address
-               subnet = ioctl(fd, 7, NULL);    // Get Subnet Bits
+               _SysIOCtl(fd, 5, ip);   // Get IP Address
+               subnet = _SysIOCtl(fd, 7, NULL);        // Get Subnet Bits
                printf("%x:%x:%x:%x:%x:%x:%x:%x/%i\n",
                        ntohs(ip[0]), ntohs(ip[1]), ntohs(ip[2]), ntohs(ip[3]),
                        ntohs(ip[4]), ntohs(ip[5]), ntohs(ip[6]), ntohs(ip[7]),
@@ -208,6 +208,6 @@ void DumpInterface(const char *Name)
                break;
        }
                        
-       close(fd);
+       _SysClose(fd);
 }
 
index f074bff..ba56813 100644 (file)
@@ -12,7 +12,7 @@
 // === PROTOTYPES ===
  int   Routes_main(int argc, char *argv[]);
 void   DumpRoutes(void);
-void   DumpRoute(const char *Name);
+void   DumpRoute(int PFD, const char *Name);
 void   AddRoute(const char *Interface, int AddressType, void *Dest, int MaskBits, int Metric, void *NextHop);
 
 // === CODE ===
@@ -114,33 +114,30 @@ void DumpRoutes(void)
         int    dp;
        char    filename[FILENAME_MAX+1];
        
-       dp = open(IPSTACK_ROOT"/routes", OPENFLAG_READ);
+       dp = _SysOpen(IPSTACK_ROOT"/routes", OPENFLAG_READ);
        
        printf("Type\tNetwork \tGateway \tMetric\tIFace\n");
        
-       while( SysReadDir(dp, filename) )
+       while( _SysReadDir(dp, filename) )
        {
                if(filename[0] == '.')  continue;
-               DumpRoute(filename);
+               DumpRoute(dp, filename);
        }
        
-       close(dp);
+       _SysClose(dp);
 }
 
 /**
  * \brief Dump a route
  */
-void DumpRoute(const char *Name)
+void DumpRoute(int PFD, const char *Name)
 {
         int    fd;
         int    type;
-       char    path[sizeof(IPSTACK_ROOT)+8+FILENAME_MAX+1] = IPSTACK_ROOT"/routes/";
        
-       strcat(path, Name);
-       
-       fd = open(path, OPENFLAG_READ);
+       fd = _SysOpenChild(PFD, Name, OPENFLAG_READ);
        if(fd == -1) {
-               printf("%s:\tUnable to open ('%s')\n", Name, path);
+               printf("%s:\tUnable to open\n", Name);
                return ;
        }
        
@@ -161,7 +158,7 @@ void DumpRoute(const char *Name)
        subnet = atoi(Name+ofs);
        ofs ++;
        metric = atoi(Name+ofs);
-       ioctl(fd, ioctl(fd, 3, "get_nexthop"), gw);     // Get Gateway/NextHop
+       _SysIOCtl(fd, _SysIOCtl(fd, 3, "get_nexthop"), gw);     // Get Gateway/NextHop
        
        // Get the address type
        switch(type)
@@ -185,17 +182,17 @@ void DumpRoute(const char *Name)
        
        // Interface
        {
-                int    call_num = ioctl(fd, 3, "get_interface");
-                int    len = ioctl(fd, call_num, NULL);
+                int    call_num = _SysIOCtl(fd, 3, "get_interface");
+                int    len = _SysIOCtl(fd, call_num, NULL);
                char    *buf = malloc(len+1);
-               ioctl(fd, call_num, buf);
+               _SysIOCtl(fd, call_num, buf);
                printf("'%s'\t", buf);
                free(buf);
        }
        
        printf("\n");
                        
-       close(fd);
+       _SysClose(fd);
 }
 
 void AddRoute(const char *Interface, int AddressType, void *Dest, int MaskBits, int Metric, void *NextHop)
@@ -227,20 +224,20 @@ void AddRoute(const char *Interface, int AddressType, void *Dest, int MaskBits,
                // Open interface
                strcpy(ifacePath, IPSTACK_ROOT"/");
                strcat(ifacePath, Interface);
-               fd = open(ifacePath, 0);
+               fd = _SysOpen(ifacePath, 0);
                if( fd == -1 ) {
                        fprintf(stderr, "Error: Interface '%s' does not exist\n", Interface);
                        return ;
                }
                // Get and check type
-               num = ioctl(fd, ioctl(fd, 3, "getset_type"), NULL);
+               num = _SysIOCtl(fd, _SysIOCtl(fd, 3, "getset_type"), NULL);
                if( num != AddressType ) {
                        fprintf(stderr, "Error: Passed type does not match interface type (%i != %i)\n",
                                AddressType, num);
                        return ;
                }
                
-               close(fd);
+               _SysClose(fd);
        }
        
        // Create route
@@ -256,23 +253,23 @@ void AddRoute(const char *Interface, int AddressType, void *Dest, int MaskBits,
                sprintf(path+ofs, ":%i:%i", MaskBits, Metric);
        }
 
-       fd = open(path, 0);
+       fd = _SysOpen(path, 0);
        if( fd != -1 ) {
-               close(fd);
+               _SysClose(fd);
                fprintf(stderr, "Unable to create route '%s', already exists\n", path);
                return ;
        }
-       fd = open(path, OPENFLAG_CREATE, 0);
+       fd = _SysOpen(path, OPENFLAG_CREATE, 0);
        if( fd == -1 ) {
                fprintf(stderr, "Unable to create '%s'\n", path);
                return ;
        }
        
        if( NextHop )
-               ioctl(fd, ioctl(fd, 3, "set_nexthop"), NextHop);
-       ioctl(fd, ioctl(fd, 3, "set_interface"), (void*)Interface);
+               _SysIOCtl(fd, _SysIOCtl(fd, 3, "set_nexthop"), NextHop);
+       _SysIOCtl(fd, _SysIOCtl(fd, 3, "set_interface"), (void*)Interface);
        
-       close(fd);
+       _SysClose(fd);
        
        // Check if the interface name was allocated by us
        if( ifaceToFree )
index 901e8ac..9e5a075 100644 (file)
@@ -102,8 +102,8 @@ int main(int argc, const char *argv[], const char *envp[])
        \r
        atexit(ExitHandler);\r
        \r
-       giTerminal_Width = ioctl(1, 5, NULL);   // getset_width\r
-       giTerminal_Height = ioctl(1, 6, NULL);  // getset_height\r
+       giTerminal_Width = _SysIOCtl(1, 5, NULL);       // getset_width\r
+       giTerminal_Height = _SysIOCtl(1, 6, NULL);      // getset_height\r
        \r
        printf("\x1B[?1047h");\r
        printf("\x1B[%i;%ir", 0, giTerminal_Height-1);\r
@@ -194,7 +194,7 @@ int main(int argc, const char *argv[], const char *envp[])
        {\r
                tServer *srv;\r
                for( srv = gpServers; srv; srv = srv->Next )\r
-                       close(srv->FD);\r
+                       _SysClose(srv->FD);\r
        }\r
        return 0;\r
 }\r
@@ -659,11 +659,11 @@ int ProcessIncoming(tServer *Server)
        // ioctl#8 on a TCP client gets the number of bytes in the recieve buffer\r
        // - Used to avoid blocking\r
        #if NON_BLOCK_READ\r
-       while( (len = ioctl(Server->FD, 8, NULL)) > 0 )\r
+       while( (len = _SysIOCtl(Server->FD, 8, NULL)) > 0 )\r
        {\r
        #endif\r
                // Read data\r
-               len = read(Server->FD, &Server->InBuf[Server->ReadPos], BUFSIZ - Server->ReadPos);\r
+               len = _SysRead(Server->FD, &Server->InBuf[Server->ReadPos], BUFSIZ - Server->ReadPos);\r
                if( len == -1 ) {\r
                        return -1;\r
                }\r
@@ -717,7 +717,7 @@ int writef(int FD, const char *Format, ...)
                vsnprintf(buf, len+1, Format, args);\r
                va_end(args);\r
                \r
-               return write(FD, buf, len);\r
+               return _SysWrite(FD, buf, len);\r
        }\r
 }\r
 \r
@@ -747,12 +747,12 @@ int OpenTCP(const char *AddressString, short PortNumber)
        \r
        // Set remote port and address\r
 //     printf("Setting port and remote address\n");\r
-       ioctl(fd, 5, &PortNumber);\r
-       ioctl(fd, 6, addrBuffer);\r
+       _SysIOCtl(fd, 5, &PortNumber);\r
+       _SysIOCtl(fd, 6, addrBuffer);\r
        \r
        // Connect\r
 //     printf("Initiating connection\n");\r
-       if( ioctl(fd, 7, NULL) == 0 ) {\r
+       if( _SysIOCtl(fd, 7, NULL) == 0 ) {\r
                // Shouldn't happen :(\r
                fprintf(stderr, "Unable to start connection\n");\r
                return -1;\r
@@ -797,7 +797,7 @@ int SetCursorPos(int Row, int Col)
                Row = Col / giTerminal_Width;\r
                Col = Col % giTerminal_Width;\r
        }\r
-       rv = ioctl(1, 9, NULL); // Ugh, constants\r
+       rv = _SysIOCtl(1, 9, NULL);     // Ugh, constants\r
        printf("\x1B[%i;%iH", Col, Row);\r
        return rv;\r
 }\r
index 2394af6..973013b 100644 (file)
@@ -51,17 +51,17 @@ int main(int argc, char *argv[])
        ParseArguments(argc, argv);
 
        // Open Directory
-       fd = open(gsDirectory, OPENFLAG_READ|OPENFLAG_EXEC);
+       fd = _SysOpen(gsDirectory, OPENFLAG_READ|OPENFLAG_EXEC);
        if(fd == -1) {
                printf("Unable to open '%s' for reading\n", gsDirectory);
                return EXIT_FAILURE;
        }
 
        // Check that it is a directory
-       finfo(fd, &info, 0);
+       _SysFInfo(fd, &info, 0);
        if( !(info.flags & FILEFLAG_DIRECTORY) ) {
                fprintf(stderr, "'%s' is not a directory\n", gsDirectory);
-               close(fd);
+               _SysClose(fd);
                return EXIT_FAILURE;
        }
 
@@ -75,11 +75,11 @@ int main(int argc, char *argv[])
        }
 
        // Traverse Directory
-       while( (tmp = SysReadDir(fd, buf)) > 0 )
+       while( (tmp = _SysReadDir(fd, buf)) > 0 )
        {
                // Error check
                if(tmp < 0) {
-                       close(fd);
+                       _SysClose(fd);
                        return EXIT_FAILURE;
                }
                
@@ -89,7 +89,7 @@ int main(int argc, char *argv[])
                        space += 16;
                        gFileList = realloc(gFileList, space*sizeof(char*));
                        if(gFileList == NULL) {
-                               close(fd);
+                               _SysClose(fd);
                                return EXIT_FAILURE;
                        }
                }
@@ -105,7 +105,7 @@ int main(int argc, char *argv[])
                DisplayFile( gFileList[i] );
        }
 
-       close(fd);
+       _SysClose(fd);
        printf("\n");
 
        return EXIT_SUCCESS;
@@ -218,13 +218,13 @@ void DisplayFile(char *Filename)
        strcpy(&path[dirLen+1], Filename);
        
        // Get file type
-       fd = open(path, 0);
+       fd = _SysOpen(path, 0);
        if(fd == -1) {
                fprintf(stderr, "Unable to open '%s'\n", path);
        }
        else {
                // Get Info
-               finfo(fd, &info, 0);
+               _SysFInfo(fd, &info, 0);
                // Get Type
                if(info.flags & FILEFLAG_DIRECTORY) {
                        type = FTYPE_DIR;
@@ -262,7 +262,7 @@ void DisplayFile(char *Filename)
                if(acl.perms & 8)       perms |= 0001;  // X
                
                // Close file
-               close(fd);
+               _SysClose(fd);
        }
        free(path);     // We're finished with it
        
index c24fde9..44dc61a 100644 (file)
@@ -6,7 +6,6 @@
  */
 #include <stdlib.h>
 #include <stdio.h>
-#include <unistd.h>
 #include <acess/sys.h>
 
 #define PCI_BASE       "/Devices/pci"
@@ -17,17 +16,19 @@ void        show_device(int PFD, const char *File, int bVerbose);
 // === CODE ===
 int main(int argc, char *argv[])
 {
-       int fd = open(PCI_BASE, OPENFLAG_READ);
+       int fd = _SysOpen(PCI_BASE, OPENFLAG_READ);
 
        char name[256]; 
 
-       while( SysReadDir(fd, name) )
+       while( _SysReadDir(fd, name) )
        {
                if(name[0] == '.')      continue ;
                
                show_device(fd, name, 0);
        }
 
+       _SysClose(fd);
+
        return 0;
 }
 
@@ -48,10 +49,10 @@ void show_device(int PFD, const char *File, int bVerbose)
                printf("%s - ERR (open failure)\n", File);
                return ;
        }
-       rv = read(fd, &pciinfo, sizeof(pciinfo));
+       rv = _SysRead(fd, &pciinfo, sizeof(pciinfo));
        if( rv != sizeof(pciinfo) ) {
                printf("%s - ERR (read %i < %i)\n", File, rv, sizeof(pciinfo));
-               close(fd);
+               _SysClose(fd);
                return ;
        }
        uint32_t        class_if = pciinfo.revclass >> 8;
@@ -67,6 +68,6 @@ void show_device(int PFD, const char *File, int bVerbose)
                printf("\n");
        }
 
-       close(fd);
+       _SysClose(fd);
 }
 
index 7c401bd..1a1fc7b 100644 (file)
@@ -142,20 +142,20 @@ int main(int argc, char *argv[])
        }
        
        // Check Device
-       fd = open(sDevice, OPENFLAG_READ);
+       fd = _SysOpen(sDevice, OPENFLAG_READ);
        if(fd == -1) {
                printf("Device '%s' cannot be opened for reading\n", sDevice);
                return EXIT_FAILURE;
        }
-       close(fd);
+       _SysClose(fd);
        
        // Check Mount Point
-       fd = open(sDir, OPENFLAG_EXEC);
+       fd = _SysOpen(sDir, OPENFLAG_EXEC);
        if(fd == -1) {
                printf("Directory '%s' does not exist\n", sDir);
                return EXIT_FAILURE;
        }
-       close(fd);
+       _SysClose(fd);
 
        // Replace sOptions with an empty string if it is still NULL
        if(sOptions == NULL)    sOptions = "";
index 7686e5c..7c10e57 100644 (file)
@@ -88,7 +88,7 @@ int main(int argc, char *argv[])
                free(iface);    // TODO: Handle when this is not heap
                iface = _iface;
                printf("iface = '%s'\n", iface);
-               fd = open(iface, OPENFLAG_EXEC);
+               fd = _SysOpen(iface, OPENFLAG_EXEC);
                if(fd == -1) {
                        fprintf(stderr, "ERROR: Unable to open interface '%s'\n", iface);
                        return 1;
@@ -106,7 +106,7 @@ int main(int argc, char *argv[])
                }
        }
        
-       call = ioctl(fd, 3, "ping");
+       call = _SysIOCtl(fd, 3, "ping");
        if(call == 0) {
                fprintf(stderr, "ERROR: '%s' does not have a 'ping' call\n", iface);
                return 1;
@@ -114,11 +114,11 @@ int main(int argc, char *argv[])
        
        for( i = 0; i < giNumberOfPings; i ++ )
        {
-               ping = ioctl(fd, call, addr);
+               ping = _SysIOCtl(fd, call, addr);
                printf("ping = %i\n", ping);
        }
                
-       close(fd);
+       _SysClose(fd);
        
        return 0;
 }
index 3fdbf00..708935d 100644 (file)
@@ -62,8 +62,8 @@ int main(int argc, char *argv[], char *envp[])
                        // Read from server, and write to stdout\r
                        do\r
                        {\r
-                               len = read(server_fd, buffer, BUFSIZ);\r
-                               write(1, buffer, len);\r
+                               len = _SysRead(server_fd, buffer, BUFSIZ);\r
+                               _SysWrite(1, buffer, len);\r
                        } while( len == BUFSIZ );\r
                }\r
                \r
@@ -76,17 +76,17 @@ int main(int argc, char *argv[], char *envp[])
                                char    *line = Readline_NonBlock(readline_info);\r
                                if( line )\r
                                {\r
-                                       write(server_fd, line, strlen(line));\r
-                                       write(server_fd, "\n", 1);\r
+                                       _SysWrite(server_fd, line, strlen(line));\r
+                                       _SysWrite(server_fd, "\n", 1);\r
                                }\r
                        }\r
                        else\r
                        {\r
                                do\r
                                {\r
-                                       len = read(0, buffer, BUFSIZ);\r
-                                       write(server_fd, buffer, len);\r
-                                       write(1, buffer, len);\r
+                                       len = _SysRead(0, buffer, BUFSIZ);\r
+                                       _SysWrite(server_fd, buffer, len);\r
+                                       _SysWrite(1, buffer, len);\r
                                } while( len == BUFSIZ );\r
                        }\r
                }\r
@@ -99,7 +99,7 @@ int main(int argc, char *argv[], char *envp[])
                }\r
        }\r
        \r
-       close(server_fd);\r
+       _SysClose(server_fd);\r
        return 0;\r
 }\r
 \r
@@ -127,11 +127,11 @@ int OpenTCP(const char *AddressString, short PortNumber)
        }\r
        \r
        // Set remote port and address\r
-       ioctl(fd, 5, &PortNumber);\r
-       ioctl(fd, 6, addrBuffer);\r
+       _SysIOCtl(fd, 5, &PortNumber);\r
+       _SysIOCtl(fd, 6, addrBuffer);\r
        \r
        // Connect\r
-       if( ioctl(fd, 7, NULL) == 0 ) {\r
+       if( _SysIOCtl(fd, 7, NULL) == 0 ) {\r
                fprintf(stderr, "Unable to start connection\n");\r
                return -1;\r
        }\r
index a62d0dd..a4f5e0d 100644 (file)
@@ -1,9 +1,14 @@
 /*
+ * Acess2 Telnet Server (TCP server test case)
+ * - By John Hodge (thePowersGang)
+ *
+ * main.c
+ * - All
  */
 #include <stddef.h>
 #include <net.h>
-#include <unistd.h>
 #include <stdio.h>
+#include <acess/sys.h>
 
 // === TYPES ===
 typedef struct sClient
@@ -41,7 +46,7 @@ int main(int argc, char *argv[])
                 int    addrtype = Net_ParseAddress("10.0.2.10", data);
                 int    port = 23;
                giServerFD = Net_OpenSocket(addrtype, data, "tcps");
-               ioctl(giServerFD, 4, &port);    // Set port and start listening
+               _SysIOCtl(giServerFD, 4, &port);        // Set port and start listening
        }
 
        // Event loop
@@ -77,7 +82,7 @@ void EventLoop(void)
                }
                
                // Select!
-               select( maxfd+1, &fds, NULL, NULL, NULL );
+               _SysSelect( maxfd+1, &fds, NULL, NULL, NULL, 0 );
                
                // Check events
                if( FD_ISSET(giServerFD, &fds) )
@@ -108,7 +113,7 @@ void Server_NewClient(int FD)
        if( giNumClients == giConfig_MaxClients )
        {
                // Open, reject
-               close( _SysOpenChild(FD, "", O_RDWR) );
+               _SysClose( _SysOpenChild(FD, "", OPENFLAG_READ) );
                return ;
        }
        
@@ -121,12 +126,12 @@ void Server_NewClient(int FD)
                }
        }
        // Accept the connection
-       clt->Socket = _SysOpenChild(FD, "", O_RDWR);
+       clt->Socket = _SysOpenChild(FD, "", OPENFLAG_READ|OPENFLAG_WRITE);
        giNumClients ++;
        
        // Create stdin/stdout
-       clt->stdin = open("/Devices/fifo/anon", O_RDWR);
-       clt->stdout = open("/Devices/fifo/anon", O_RDWR);
+       clt->stdin = _SysOpen("/Devices/fifo/anon", OPENFLAG_READ|OPENFLAG_WRITE);
+       clt->stdout = _SysOpen("/Devices/fifo/anon", OPENFLAG_READ|OPENFLAG_WRITE);
        
        // TODO: Arguments and envp
        {
@@ -141,9 +146,9 @@ void HandleServerBoundData(tClient *Client)
        char    buf[BUFSIZ];
         int    len;
        
-       len = read(Client->Socket, buf, BUFSIZ);
+       len = _SysRead(Client->Socket, buf, BUFSIZ);
        if( len <= 0 )  return ;
-       write(Client->stdin, buf, len);
+       _SysWrite(Client->stdin, buf, len);
 }
 
 void HandleClientBoundData(tClient *Client)
@@ -151,8 +156,8 @@ void HandleClientBoundData(tClient *Client)
        char    buf[BUFSIZ];
         int    len;
        
-       len = read(Client->stdout, buf, BUFSIZ);
+       len = _SysRead(Client->stdout, buf, BUFSIZ);
        if( len <= 0 )  return ;
-       write(Client->Socket, buf, len);
+       _SysWrite(Client->Socket, buf, len);
 }
 
index 3410840..9b5391f 100644 (file)
@@ -11,6 +11,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <netdb.h>
+#include <acess/sys.h> // _SysDebug
 
 enum eProcols
 {
@@ -164,7 +165,7 @@ int main(int argc, char *argv[])
                        if( state == 2 )
                        {
                                _SysDebug("RXing %i bytes to '%s'", bytes_wanted, outfile);
-                                int    outfd = open(outfile, O_WR|O_CREAT, 0666);
+                                int    outfd = open(outfile, O_WRONLY|O_CREAT, 0666);
                                if( outfd == -1 ) {
                                        fprintf(stderr, "Unable to open '%s' for writing\n", outfile);
                                }
index a59e857..77d88ce 100644 (file)
@@ -5,8 +5,8 @@ SYSCALL1(_exit, SYS_EXIT)
 
 SYSCALL2(clone, SYS_CLONE)
 SYSCALL2(kill, SYS_KILL)
-SYSCALL0(yield, SYS_YIELD)
-SYSCALL0(sleep, SYS_SLEEP)
+//SYSCALL0(yield, SYS_YIELD)
+//SYSCALL0(sleep, SYS_SLEEP)
 SYSCALL1(_SysWaitEvent, SYS_WAITEVENT)
 SYSCALL2(waittid, SYS_WAITTID)
 
@@ -39,20 +39,20 @@ SYSCALL1(_SysGetPhys, SYS_GETPHYS)  // uint64_t _SysGetPhys(uint addr)
 SYSCALL1(_SysAllocate, SYS_ALLOCATE)   // uint64_t _SysAllocate(uint addr)
 SYSCALL3(SysSetMemFlags, SYS_SETFLAGS) // uint32_t SysSetMemFlags(uint addr, uint flags, uint mask)
 // VFS System calls
-SYSCALL2(open, SYS_OPEN)       // char*, int
-SYSCALL3(reopen, SYS_REOPEN)   // int, char*, int
-SYSCALL1(close, SYS_CLOSE)     // int
-SYSCALL3(read, SYS_READ)       // int, uint, void*
-SYSCALL3(write, SYS_WRITE)     // int, uint, void*
-SYSCALL4(seek, SYS_SEEK)       // int, uint64_t, int
-SYSCALL1(tell, SYS_TELL)       // int
-SYSCALL3(finfo, SYS_FINFO)     // int, void*, int
-SYSCALL2(SysReadDir, SYS_READDIR)      // int, char*
+SYSCALL2(_SysOpen, SYS_OPEN)   // char*, int
+SYSCALL3(_SysOpenChild, SYS_OPENCHILD) // int, char*, int
+SYSCALL3(_SysReopen, SYS_REOPEN)       // int, char*, int
+SYSCALL1(_SysClose, SYS_CLOSE) // int
+SYSCALL3(_SysRead, SYS_READ)   // int, uint, void*
+SYSCALL3(_SysWrite, SYS_WRITE) // int, uint, void*
+SYSCALL4(_SysSeek, SYS_SEEK)   // int, uint64_t, int
+SYSCALL1(_SysTell, SYS_TELL)   // int
+SYSCALL3(_SysFInfo, SYS_FINFO) // int, void*, int
+SYSCALL2(_SysReadDir, SYS_READDIR)     // int, char*
 SYSCALL2(_SysGetACL,SYS_GETACL)        // int, void*
-SYSCALL1(chdir, SYS_CHDIR)     // char*
-SYSCALL3(ioctl, SYS_IOCTL)     // int, int, void*
+SYSCALL1(_SysChdir, SYS_CHDIR) // char*
+SYSCALL3(_SysIOCtl, SYS_IOCTL) // int, int, void*
 SYSCALL4(_SysMount, SYS_MOUNT) // char*, char*, char*, char*
 SYSCALL6(_SysSelect, SYS_SELECT)       // int, fd_set*, fd_set*, fd_set*, tTime*, uint32_t
-SYSCALL1(unlink, SYS_UNLINK)   // const char*
+SYSCALL1(_SysUnlink, SYS_UNLINK)       // const char*
 
-SYSCALL3(_SysOpenChild, SYS_OPENCHILD)
index eb9b83b..fa1957f 100644 (file)
@@ -10,6 +10,7 @@
 #include <stddef.h>
 #include <stdarg.h>
 #include <stdint.h>
+#include <acess/sys.h>
 
 typedef        uintptr_t       Uint;
 typedef uint8_t        Uint8;
@@ -51,14 +52,11 @@ extern int  file_exists(const char *filename);
 extern void    *memcpy(void *dest, const void *src, size_t len);
 
 // === System Calls ===
-extern void    _exit(int retval);
 extern void    SysDebug(const char *fmt, ...); //!< Now implemented in main.c
 extern void    SysDebugV(const char *fmt, ...);
 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 int     close(int fd);
 
 // === ELF Loader ===
 extern void    *ElfRelocate(void *Base, char **envp, const char *Filename);
diff --git a/Usermode/Libraries/ld-acess.so_src/include_exp/acess/fd_set.h b/Usermode/Libraries/ld-acess.so_src/include_exp/acess/fd_set.h
new file mode 100644 (file)
index 0000000..0793901
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Acess2 Dynamic Linker
+ * - By John Hodge (thePowersGang)
+ *
+ * acess/fd_set.h
+ * - fd_set structure used by select()
+ */
+#ifndef _ACESS__FD_SET_H_
+#define _ACESS__FD_SET_H_
+
+#define FD_SETSIZE     128
+
+typedef unsigned short fd_set_ent_t;
+
+/**
+ * \brief fd_set for select()
+ */
+typedef struct
+{
+       fd_set_ent_t    flags[FD_SETSIZE/16];
+}      fd_set;
+
+
+extern void    FD_ZERO(fd_set *fdsetp);
+extern void    FD_CLR(int fd, fd_set *fdsetp);
+extern void    FD_SET(int fd, fd_set *fdsetp);
+extern int     FD_ISSET(int fd, fd_set *fdsetp);
+
+#endif
index b5d0f0c..0f9a5f9 100644 (file)
@@ -5,7 +5,8 @@
 #define _ACESS_SYS_H_
 
 #include <stdint.h>
-#include "../sys/types.h"
+#include <stddef.h>    // size_t
+#include "syscall_types.h"
 
 // === CONSTANTS ===
 #ifndef NULL
@@ -19,6 +20,7 @@
 #define OPENFLAG_EXEC  0x01
 #define OPENFLAG_READ  0x02
 #define OPENFLAG_WRITE 0x04
+#define OPENFLAG_RDWR  (OPENFLAG_READ|OPENFLAG_WRITE)
 #define OPENFLAG_TRUNCATE      0x10
 #define OPENFLAG_APPEND        0x20
 #define        OPENFLAG_NOLINK 0x40
@@ -41,8 +43,8 @@ extern int    _errno;
 extern void    _SysDebug(const char *format, ...);
 // --- Proc ---
 extern void    _exit(int status)       __attribute__((noreturn));
-extern void    sleep(void);
-extern void    yield(void);
+//extern void  sleep(void);
+//extern void  yield(void);
 extern int     kill(int pid, int sig);
 //extern void  wait(int miliseconds);
 extern int     _SysWaitEvent(int EventMask);
@@ -65,31 +67,35 @@ extern void setuid(int id);
 extern void    setgid(int id);
 
 // --- VFS ---
-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 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);
-extern int     finfo(int fd, t_sysFInfo *info, int maxacls);
-extern int     SysReadDir(int fd, char *dest);
+extern int     _SysChdir(const char *dir);
+extern int     _SysRoot(const char *dir);
+
+extern int     _SysOpen(const char *path, int flags, ...);
 extern int     _SysOpenChild(int fd, const char *name, int flags);
+extern int     _SysOpenPipe(int *read, int *write, int flags);
+extern int     _SysReopen(int fd, const char *path, int flags);
+extern int     _SysCopyFD(int srcfd, int dstfd);
+extern int     _SysClose(int fd);
+extern size_t  _SysRead(int fd, void *buffer, size_t length);
+extern size_t  _SysWrite(int fd, const void *buffer, size_t length);
+extern int     _SysSeek(int fd, int64_t offset, int whence);
+extern uint64_t        _SysTell(int fd);
+extern int     _SysIOCtl(int fd, int id, void *data);
+extern int     _SysFInfo(int fd, t_sysFInfo *info, int maxacls);
+extern int     _SysReadDir(int fd, char *dest);
 extern int     _SysGetACL(int fd, t_sysACL *dest);
 extern int     _SysMount(const char *Device, const char *Directory, const char *Type, const char *Options);
 extern int     _SysSelect(int nfds, fd_set *read, fd_set *write, fd_set *err, int64_t *timeout, unsigned int extraevents);
 #define select(nfs, rdfds, wrfds, erfds, timeout)      _SysSelect(nfs, rdfds, wrfds, erfds, timeout, 0)
-extern int     unlink(const char *pathname);
+extern int     _SysUnlink(const char *pathname);
 
 // --- IPC ---
-extern int     SysSendMessage(pid_t dest, uint length, const void *Data);
-extern int     SysGetMessage(pid_t *src, uint buflen, void *Data);
+extern int     SysSendMessage(int dest, size_t length, const void *Data);
+extern int     SysGetMessage(int *src, size_t buflen, void *Data);
 
 // --- MEMORY ---
-uint64_t       _SysGetPhys(uint vaddr);
-uint64_t       _SysAllocate(uint vaddr);
-uint32_t       SysSetMemFlags(uint vaddr, uint32_t flags, uint32_t mask);
+uint64_t       _SysGetPhys(uintptr_t vaddr);
+uint64_t       _SysAllocate(uintptr_t vaddr);
+uint32_t       SysSetMemFlags(uintptr_t vaddr, uint32_t flags, uint32_t mask);
 
 #endif
index 2da7333..c1f25c6 100644 (file)
@@ -5,10 +5,11 @@
  * acess/syscall_types.h
  * - Structures used for syscalls
  */
-
 #ifndef _ACESS__SYSCALL_TYPES_H_
 #define _ACESS__SYSCALL_TYPES_H_
 
+#include "fd_set.h"
+
 struct s_sysACL {
        unsigned long   object; /*!< Group or user (bit 31 determines) */
        unsigned long   perms;  /*!< Inverted by bit 31 */
@@ -20,9 +21,9 @@ struct s_sysFInfo {
        unsigned int    gid;
        unsigned int    flags;
        unsigned long long      size;
-       time_t  atime;
-       time_t  mtime;
-       time_t  ctime;
+       int64_t atime;
+       int64_t mtime;
+       int64_t ctime;
         int    numacls;
        struct s_sysACL acls[];
 } __attribute__((packed));
diff --git a/Usermode/Libraries/ld-acess.so_src/include_exp/sys/stat.h b/Usermode/Libraries/ld-acess.so_src/include_exp/sys/stat.h
deleted file mode 100644 (file)
index 4a1c107..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Acess2 C Library
- * - By John Hodge (thePowersGang)
- */
-#ifndef _SYS_STAT_H_
-#define _SYS_STAT_H_
-
-//#include "../acess/intdefs.h"        /* Evil */
-//#include "../stddef.h"
-#include <stdint.h>
-
-typedef void   *dev_t; /* TODO: How to identify a device with Acess */
-typedef uint64_t       ino_t;
-typedef unsigned int   blksize_t;
-typedef uint64_t       blkcnt_t;
-typedef unsigned int   nlink_t;
-typedef uint32_t       mode_t;
-
-typedef uint32_t       uid_t;
-typedef uint32_t       gid_t;
-
-#define        S_IFMT          0170000 /* type of file */
-#define                S_IFDIR 0040000 /* directory */
-#define                S_IFCHR 0020000 /* character special */
-#define                S_IFBLK 0060000 /* block special */
-#define                S_IFREG 0100000 /* regular */
-#define                S_IFLNK 0120000 /* symbolic link */
-#define                S_IFSOCK        0140000 /* socket */
-#define                S_IFIFO 0010000 /* fifo */
-
-
-struct stat
-{
-       dev_t     st_dev;     /* ID of device containing file */
-       ino_t     st_ino;     /* inode number */
-       mode_t    st_mode;    /* protection */
-       nlink_t   st_nlink;   /* number of hard links */
-       uid_t     st_uid;     /* user ID of owner */
-       gid_t     st_gid;     /* group ID of owner */
-       dev_t     st_rdev;    /* device ID (if special file) */
-       off_t     st_size;    /* total size, in bytes */
-       blksize_t st_blksize; /* blocksize for file system I/O */
-       blkcnt_t  st_blocks;  /* number of 512B blocks allocated */
-       time_t    st_atime;   /* time of last access */
-       time_t    st_mtime;   /* time of last modification */
-       time_t    st_ctime;   /* time of last status change */
-};
-
-extern int stat(const char *path, struct stat *buf);
-extern int fstat(int fd, struct stat *buf);
-
-#endif
diff --git a/Usermode/Libraries/ld-acess.so_src/include_exp/sys/types.h b/Usermode/Libraries/ld-acess.so_src/include_exp/sys/types.h
deleted file mode 100644 (file)
index 36d2dba..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- */
-#ifndef _SYS_TYPES_H
-#define _SYS_TYPES_H
-
-#include "../acess/intdefs.h"
-
-typedef signed int     ssize_t;
-//#ifdef  __USE_BSD
-typedef unsigned int   u_int;
-//#endif
-
-typedef struct stat    t_fstat;
-
-#define FD_SETSIZE     128
-
-
-#define CLONE_VM       0x10
-
-typedef unsigned int   id_t;
-typedef unsigned long  pid_t;
-typedef unsigned long  tid_t;
-typedef signed long long int   time_t;
-typedef long long int  off_t;
-
-typedef unsigned int   uint;
-
-typedef unsigned short fd_set_ent_t;
-
-/**
- * \brief fd_set for select()
- */
-typedef struct
-{
-       fd_set_ent_t    flags[FD_SETSIZE/16];
-}      fd_set;
-
-#include "../acess/syscall_types.h"
-
-extern void    FD_ZERO(fd_set *fdsetp);
-extern void    FD_CLR(int fd, fd_set *fdsetp);
-extern void    FD_SET(int fd, fd_set *fdsetp);
-extern int     FD_ISSET(int fd, fd_set *fdsetp);
-
-#include "../sys/stat.h"
-
-#endif
diff --git a/Usermode/Libraries/ld-acess.so_src/include_exp/unistd.h b/Usermode/Libraries/ld-acess.so_src/include_exp/unistd.h
deleted file mode 100644 (file)
index 54a6847..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-#ifndef _UNISTD_H_
-#define _UNISTD_H_
-
-#define        O_RDWR  (OPENFLAG_READ|OPENFLAG_WRITE)
-#define O_WR   (OPENFLAG_WRITE)
-#define O_RD   (OPENFLAG_READ)
-#define O_CREAT        (OPENFLAG_CREATE)
-#define O_RDONLY       OPENFLAG_READ
-#define O_WRONLY       OPENFLAG_WRITE
-#define O_TRUNC        OPENFLAG_TRUNCATE
-#define O_APPEND       OPENFLAG_APPEND
-#define O_NONBLOCK     0       // TODO: 
-
-#include "acess/sys.h"
-
-#define STDIN_FILENO   0
-#define STDOUT_FILENO  1
-#define STDERR_FILENO  2
-
-static inline int fork(void) { return clone(CLONE_VM, 0); }
-static inline int execv(const char *b,char *v[]) { return execve(b,v,NULL); }
-
-#endif
-
index 0672102..9b8f86a 100644 (file)
@@ -73,10 +73,9 @@ void *memcpy(void *dest, const void *src, size_t len)
 int file_exists(const char *filename)
 {
         int    fd;
-       //fd = open(filename, OPENFLAG_READ);
-       fd = open(filename, 0);
+       fd = _SysOpen(filename, 0);
        if(fd == -1)    return 0;
-       close(fd);
+       _SysClose(fd);
        return 1;
 }
 
index af8f007..1dde9ad 100644 (file)
@@ -109,16 +109,16 @@ EXPORT FILE *freopen(const char *file, const char *mode, FILE *fp)
 \r
        //Open File\r
        if(fp->FD != -1)\r
-               fp->FD = reopen(fp->FD, file, openFlags);\r
+               fp->FD = _SysReopen(fp->FD, file, openFlags);\r
        else\r
-               fp->FD = open(file, openFlags);\r
+               fp->FD = _SysOpen(file, openFlags);\r
        if(fp->FD == -1) {\r
                fp->Flags = 0;\r
                return NULL;\r
        }\r
        \r
        if( (fp->Flags & FILE_FLAG_MODE_MASK) == FILE_FLAG_MODE_APPEND ) {\r
-               seek(fp->FD, 0, SEEK_END);      //SEEK_END\r
+               _SysSeek(fp->FD, 0, SEEK_END);  //SEEK_END\r
        }\r
        \r
        return fp;\r
@@ -168,7 +168,7 @@ EXPORT int fclose(FILE *fp)
 {\r
        fflush(fp);\r
        if( fp->FD != -1 ) {\r
-               close(fp->FD);\r
+               _SysClose(fp->FD);\r
        }\r
        fp->Flags = 0;\r
        fp->FD = -1;\r
@@ -221,7 +221,7 @@ EXPORT off_t ftell(FILE *fp)
        if( fp->FD == -2 )\r
                return fp->Pos; \r
        else\r
-               return tell(fp->FD);\r
+               return _SysTell(fp->FD);\r
 }\r
 \r
 EXPORT int fseek(FILE *fp, long int amt, int whence)\r
@@ -251,7 +251,7 @@ EXPORT int fseek(FILE *fp, long int amt, int whence)
                return 0;\r
        }\r
        else\r
-               return seek(fp->FD, amt, whence);\r
+               return _SysSeek(fp->FD, amt, whence);\r
 }\r
 \r
 \r
@@ -318,7 +318,7 @@ EXPORT size_t fwrite(void *ptr, size_t size, size_t num, FILE *fp)
                ret = num;\r
        }\r
        else {  \r
-               ret = write(fp->FD, ptr, size*num);\r
+               ret = _SysWrite(fp->FD, ptr, size*num);\r
                ret /= size;\r
        }\r
        \r
@@ -347,7 +347,7 @@ EXPORT size_t fread(void *ptr, size_t size, size_t num, FILE *fp)
                ret = num;\r
        }\r
        else {\r
-               ret = read(fp->FD, ptr, size*num);\r
+               ret = _SysRead(fp->FD, ptr, size*num);\r
                ret /= size;\r
        }\r
                \r
@@ -366,7 +366,7 @@ EXPORT int fputc(int c, FILE *fp)
 EXPORT int putchar(int c)\r
 {\r
        c &= 0xFF;\r
-       return write(_stdout, &c, 1);\r
+       return _SysWrite(_stdout, &c, 1);\r
 }\r
 \r
 /**\r
@@ -384,7 +384,7 @@ EXPORT int fgetc(FILE *fp)
 EXPORT int getchar(void)\r
 {\r
        char    ret = 0;\r
-       if(read(_stdin, &ret, 1) != 1)  return -1;\r
+       if(_SysRead(_stdin, &ret, 1) != 1)      return -1;\r
        return ret;\r
 }\r
 \r
@@ -415,8 +415,8 @@ EXPORT int puts(const char *str)
        if(!str)        return 0;\r
        len = strlen(str);\r
        \r
-       len = write(_stdout, str, len);\r
-       write(_stdout, "\n", 1);\r
+       len = _SysWrite(_stdout, str, len);\r
+       _SysWrite(_stdout, "\n", 1);\r
        return len;\r
 }\r
 \r
@@ -681,7 +681,7 @@ EXPORT int printf(const char *format, ...)
        va_end(args);\r
        \r
        // Send to stdout\r
-       write(_stdout, buf, size+1);\r
+       _SysWrite(_stdout, buf, size+1);\r
        \r
        // Free buffer\r
        free(buf);\r
index 2adaf1b..2b3ff76 100644 (file)
@@ -47,7 +47,7 @@ char *Net_GetInterface(int AddressType, void *Address)
                uint32_t        *type = (void*)buf;
                
                // Open
-               fd = open("/Devices/ip/routes", 0);
+               fd = _SysOpen("/Devices/ip/routes", 0);
                if( !fd ) {
                        fprintf(stderr, "ERROR: Unable to open '/Devices/ip/routes'\n");
                        return NULL;
@@ -56,10 +56,10 @@ char *Net_GetInterface(int AddressType, void *Address)
                // Make structure and ask
                *type = AddressType;
                memcpy(type+1, Address, size);
-               routeNum = ioctl(fd, ioctl(fd, 3, "locate_route"), buf);
+               routeNum = _SysIOCtl(fd, _SysIOCtl(fd, 3, "locate_route"), buf);
                
                // Close
-               close(fd);
+               _SysClose(fd);
        }
        
        // Check answer validity
@@ -71,24 +71,24 @@ char *Net_GetInterface(int AddressType, void *Address)
                sprintf(buf, "/Devices/ip/routes/#%i", routeNum);
                
                // Open route
-               fd = open(buf, 0);
+               fd = _SysOpen(buf, 0);
                if( fd == -1 ) {
                        fprintf(stderr, "Net_GetInterface - ERROR: Unable to open %s\n", buf);
                        return NULL;    // Shouldn't happen :/
                }
                
                // Allocate space for name
-               ret = malloc( ioctl(fd, ioctl(fd, 3, "get_interface"), NULL) + 1 );
+               ret = malloc( _SysIOCtl(fd, _SysIOCtl(fd, 3, "get_interface"), NULL) + 1 );
                if( !ret ) {
                        fprintf(stderr, "malloc() failure - Allocating space for interface name\n");
                        return NULL;
                }
                
                // Get name
-               ioctl(fd, ioctl(fd, 3, "get_interface"), ret);
+               _SysIOCtl(fd, _SysIOCtl(fd, 3, "get_interface"), ret);
                
                // Close and return
-               close(fd);
+               _SysClose(fd);
                
                return ret;
        }
index 0b54079..f5933f2 100644 (file)
@@ -26,14 +26,14 @@ int Net_OpenSocket(int AddrType, void *Addr, const char *Filename)
                char    path[len+1];
                snprintf(path, 100, "/Devices/ip/routes/@%i:%s/%s", AddrType, hexAddr, Filename);
                _SysDebug("%s", path);
-               return open(path, OPENFLAG_READ|OPENFLAG_WRITE);
+               return _SysOpen(path, OPENFLAG_READ|OPENFLAG_WRITE);
        }
        else
        {
                 int    len = snprintf(NULL, 100, "/Devices/ip/routes/@%i:%s", AddrType, hexAddr);
                char    path[len+1];
                snprintf(path, 100, "/Devices/ip/routes/@%i:%s", AddrType, hexAddr);
-               return open(path, OPENFLAG_READ);
+               return _SysOpen(path, OPENFLAG_READ);
        }
 }
 
@@ -42,9 +42,9 @@ int Net_OpenSocket_TCPC(int AddrType, void *Addr, int Port)
        int fd = Net_OpenSocket(AddrType, Addr, "tcpc");
        if( fd == -1 )  return -1;
        
-       ioctl(fd, 5, &Port);    // Remote Port
-        ioctl(fd, 6, Addr);    // Remote address
-       ioctl(fd, 7, NULL);     // connect
+       _SysIOCtl(fd, 5, &Port);        // Remote Port
+        _SysIOCtl(fd, 6, Addr);        // Remote address
+       _SysIOCtl(fd, 7, NULL); // connect
        return fd;
 }
 
diff --git a/Usermode/Libraries/libposix.so_src/Makefile b/Usermode/Libraries/libposix.so_src/Makefile
new file mode 100644 (file)
index 0000000..2f472fc
--- /dev/null
@@ -0,0 +1,16 @@
+# Acess2 POSIX Emulation\r
+# Makefile\r
+\r
+-include ../Makefile.cfg\r
+\r
+CPPFLAGS += \r
+CFLAGS   += -Werror -Wextra\r
+ASFLAGS  +=\r
+LDFLAGS  += -soname libposix.so -Map map.txt\r
+\r
+OBJ  = main.o unistd.o\r
+DEPFILES := $(OBJ:%.o=%.d)\r
+BIN = libposix.so\r
+\r
+include ../Makefile.tpl\r
+\r
diff --git a/Usermode/Libraries/libposix.so_src/include_exp/sys/select.h b/Usermode/Libraries/libposix.so_src/include_exp/sys/select.h
new file mode 100644 (file)
index 0000000..c33ccb1
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * Acess2 POSIX Emulation Layer
+ * - By John Hodge
+ * 
+ * sys/select.h
+ * - select(2)
+ */
+#ifndef _SYS__SELECT_H_
+#define _SYS__SELECT_H_
+
+#include <acess/fd_set.h>
+
+extern int select(int nfds, fd_set *readfds, fd_set *writefds, struct timeval *timeout);
+// TODO: pselect?
+
+#endif
+
diff --git a/Usermode/Libraries/libposix.so_src/include_exp/sys/stat.h b/Usermode/Libraries/libposix.so_src/include_exp/sys/stat.h
new file mode 100644 (file)
index 0000000..99c526b
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Acess2 C Library
+ * - By John Hodge (thePowersGang)
+ */
+#ifndef _SYS_STAT_H_
+#define _SYS_STAT_H_
+
+//#include "../acess/intdefs.h"        /* Evil */
+//#include "../stddef.h"
+#include <stdint.h>
+#include "sys/types.h" // off_t
+
+typedef void   *dev_t; /* TODO: How to identify a device with Acess */
+typedef uint64_t       ino_t;
+typedef unsigned int   blksize_t;
+typedef uint64_t       blkcnt_t;
+typedef unsigned int   nlink_t;
+typedef uint32_t       mode_t;
+
+typedef uint32_t       uid_t;
+typedef uint32_t       gid_t;
+
+#define        S_IFMT          0170000 /* type of file */
+#define                S_IFDIR 0040000 /* directory */
+#define                S_IFCHR 0020000 /* character special */
+#define                S_IFBLK 0060000 /* block special */
+#define                S_IFREG 0100000 /* regular */
+#define                S_IFLNK 0120000 /* symbolic link */
+#define                S_IFSOCK        0140000 /* socket */
+#define                S_IFIFO 0010000 /* fifo */
+
+
+struct stat
+{
+       dev_t     st_dev;     /* ID of device containing file */
+       ino_t     st_ino;     /* inode number */
+       mode_t    st_mode;    /* protection */
+       nlink_t   st_nlink;   /* number of hard links */
+       uid_t     st_uid;     /* user ID of owner */
+       gid_t     st_gid;     /* group ID of owner */
+       dev_t     st_rdev;    /* device ID (if special file) */
+       off_t     st_size;    /* total size, in bytes */
+       blksize_t st_blksize; /* blocksize for file system I/O */
+       blkcnt_t  st_blocks;  /* number of 512B blocks allocated */
+       time_t    st_atime;   /* time of last access */
+       time_t    st_mtime;   /* time of last modification */
+       time_t    st_ctime;   /* time of last status change */
+};
+
+extern int stat(const char *path, struct stat *buf);
+extern int fstat(int fd, struct stat *buf);
+
+#endif
diff --git a/Usermode/Libraries/libposix.so_src/include_exp/sys/types.h b/Usermode/Libraries/libposix.so_src/include_exp/sys/types.h
new file mode 100644 (file)
index 0000000..db78b5a
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ */
+#ifndef _SYS_TYPES_H
+#define _SYS_TYPES_H
+
+#include <stdint.h>
+
+//typedef signed int   ssize_t;
+//#ifdef  __USE_BSD
+typedef unsigned int   u_int;
+//#endif
+
+typedef struct stat    t_fstat;
+
+
+#define CLONE_VM       0x10
+
+typedef unsigned int   id_t;
+typedef unsigned long  pid_t;
+typedef unsigned long  tid_t;
+typedef signed long long int   time_t;
+typedef long long int  off_t;
+
+typedef unsigned int   uint;
+
+#include "stat.h"
+#include <acess/fd_set.h>
+
+#endif
diff --git a/Usermode/Libraries/libposix.so_src/include_exp/unistd.h b/Usermode/Libraries/libposix.so_src/include_exp/unistd.h
new file mode 100644 (file)
index 0000000..a2f397c
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Acess2 POSIX Emulation Layer
+ * - By John Hodge
+ * 
+ * unistd.h
+ * - 
+ */
+#ifndef _UNISTD_H_
+#define _UNISTD_H_
+
+#include <stddef.h>
+
+//! \brief flags for open(2)
+#define O_WRONLY       0x01
+#define O_RDONLY       0x02
+#define        O_RDWR          0x03
+#define O_APPEND       0x04
+#define O_CREAT        0x08
+#define O_DIRECTORY    0x10
+#define O_ASYNC        0x20
+#define O_TRUNC        0x40
+#define O_NOFOLLOW     0x80    // don't follow symlinks
+#define        O_EXCL          0x100
+#define O_NOCTTY       0       // unsupported
+#define O_NONBLOCK     0x200
+#define        O_SYNC  0       // not supported
+
+#define STDIN_FILENO   0
+#define STDOUT_FILENO  1
+#define STDERR_FILENO  2
+
+typedef signed long    ssize_t;
+
+#include "sys/stat.h"  // mode_t
+
+extern int     open(const char *path, int flags, ...);
+extern int     creat(const char *path, mode_t mode);
+extern int     close(int fd);
+
+extern ssize_t write(int fd, const void *buf, size_t count);
+extern ssize_t read(int fd, void *buf, size_t count);
+
+extern int     fork(void);
+extern int     execv(const char *b, char *v[]);
+
+#endif
+
diff --git a/Usermode/Libraries/libposix.so_src/main.c b/Usermode/Libraries/libposix.so_src/main.c
new file mode 100644 (file)
index 0000000..72989a5
--- /dev/null
@@ -0,0 +1,14 @@
+/*
+ * Acess2 POSIX Emulation Layer
+ * - By John Hodge
+ * 
+ * main.c
+ * - Stub Main
+ */
+
+// === CODE ===
+int SoMain(void)
+{
+       return 0;
+}
+
diff --git a/Usermode/Libraries/libposix.so_src/unistd.c b/Usermode/Libraries/libposix.so_src/unistd.c
new file mode 100644 (file)
index 0000000..1a5b7be
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Acess2 POSIX Emulation Layer
+ * - By John Hodge
+ * 
+ * unistd.c
+ * - POSIX->Acess VFS call translation
+ */
+#include <unistd.h>
+#include <acess/sys.h>
+#include <stdarg.h>
+
+// === CODE ===
+int open(const char *path, int openmode, ...)
+{
+       mode_t  create_mode = 0;
+       int openflags = 0;
+       
+       switch( openmode & O_RDWR )
+       {
+       case 0: // Special
+               break;
+       case O_RDONLY:  openflags |= OPENFLAG_READ;     break;
+       case O_WRONLY:  openflags |= OPENFLAG_WRITE;    break;
+       case O_RDWR:    openflags |= OPENFLAG_READ|OPENFLAG_WRITE;      break;
+       }
+       
+       if( openmode & O_CREAT ) {
+               openflags |= OPENFLAG_CREATE;
+               va_list args;
+               va_start(args, openmode);
+               create_mode = va_arg(args, mode_t);
+               va_end(args);
+       }
+       
+       return _SysOpen(path, openflags, create_mode);
+}
+
+int creat(const char *path, mode_t mode)
+{
+       // TODO: Make native call to do this cheaper
+       int fd = _SysOpen(path, OPENFLAG_CREATE, mode);
+       if( fd == -1 )  return -1;
+       _SysClose(fd);
+       return 0;
+}
+
+int close(int fd)
+{
+       _SysClose(fd);
+       return 0;
+}
+
+ssize_t        write(int fd, const void *buf, size_t count)
+{
+       return _SysWrite(fd, buf, count);
+}
+
+ssize_t        read(int fd, void *buf, size_t count)
+{
+       return _SysRead(fd, buf, count);
+}
+
+int fork(void)
+{
+       return clone(CLONE_VM, 0);
+}
+
+int execv(const char *b, char *v[])
+{
+       return execve(b, v, NULL);
+}
diff --git a/Usermode/Libraries/libpsocket.so_src/common.h b/Usermode/Libraries/libpsocket.so_src/common.h
new file mode 100644 (file)
index 0000000..27e88e4
--- /dev/null
@@ -0,0 +1,2 @@
+
+extern char *mkstr(const char *format, ...);
index 99fbe2a..9c1e5a1 100644 (file)
@@ -8,6 +8,7 @@
 #include <stdlib.h>
 #include <stdarg.h>
 #include <stdio.h>
+#include "common.h"
 
 int SoMain(void)
 {
index 913f72f..613e82b 100644 (file)
@@ -6,10 +6,11 @@
  * - sys/socket.h calls
  */
 #include <sys/socket.h>
-#include <unistd.h>
+#include <acess/sys.h>
 #include <stdlib.h>    // malloc/free
 #include <string.h>
 #include <netinet/in.h>
+#include "common.h"
 
 #define MAXFD  32
 
@@ -55,7 +56,7 @@ int socket(int domain, int type, int protocol)
        si = _GetInfo(0);
        if( !si )       return -1;
 
-       int fd = open("/Devices/null", O_RDWR);
+       int fd = _SysOpen("/Devices/null", OPENFLAG_RDWR);
        if( fd == -1 )  return -1;
 
        giNumPreinit ++;
@@ -167,7 +168,7 @@ void _CommitServer(int sockfd)
        else
                path = mkstr("/Devices/ip/*%i/%s", si->local->sa_family, file);
 
-       reopen(si->fd, path, O_RDWR);
+       _SysReopen(si->fd, path, OPENFLAG_RDWR);
        // TODO: Error-check
        
        free(path);
@@ -191,10 +192,11 @@ int accept(int sockfd, struct sockaddr *clientaddr, socklen_t addrlen)
         int    child;
 
 
-       child = _SysOpenChild(sockfd, "", O_RDWR);
+       child = _SysOpenChild(sockfd, "", OPENFLAG_RDWR);
        if( child == -1 )       return -1;
        
-       ioctl(child, 8, clientaddr);
+       _SysIOCtl(child, 8, clientaddr);
+
        
        return child;
 }
@@ -203,25 +205,25 @@ int recvfrom(int sockfd, void *buffer, size_t length, int flags, struct sockaddr
 {
        _CommitClient(sockfd);
        // TODO: Determine socket type (TCP/UDP) and use a bounce-buffer for UDP
-       return read(sockfd, buffer, length);
+       return _SysRead(sockfd, buffer, length);
 }
 
 int recv(int sockfd, void *buffer, size_t length, int flags)
 {
        _CommitClient(sockfd);
-       return read(sockfd, buffer, length);
+       return _SysRead(sockfd, buffer, length);
 }
 
 int sendto(int sockfd, const void *buffer, size_t length, int flags, const struct sockaddr *clientaddr, socklen_t addrlen)
 {
        _CommitClient(sockfd);
        // TODO: Determine socket type (TCP/UDP) and use a bounce-buffer for UDP
-       return write(sockfd, buffer, length);
+       return _SysWrite(sockfd, buffer, length);
 }
 
 int send(int sockfd, void *buffer, size_t length, int flags)
 {
        _CommitClient(sockfd);
-       return write(sockfd, buffer, length);
+       return _SysWrite(sockfd, buffer, length);
 }
 
index 719667d..58db03a 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, Info->ReadBuffer, READ_BUFFER_SIZE - 1 - Info->ReadBufferLen);
+       len = _SysRead(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, "\x1B[D", 3);
+                                       while(pos--)    _SysWrite(STDOUT_FD, "\x1B[D", 3);
                                        
                                        // Update state
                                        Info->CurBuffer = Info->History[--Info->HistoryPos];
                                        Info->BufferSize = Info->BufferUsed = strlen(Info->CurBuffer);
                                        
-                                       write(STDOUT_FD, Info->CurBuffer, Info->BufferUsed);
+                                       _SysWrite(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--)    _SysWrite(STDOUT_FD, " ", 1);
                                                pos = oldLen - Info->BufferWritePos;
-                                               while(pos--)    write(STDOUT_FD, "\x1B[D", 3);
+                                               while(pos--)    _SysWrite(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, "\x1B[D", 3);
+                                       while(pos--)    _SysWrite(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->CurBuffer, Info->BufferUsed);
+                                       _SysWrite(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--)    _SysWrite(STDOUT_FD, " ", 1);
                                                pos = oldLen - Info->BufferWritePos;
-                                               while(pos--)    write(STDOUT_FD, "\x1B[D", 3);
+                                               while(pos--)    _SysWrite(STDOUT_FD, "\x1B[D", 3);
                                        }
                                }
                                break;
                        case 'D':       // Left
                                if(Info->BufferWritePos == 0)   break;
                                Info->BufferWritePos --;
-                               write(STDOUT_FD, "\x1B[D", 3);
+                               _SysWrite(STDOUT_FD, "\x1B[D", 3);
                                break;
                        case 'C':       // Right
                                if(Info->BufferWritePos == Info->BufferUsed)    break;
                                Info->BufferWritePos ++;
-                               write(STDOUT_FD, "\x1B[C", 3);
+                               _SysWrite(STDOUT_FD, "\x1B[C", 3);
                                break;
                        }
                        break;
@@ -271,7 +271,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, &ch, 1);
+               _SysWrite(STDOUT_FD, &ch, 1);
                if(Info->BufferWritePos == Info->BufferUsed)    // Simple case: End of string
                {
                        Info->BufferUsed --;
@@ -286,12 +286,12 @@ int Readline_int_ParseCharacter(tReadline *Info, char *Input)
                        buf[3] += (delta/10) % 10;
                        buf[4] += (delta) % 10;
                        // Write everything save for the deleted character
-                       write(STDOUT_FD,
+                       _SysWrite(STDOUT_FD,
                                &Info->CurBuffer[Info->BufferWritePos],
                                Info->BufferUsed - Info->BufferWritePos
                                );
-                       ch = ' ';       write(STDOUT_FD, &ch, 1);       ch = '\b';      // Clear old last character
-                       write(STDOUT_FD, buf, 7);       // Update Cursor
+                       ch = ' ';       _SysWrite(STDOUT_FD, &ch, 1);   ch = '\b';      // Clear old last character
+                       _SysWrite(STDOUT_FD, buf, 7);   // Update Cursor
                        // Alter Buffer
                        memmove(&Info->CurBuffer[Info->BufferWritePos-1],
                                &Info->CurBuffer[Info->BufferWritePos],
@@ -325,12 +325,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, &ch, 1);       // Print new character
-                       write(STDOUT_FD,
+                       _SysWrite(STDOUT_FD, &ch, 1);   // Print new character
+                       _SysWrite(STDOUT_FD,
                                &Info->CurBuffer[Info->BufferWritePos],
                                Info->BufferUsed - Info->BufferWritePos
                                );
-                       write(STDOUT_FD, buf, 7);       // Update Cursor
+                       _SysWrite(STDOUT_FD, buf, 7);   // Update Cursor
                        // Move buffer right
                        memmove(
                                &Info->CurBuffer[Info->BufferWritePos+1],
@@ -340,7 +340,7 @@ int Readline_int_ParseCharacter(tReadline *Info, char *Input)
                }
                // Simple append
                else {
-                       write(STDOUT_FD, &ch, 1);
+                       _SysWrite(STDOUT_FD, &ch, 1);
                }
                Info->CurBuffer[ Info->BufferWritePos ++ ] = ch;
                Info->BufferUsed ++;
index bf88b98..e8f8dea 100644 (file)
@@ -32,7 +32,7 @@ void  URI_Close(tURIFile *File);
 size_t URI_file_Read(int Handle, size_t Bytes, void *Buffer);
 size_t URI_file_Write(int Handle, size_t Bytes, void *Buffer);
 void   URI_file_Close(int Handle);
-size_t URI_file_GetSize(int Handle);
+off_t  URI_file_GetSize(int Handle);
 
 // === CONSTANTS ===
 // Builtin URI protocol handlers
@@ -319,7 +319,7 @@ int URI_file_Open(char *Host, int Port, char *Path, int Mode)
 //     printf("URI_file_Open: open('%s', 0x%x)\n", Path, smode);
        {
                 int    ret;
-               ret = open(Path, smode);
+               ret = _SysOpen(Path, smode);
                return ret;
        }
 }
@@ -327,22 +327,22 @@ size_t URI_file_Read(int Handle, size_t Bytes, void *Buffer)
 {
 //     printf("URI_file_Read: (Handle=%i, Buffer=%p, Bytes=%i)\n",
 //             Handle, Buffer, (int)Bytes);
-       return read(Handle, Buffer, Bytes);
+       return _SysRead(Handle, Buffer, Bytes);
 }
 size_t URI_file_Write(int Handle, size_t Bytes, void *Buffer)
 {
-       return write(Handle, Buffer, Bytes);
+       return _SysWrite(Handle, Buffer, Bytes);
 }
 void URI_file_Close(int Handle)
 {
-       close(Handle);
+       _SysClose(Handle);
 }
-size_t URI_file_GetSize(int Handle)
+off_t URI_file_GetSize(int Handle)
 {
-       uint64_t curpos = tell(Handle);
-       size_t ret;
-       seek(Handle, 0, SEEK_END);
-       ret = tell(Handle);
-       seek(Handle, curpos, SEEK_SET);
+       uint64_t curpos = _SysTell(Handle);
+       off_t ret;
+       _SysSeek(Handle, 0, SEEK_END);
+       ret = _SysTell(Handle);
+       _SysSeek(Handle, curpos, SEEK_SET);
        return ret;
 }

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