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"
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
{\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
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
*/\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
\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
strcpy(gsCurrentDirectory, tmpPath);\r
\r
// Register change with kernel\r
- chdir( gsCurrentDirectory );\r
+ _SysChdir( gsCurrentDirectory );\r
}\r
\r
/**\r
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
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
\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
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
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
printf("\n");\r
}\r
// Close Directory\r
- close(dp);\r
+ _SysClose(dp);\r
}\r
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!
@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/
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;
}
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
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)");
{
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
}
}
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;
}
size_t len;
- pid_t tid;
+ int tid;
while( (len = SysGetMessage(&tid, 0, NULL)) )
{
char data[len];
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)
// 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);
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");
// 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 );
}
_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;
} 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)
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;
giVideo_LastDirtyLine = DstY + H;
buf = gpScreenBuffer + DstY*giScreenWidth + DstX;
- if(drawW != giScreenWidth)
+ if(drawW != giScreenWidth || W != giScreenWidth)
{
while( H -- )
{
}
else
{
+ // Only valid if copying full scanlines on both ends
memcpy(buf, Source, giScreenWidth*H*4);
}
}
#include <wm_internals.h>
#include <stdlib.h>
#include <utf8.h>
+#include <limits.h> // INT_MAX
// === TYPES ===
typedef struct sGlyph tGlyph;
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;
{
int len;
tAxWin_IPCMessage *ret = NULL;
- pid_t tid;
+ int tid;
_SysSelect(nFD, fds, NULL, NULL, NULL, THREAD_EVENT_IPCMSG);
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");
/*
* Acess2 CAT command
*/
-#include <acess/sys.h>
#include <stdlib.h>
#include <stdio.h>
*/
int main(int argc, char *argv[])
{
- int fd;
int num;
char buf[BUF_SIZE];
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;
#include <string.h>
#include <stdlib.h>
#include <net.h>
+#include <acess/sys.h>
#define FILENAME_MAX 255
// --- Translation functions ---
{
if( Handle_Packet( i ) )
{
- close(i->SocketFD);
- close(i->IfaceFD);
+ _SysClose(i->SocketFD);
+ _SysClose(i->IfaceFD);
p->Next = i->Next;
free(i);
i = p;
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 ;
new->Next = *IfaceList;
*IfaceList = new;
}
- close(dp);
+ _SysClose(dp);
}
// RETURN: Client FD
{
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;
}
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);
}
((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);
}
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 = {");
);
}
- ioctl(Iface->IfaceFD, 6, Addr);
- ioctl(Iface->IfaceFD, 7, &mask_bits);
+ _SysIOCtl(Iface->IfaceFD, 6, Addr);
+ _SysIOCtl(Iface->IfaceFD, 7, &mask_bits);
if( 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);
}
}
}
#include <axwin3/menu.h>
#include <axwin3/richtext.h>
#include <stdio.h>
+#include "strings.h"
// === PROTOTYPES ===
int main(int argc, char *argv[]);
int len = read(giChildStdout, buf, sizeof(buf));
if( len <= 0 ) break;
- //Term_HandleOutput(len, buf);
+ Term_HandleOutput(len, buf);
}
}
{
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;
}
{
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);
// 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 );
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);
}
/**
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 ) {
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);
}
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;
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]),
break;
}
- close(fd);
+ _SysClose(fd);
}
// === 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 ===
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 ;
}
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)
// 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)
// 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
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 )
\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
{\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
// 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
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
\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
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
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;
}
}
// 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;
}
space += 16;
gFileList = realloc(gFileList, space*sizeof(char*));
if(gFileList == NULL) {
- close(fd);
+ _SysClose(fd);
return EXIT_FAILURE;
}
}
DisplayFile( gFileList[i] );
}
- close(fd);
+ _SysClose(fd);
printf("\n");
return EXIT_SUCCESS;
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;
if(acl.perms & 8) perms |= 0001; // X
// Close file
- close(fd);
+ _SysClose(fd);
}
free(path); // We're finished with it
*/
#include <stdlib.h>
#include <stdio.h>
-#include <unistd.h>
#include <acess/sys.h>
#define PCI_BASE "/Devices/pci"
// === 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;
}
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;
printf("\n");
}
- close(fd);
+ _SysClose(fd);
}
}
// 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 = "";
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;
}
}
- 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;
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;
}
// 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
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
}\r
}\r
\r
- close(server_fd);\r
+ _SysClose(server_fd);\r
return 0;\r
}\r
\r
}\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
/*
+ * 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
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
}
// Select!
- select( maxfd+1, &fds, NULL, NULL, NULL );
+ _SysSelect( maxfd+1, &fds, NULL, NULL, NULL, 0 );
// Check events
if( FD_ISSET(giServerFD, &fds) )
if( giNumClients == giConfig_MaxClients )
{
// Open, reject
- close( _SysOpenChild(FD, "", O_RDWR) );
+ _SysClose( _SysOpenChild(FD, "", OPENFLAG_READ) );
return ;
}
}
}
// 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
{
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)
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);
}
#include <string.h>
#include <unistd.h>
#include <netdb.h>
+#include <acess/sys.h> // _SysDebug
enum eProcols
{
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);
}
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)
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)
#include <stddef.h>
#include <stdarg.h>
#include <stdint.h>
+#include <acess/sys.h>
typedef uintptr_t Uint;
typedef uint8_t Uint8;
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);
--- /dev/null
+/*
+ * 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
#define _ACESS_SYS_H_
#include <stdint.h>
-#include "../sys/types.h"
+#include <stddef.h> // size_t
+#include "syscall_types.h"
// === CONSTANTS ===
#ifndef NULL
#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
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);
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
* 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 */
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));
+++ /dev/null
-/*
- * 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
+++ /dev/null
-/*
- */
-#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
+++ /dev/null
-#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
-
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;
}
\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
{\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
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
return 0;\r
}\r
else\r
- return seek(fp->FD, amt, whence);\r
+ return _SysSeek(fp->FD, amt, whence);\r
}\r
\r
\r
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
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
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
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
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
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
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;
// 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
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;
}
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);
}
}
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;
}
--- /dev/null
+# 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
--- /dev/null
+/*
+ * 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
+
--- /dev/null
+/*
+ * 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
--- /dev/null
+/*
+ */
+#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
--- /dev/null
+/*
+ * 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
+
--- /dev/null
+/*
+ * Acess2 POSIX Emulation Layer
+ * - By John Hodge
+ *
+ * main.c
+ * - Stub Main
+ */
+
+// === CODE ===
+int SoMain(void)
+{
+ return 0;
+}
+
--- /dev/null
+/*
+ * 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);
+}
--- /dev/null
+
+extern char *mkstr(const char *format, ...);
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
+#include "common.h"
int SoMain(void)
{
* - 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
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 ++;
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);
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;
}
{
_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);
}
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';
// 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;
// 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;
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 --;
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],
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],
}
// Simple append
else {
- write(STDOUT_FD, &ch, 1);
+ _SysWrite(STDOUT_FD, &ch, 1);
}
Info->CurBuffer[ Info->BufferWritePos ++ ] = ch;
Info->BufferUsed ++;
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
// printf("URI_file_Open: open('%s', 0x%x)\n", Path, smode);
{
int ret;
- ret = open(Path, smode);
+ ret = _SysOpen(Path, smode);
return ret;
}
}
{
// 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;
}