}\r
} \r
\r
- write(_stdout, 22, "Acess Shell Version 3\n");\r
- write(_stdout, 2, "\n");\r
+ printf("Acess Shell Version 3\n\n");\r
for(;;)\r
{\r
// Free last command & arguments\r
bCached = 0;\r
#endif\r
\r
- write(_stdout, strlen(gsCurrentDirectory), gsCurrentDirectory);\r
- write(_stdout, 2, "$ ");\r
+ printf("%s$ ", gsCurrentDirectory);\r
\r
// Read Command line\r
#if USE_READLINE\r
sCommandStr = ReadCommandLine( &length );\r
\r
if(!sCommandStr) {\r
- write(_stdout, 25, "PANIC: Out of heap space\n");\r
+ printf("PANIC: Out of heap space\n");\r
return -1;\r
}\r
\r
}\r
}\r
\r
+#if USE_READLINE\r
/**\r
* \fn char *ReadCommandLine(int *Length)\r
* \brief Read from the command line\r
\r
// Read In Command Line\r
do {\r
- read(_stdin, 1, &ch); // Read Character from stdin (read is a blocking call)\r
- \r
+ ch = getchar(); // Read Character from stdin (read is a blocking call)\r
if(ch == '\n') break;\r
\r
switch(ch)\r
{\r
// Control characters\r
case '\x1B':\r
- read(_stdin, 1, &ch); // Read control character\r
+ ch = getchar(); // Read control character\r
switch(ch)\r
{\r
//case 'D': if(pos) pos--; break;\r
//case 'C': if(pos<len) pos++; break;\r
case '[':\r
- read(_stdin, 1, &ch); // Read control character\r
+ ch = getchar(); // Read control character\r
switch(ch)\r
{\r
#if 0\r
ret = strdup( gasCommandHistory[--scrollbackPos] );\r
\r
len = strlen(ret);\r
- while(pos--) write(_stdout, 3, "\x1B[D");\r
+ while(pos--) printf("\x1B[D");\r
write(_stdout, len, ret); pos = len;\r
while(pos++ < oldLen) write(_stdout, 1, " ");\r
}\r
case 'D': // Left\r
if(pos == 0) break;\r
pos --;\r
- write(_stdout, 3, "\x1B[D");\r
+ printf("\x1B[D");\r
break;\r
case 'C': // Right\r
if(pos == len) break;\r
pos++;\r
- write(_stdout, 3, "\x1B[C");\r
+ printf("\x1B[C");\r
break;\r
}\r
}\r
// Backspace\r
case '\b':\r
if(len <= 0) break; // Protect against underflows\r
- write(_stdout, 1, &ch);\r
+ putchar(ch);\r
if(pos == len) { // Simple case of end of string\r
len --;\r
pos--;\r
}\r
else {\r
- char buf[7] = "\x1B[000D";\r
- buf[2] += ((len-pos+1)/100) % 10;\r
- buf[3] += ((len-pos+1)/10) % 10;\r
- buf[4] += (len-pos+1) % 10;\r
- write(_stdout, len-pos, &ret[pos]); // Move Text\r
- ch = ' '; write(_stdout, 1, &ch); ch = '\b'; // Clear deleted character\r
- write(_stdout, 7, buf); // Update Cursor\r
+ printf("%.*s ", len-pos, &ret[pos]); // Move Text\r
+ printf("\x1B[%iD", len-pos+1);\r
// Alter Buffer\r
memmove(&ret[pos-1], &ret[pos], len-pos);\r
pos --;\r
\r
// Editing inside the buffer\r
if(pos != len) {\r
- char buf[7] = "\x1B[000D";\r
- buf[2] += ((len-pos)/100) % 10;\r
- buf[3] += ((len-pos)/10) % 10;\r
- buf[4] += (len-pos) % 10;\r
- write(_stdout, 1, &ch); // Print new character\r
- write(_stdout, len-pos, &ret[pos]); // Move Text\r
- write(_stdout, 7, buf); // Update Cursor\r
+ putchar(ch); // Print new character\r
+ printf("%.*s", len-pos, &ret[pos]); // Move Text\r
+ printf("\x1B[%iD", len-pos);\r
memmove( &ret[pos+1], &ret[pos], len-pos );\r
}\r
else {\r
- write(_stdout, 1, &ch);\r
+ putchar(ch);\r
}\r
ret[pos++] = ch;\r
len ++;\r
\r
return ret;\r
}\r
+#endif\r
\r
/**\r
* \fn void Parse_Args(char *str, char **dest)\r
\r
if(buf == NULL) {\r
dest[0] = NULL;\r
- Print("Parse_Args: Out of heap space!\n");\r
+ printf("Parse_Args: Out of heap space!\n");\r
return ;\r
}\r
\r
// Check file existence\r
fd = open(sTmpBuffer, OPENFLAG_EXEC);\r
if(fd == -1) {\r
- Print("Unknown Command: `");Print(Args[0]);Print("'\n"); // Error Message\r
+ printf("Unknown Command: `%s'\n", Args[0]); // Error Message\r
return ;\r
}\r
\r
\r
// Check if the file is a directory\r
if(info.flags & FILEFLAG_DIRECTORY) {\r
- Print("`");Print(sTmpBuffer); // Error Message\r
- Print("' is a directory.\n");\r
+ printf("`%s' is a directory.\n", sTmpBuffer);\r
return ;\r
}\r
}\r
\r
// Exhausted path directories\r
if( i == giNumPathDirs ) {\r
- Print("Unknown Command: `");Print(exefile);Print("'\n");\r
+ printf("Unknown Command: `%s'\n", exefile);\r
return ;\r
}\r
}\r
if(pid == 0)\r
execve(sTmpBuffer, Args, gasEnvironment);\r
if(pid <= 0) {\r
- Print("Unablt to create process: `");Print(sTmpBuffer);Print("'\n"); // Error Message\r
+ printf("Unable to create process: `%s'\n", sTmpBuffer); // Error Message\r
}\r
else {\r
int status;\r
*/\r
void Command_Help(int argc, char **argv)\r
{\r
- Print("Acess 2 Command Line Interface\n");\r
- Print(" By John Hodge (thePowersGang / [TPG])\n");\r
- Print("\n");\r
- Print("Builtin Commands:\n");\r
- Print(" logout: Return to the login prompt\n");\r
- Print(" exit: Same\n");\r
- Print(" help: Display this message\n");\r
- Print(" clear: Clear the screen\n");\r
- Print(" cd: Change the current directory\n");\r
- Print(" dir: Print the contents of the current directory\n");\r
- //Print("\n");\r
+ printf( "Acess 2 Command Line Interface\n"\r
+ " By John Hodge (thePowersGang / [TPG])\n"\r
+ "\n"\r
+ "Builtin Commands:\n"\r
+ " logout: Return to the login prompt\n"\r
+ " exit: Same\n"\r
+ " help: Display this message\n"\r
+ " clear: Clear the screen\n"\r
+ " cd: Change the current directory\n"\r
+ " dir: Print the contents of the current directory\n");\r
return;\r
}\r
\r
*/\r
void Command_Clear(int argc, char **argv)\r
{\r
- write(_stdout, 4, "\x1B[2J"); //Clear Screen\r
+ write(_stdout, "\x1B[2J", 4); //Clear Screen\r
}\r
\r
/**\r
\r
if(argc < 2)\r
{\r
- Print(gsCurrentDirectory);Print("\n");\r
+ printf("%s\n", gsCurrentDirectory);\r
return;\r
}\r
\r
\r
fp = open(tmpPath, 0);\r
if(fp == -1) {\r
- write(_stdout, 26, "Directory does not exist\n");\r
+ printf("Directory does not exist\n");\r
return;\r
}\r
finfo(fp, &stats, 0);\r
close(fp);\r
\r
if( !(stats.flags & FILEFLAG_DIRECTORY) ) {\r
- write(_stdout, 17, "Not a Directory\n");\r
+ printf("Not a Directory\n");\r
return;\r
}\r
\r
if( finfo(dp, &info, 0) == -1 )\r
{\r
close(dp);\r
- write(_stdout, 34, "stat Failed, Bad File Descriptor\n");\r
+ printf("stat Failed, Bad File Descriptor\n");\r
return;\r
}\r
// Check if it's a directory\r
if(!(info.flags & FILEFLAG_DIRECTORY))\r
{\r
close(dp);\r
- write(_stdout, 27, "Unable to open directory `");\r
- write(_stdout, strlen(tmpPath)+1, tmpPath);\r
- write(_stdout, 20, "', Not a directory\n");\r
+ printf("Unable to open directory `%s', Not a directory\n", tmpPath);\r
return;\r
}\r
\r
if(fp < 0)\r
{\r
if(fp == -3)\r
- write(_stdout, 42, "Invalid Permissions to traverse directory\n");\r
+ printf("Invalid Permissions to traverse directory\n");\r
break;\r
}\r
// Open File\r
finfo(fp, &info, 0);\r
\r
if(info.flags & FILEFLAG_DIRECTORY)\r
- write(_stdout, 1, "d");\r
+ printf("d");\r
else\r
- write(_stdout, 1, "-");\r
+ printf("-");\r
\r
// Print Mode\r
// - Owner\r
if(acl.perms & 1) modeStr[6] = 'r'; else modeStr[6] = '-';\r
if(acl.perms & 2) modeStr[7] = 'w'; else modeStr[7] = '-';\r
if(acl.perms & 8) modeStr[8] = 'x'; else modeStr[8] = '-';\r
- write(_stdout, 10, modeStr);\r
+ printf(modeStr);\r
close(fp);\r
\r
// Colour Code\r
if(info.flags & FILEFLAG_DIRECTORY) // Directory: Green\r
- write(_stdout, 6, "\x1B[32m");\r
+ printf("\x1B[32m");\r
// Default: White\r
\r
// Print Name\r
- write(_stdout, strlen(fileName), fileName);\r
+ printf("%s", fileName);\r
\r
// Print slash if applicable\r
if(info.flags & FILEFLAG_DIRECTORY)\r
- write(_stdout, 1, "/");\r
+ printf("/");\r
\r
// Revert Colour\r
- write(_stdout, 6, "\x1B[37m");\r
+ printf("\x1B[37m");\r
\r
// Newline!\r
- write(_stdout, 1, "\n");\r
+ printf("\n");\r
}\r
// Close Directory\r
close(dp);\r
if(FD_ISSET(giTerminalFD, set))
{
uint32_t codepoint;
- if( read(giTerminalFD, sizeof(codepoint), &codepoint) != sizeof(codepoint) )
+ if( read(giTerminalFD, &codepoint, sizeof(codepoint)) != sizeof(codepoint) )
{
// oops, error
}
_SysDebug("Cursor event");
seek(giMouseFD, 0, SEEK_SET);
- if( read(giMouseFD, sizeof(mouseinfo), &mouseinfo) != sizeof(mouseinfo) )
+ if( read(giMouseFD, &mouseinfo, sizeof(mouseinfo)) != sizeof(mouseinfo) )
{
// Not a 3 button mouse, oops
return ;
int readlen, identlen;
char *msg;
- readlen = read(giNetworkFileHandle, sizeof(staticBuf), staticBuf);
+ readlen = read(giNetworkFileHandle, staticBuf, sizeof(staticBuf));
identlen = 4 + Net_GetAddressSize( ((uint16_t*)staticBuf)[1] );
msg = staticBuf + identlen;
memcpy(tmpbuf, Ident, identlen); // Header
memcpy(tmpbuf + identlen, Data, Length); // Data
// TODO: Handle fragmented packets
- write(giNetworkFileHandle, sizeof(tmpbuf), tmpbuf);
+ write(giNetworkFileHandle, tmpbuf, sizeof(tmpbuf));
}
int IPC_Type_Sys_GetSize(void *Ident)
{
//seek(giTerminalFD, 0, SEEK_SET);
seek(giTerminalFD, 0, 1);
- write(giTerminalFD, giScreenWidth*giScreenHeight*4, gpScreenBuffer);
+ write(giTerminalFD, gpScreenBuffer, giScreenWidth*giScreenHeight*4);
}
void Video_FillRect(short X, short Y, short W, short H, uint32_t Color)
}
do {
- num = read(fd, BUF_SIZE, buf);
+ num = read(fd, buf, BUF_SIZE);
buf[num] = '\0';
printf("%s", buf);
} while(num == BUF_SIZE);
break;\r
}\r
}\r
+ else if( strcmp(cmd, "PING") == 0 )\r
+ {\r
+ writef(Server->FD, "PONG %s\n", gsHostname);\r
+ }\r
else if( strcmp(cmd, "NOTICE") == 0 )\r
{\r
char *class, *message;\r
{\r
#endif\r
// Read data\r
- len = read(Server->FD, BUFSIZ - Server->ReadPos, &Server->InBuf[Server->ReadPos]);\r
+ len = read(Server->FD, &Server->InBuf[Server->ReadPos], BUFSIZ - Server->ReadPos);\r
if( len == -1 ) {\r
return -1;\r
}\r
vsnprintf(buf, len+1, Format, args);\r
va_end(args);\r
\r
- return write(FD, len, buf);\r
+ return write(FD, buf, len);\r
}\r
}\r
\r
fp = open(tmpPath, OPENFLAG_READ);\r
if(fp == -1) continue;\r
\r
- read(fp, 2, &vendor); read(fp, 2, &device);\r
+ read(fp, &vendor, 2); read(fp, &device, 2);\r
printf(" Vendor 0x%04x, Device 0x%04x\n", vendor, device);\r
printf(" %s - %s\n", GetVendorName(vendor), GetDeviceName(vendor, device));\r
\r
// Reuse vendor and device\r
seek(fp, 0x8, SEEK_SET);\r
- read(fp, 2, &vendor); read(fp, 2, &device);\r
+ read(fp, &vendor, 2); read(fp, &device, 2);\r
printf(" Revision 0x%04x, Class 0x%04x ()\n", vendor, device);\r
\r
// Read File\r
#if DUMP_BARS\r
seek(fp, 0x10, SEEK_SET);\r
printf("Base Address Registers (BARs):\n");\r
- read(fp, 4, &tmp32); printf(" 0x%08x", tmp32);\r
- read(fp, 4, &tmp32); printf(" 0x%08x", tmp32);\r
- read(fp, 4, &tmp32); printf(" 0x%08x", tmp32);\r
- read(fp, 4, &tmp32); printf(" 0x%08x", tmp32);\r
- read(fp, 4, &tmp32); printf(" 0x%08x", tmp32);\r
- read(fp, 4, &tmp32); printf(" 0x%08x", tmp32);\r
+ read(fp, &tmp32, 4); printf(" 0x%08x", tmp32);\r
+ read(fp, &tmp32, 4); printf(" 0x%08x", tmp32);\r
+ read(fp, &tmp32, 4); printf(" 0x%08x", tmp32);\r
+ read(fp, &tmp32, 4); printf(" 0x%08x", tmp32);\r
+ read(fp, &tmp32, 4); printf(" 0x%08x", tmp32);\r
+ read(fp, &tmp32, 4); printf(" 0x%08x", tmp32);\r
printf("\n");\r
#endif\r
printf("\n");\r
// Read from server, and write to stdout\r
do\r
{\r
- len = read(server_fd, BUFSIZ, buffer);\r
- write(1, len, buffer);\r
+ len = read(server_fd, buffer, BUFSIZ);\r
+ write(1, buffer, len);\r
} while( len == BUFSIZ );\r
}\r
\r
char *line = Readline_NonBlock(readline_info);\r
if( line )\r
{\r
- write(server_fd, strlen(line), line);\r
- write(server_fd, 1, "\n");\r
+ write(server_fd, line, strlen(line));\r
+ write(server_fd, "\n", 1);\r
}\r
}\r
else\r
{\r
do\r
{\r
- len = read(0, BUFSIZ, buffer);\r
- write(server_fd, len, buffer);\r
- write(1, len, buffer);\r
+ len = read(0, buffer, BUFSIZ);\r
+ write(server_fd, buffer, len);\r
+ write(1, buffer, len);\r
} while( len == BUFSIZ );\r
}\r
}\r
extern int SysUnloadBin(void *Base);
extern void SysSetFaultHandler(int (*Hanlder)(int));
extern int open(const char *filename, int flags);
-extern void close(int fd);
+extern int close(int fd);
// === ELF Loader ===
extern int ElfGetSymbol(void *Base, char *name, void **ret);
#include "lib.h"\r
#include "stdio_int.h"\r
\r
+#define WRITE_STR(_fd, _str) write(_fd, _str, sizeof(_str))\r
+\r
#define DEBUG_BUILD 0\r
\r
// === CONSTANTS ===\r
return freopen(file, mode, retFile);\r
}\r
\r
-EXPORT void fclose(FILE *fp)\r
+EXPORT int fclose(FILE *fp)\r
{\r
close(fp->FD);\r
- free(fp);\r
+ fp->Flags = 0;\r
+ fp->FD = -1;\r
+ return 0;\r
}\r
\r
EXPORT void fflush(FILE *fp)\r
int size;\r
char sbuf[1024];\r
char *buf = sbuf;\r
- \r
-\r
\r
if(!fp || !format) return -1;\r
\r
va_copy(tmpList, args);\r
\r
- size = vsnprintf(sbuf, 1024, (char*)format, tmpList);\r
+ size = vsnprintf(sbuf, sizeof(sbuf), (char*)format, tmpList);\r
\r
- if( size >= 1024 )\r
+ if( size >= sizeof(sbuf) )\r
{\r
buf = (char*)malloc(size+1);\r
if(!buf) {\r
- write(_stdout, 31, "vfprintf ERROR: malloc() failed");\r
+ WRITE_STR(_stdout, "vfprintf ERROR: malloc() failed");\r
return 0;\r
}\r
buf[size] = '\0';\r
}\r
\r
// Write to stream\r
- write(fp->FD, size, buf);\r
+ write(fp->FD, buf, size);\r
\r
// Free buffer\r
free(buf);\r
int ret;\r
if(!fp || !fp->FD) return -1;\r
\r
- ret = write(fp->FD, size*num, ptr);\r
+ ret = write(fp->FD, ptr, size*num);\r
\r
return ret;\r
}\r
int ret;\r
if(!fp || !fp->FD) return -1;\r
\r
- ret = read(fp->FD, size*num, ptr);\r
+ ret = read(fp->FD, ptr, size*num);\r
\r
return ret;\r
}\r
EXPORT int fputc(int c, FILE *fp)\r
{\r
if(!fp || !fp->FD) return -1;\r
- return write(fp->FD, 1, &c);\r
+ return write(fp->FD, &c, 1);\r
+}\r
+\r
+EXPORT int putchar(int c)\r
+{\r
+ c &= 0xFF;\r
+ return write(_stdout, &c, 1);\r
}\r
\r
/**\r
{\r
char ret = 0;\r
if(!fp) return -1;\r
- if(read(fp->FD, 1, &ret) == -1) return -1;\r
+ if(read(fp->FD, &ret, 1) == -1) return -1;\r
+ return ret;\r
+}\r
+\r
+EXPORT int getchar(void)\r
+{\r
+ char ret = 0;\r
+ if(read(_stdin, &ret, 1) != 1) return -1;\r
return ret;\r
}\r
\r
return NULL;\r
}\r
\r
-EXPORT int putchar(int ch)\r
-{\r
- return write(_stdout, 1, (char*)&ch);\r
-}\r
-\r
-EXPORT int puts(const char *str)\r
+EXPORT int puts(const char *str)\r
{\r
int len;\r
\r
if(!str) return 0;\r
len = strlen(str);\r
\r
- len = write(_stdout, len, (char*)str);\r
- write(_stdout, 1, "\n");\r
+ len = write(_stdout, str, len);\r
+ write(_stdout, "\n", 1);\r
return len;\r
}\r
\r
// Allocate buffer\r
buf = (char*)malloc(size+1);\r
if(buf) {\r
- write(_stdout, 29, "PRINTF ERROR: malloc() failed");\r
+ WRITE_STR(_stdout, "PRINTF ERROR: malloc() failed\n");\r
return 0;\r
}\r
buf[size] = '\0';\r
}\r
\r
// Send to stdout\r
- write(_stdout, size+1, buf);\r
+ write(_stdout, buf, size+1);\r
\r
// Free buffer\r
free(buf);\r
// --- Errors ---
void __stack_chk_fail()
{
- write(2, 32, "FATAL ERROR: Stack Check Failed\n");
+ write(2, "FATAL ERROR: Stack Check Failed\n", 32);
_exit(-1);
for(;;);
}
int len, i;
// Read as much as possible (appending to remaining data)
- len = read(STDIN_FD, READ_BUFFER_SIZE - 1 - Info->ReadBufferLen, Info->ReadBuffer);
+ len = read(STDIN_FD, Info->ReadBuffer, READ_BUFFER_SIZE - 1 - Info->ReadBufferLen);
if( len <= 0 ) return NULL;
Info->ReadBuffer[Info->ReadBufferLen + len] = '\0';
// Move to the beginning of the line
pos = oldLen;
- while(pos--) write(STDOUT_FD, 3, "\x1B[D");
+ while(pos--) write(STDOUT_FD, "\x1B[D", 3);
// Update state
Info->CurBuffer = Info->History[--Info->HistoryPos];
Info->BufferSize = Info->BufferUsed = strlen(Info->CurBuffer);
- write(STDOUT_FD, Info->BufferUsed, Info->CurBuffer);
+ write(STDOUT_FD, Info->CurBuffer, Info->BufferUsed);
Info->BufferWritePos = Info->BufferUsed;
// Clear old characters (if needed)
if( oldLen > Info->BufferWritePos ) {
pos = oldLen - Info->BufferWritePos;
- while(pos--) write(STDOUT_FD, 1, " ");
+ while(pos--) write(STDOUT_FD, " ", 1);
pos = oldLen - Info->BufferWritePos;
- while(pos--) write(STDOUT_FD, 3, "\x1B[D");
+ while(pos--) write(STDOUT_FD, "\x1B[D", 3);
}
}
break;
// Move to the beginning of the line
pos = oldLen;
- while(pos--) write(STDOUT_FD, 3, "\x1B[D");
+ while(pos--) write(STDOUT_FD, "\x1B[D", 3);
// Update state
Info->CurBuffer = Info->History[Info->HistoryPos++];
Info->BufferSize = Info->BufferUsed = strlen(Info->CurBuffer);
// Write new line
- write(STDOUT_FD, Info->BufferUsed, Info->CurBuffer);
+ write(STDOUT_FD, Info->CurBuffer, Info->BufferUsed);
Info->BufferWritePos = Info->BufferUsed;
// Clear old characters (if needed)
if( oldLen > Info->BufferWritePos ) {
pos = oldLen - Info->BufferWritePos;
- while(pos--) write(STDOUT_FD, 1, " ");
+ while(pos--) write(STDOUT_FD, " ", 1);
pos = oldLen - Info->BufferWritePos;
- while(pos--) write(STDOUT_FD, 3, "\x1B[D");
+ while(pos--) write(STDOUT_FD, "\x1B[D", 3);
}
}
break;
case 'D': // Left
if(Info->BufferWritePos == 0) break;
Info->BufferWritePos --;
- write(STDOUT_FD, 3, "\x1B[D");
+ write(STDOUT_FD, "\x1B[D", 3);
break;
case 'C': // Right
if(Info->BufferWritePos == Info->BufferUsed) break;
Info->BufferWritePos ++;
- write(STDOUT_FD, 3, "\x1B[C");
+ write(STDOUT_FD, "\x1B[C", 3);
break;
}
}
case '\b':
if(Info->BufferWritePos <= 0) break; // Protect against underflows
// Write the backsapce
- write(STDOUT_FD, 1, &ch);
+ write(STDOUT_FD, &ch, 1);
if(Info->BufferWritePos == Info->BufferUsed) // Simple case: End of string
{
Info->BufferUsed --;
buf[4] += (delta) % 10;
// Write everything save for the deleted character
write(STDOUT_FD,
- Info->BufferUsed - Info->BufferWritePos,
- &Info->CurBuffer[Info->BufferWritePos]
+ &Info->CurBuffer[Info->BufferWritePos],
+ Info->BufferUsed - Info->BufferWritePos
);
- ch = ' '; write(STDOUT_FD, 1, &ch); ch = '\b'; // Clear old last character
- write(STDOUT_FD, 7, buf); // Update Cursor
+ ch = ' '; write(STDOUT_FD, &ch, 1); ch = '\b'; // Clear old last character
+ write(STDOUT_FD, buf, 7); // Update Cursor
// Alter Buffer
memmove(&Info->CurBuffer[Info->BufferWritePos-1],
&Info->CurBuffer[Info->BufferWritePos],
buf[2] += (delta/100) % 10;
buf[3] += (delta/10) % 10;
buf[4] += (delta) % 10;
- write(STDOUT_FD, 1, &ch); // Print new character
+ write(STDOUT_FD, &ch, 1); // Print new character
write(STDOUT_FD,
- Info->BufferUsed - Info->BufferWritePos,
- &Info->CurBuffer[Info->BufferWritePos]
+ &Info->CurBuffer[Info->BufferWritePos],
+ Info->BufferUsed - Info->BufferWritePos
);
- write(STDOUT_FD, 7, buf); // Update Cursor
+ write(STDOUT_FD, buf, 7); // Update Cursor
// Move buffer right
memmove(
&Info->CurBuffer[Info->BufferWritePos+1],
}
// Simple append
else {
- write(STDOUT_FD, 1, &ch);
+ write(STDOUT_FD, &ch, 1);
}
Info->CurBuffer[ Info->BufferWritePos ++ ] = ch;
Info->BufferUsed ++;
extern int chdir(const char *dir);
extern int open(const char *path, int flags);
extern int reopen(int fd, const char *path, int flags);
-extern void close(int fd);
-extern uint read(int fd, uint length, void *buffer);
-extern uint write(int fd, uint length, void *buffer);
+extern int close(int fd);
+extern uint read(int fd, void *buffer, uint length);
+extern uint write(int fd, const void *buffer, uint length);
extern int seek(int fd, int64_t offset, int whence);
extern uint64_t tell(int fd);
extern int ioctl(int fd, int id, void *data);
extern int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *errfds, time_t *timeout);
// --- IPC ---
-extern int SysSendMessage(pid_t dest, uint length, void *Data);
+extern int SysSendMessage(pid_t dest, uint length, const void *Data);
extern int SysGetMessage(pid_t *src, void *Data);
// --- MEMORY ---
#ifdef __LP64__
typedef uint64_t intptr_t;
typedef uint64_t uintptr_t;
+typedef int64_t ptrdiff_t;
#else
typedef uint32_t intptr_t;
typedef uint32_t uintptr_t;
+typedef int32_t ptrdiff_t;
#endif
#if 0
# error "Unknown pointer size"
#endif
+
#endif
-/*\r
- * AcessOS LibC\r
- * stdlib.h\r
- */\r
-#ifndef __STDIO_H\r
+/*
+ * AcessOS LibC
+ * stdlib.h
+ */
+#ifndef __STDIO_H
#define __STDIO_H
-\r
-#include <stdlib.h>\r
-#include <stdarg.h>\r
-\r
+
+#include <stdlib.h>
+#include <stdarg.h>
+
// === Types ===
typedef struct sFILE FILE;
-\r
-// === CONSTANTS ===\r
-#define EOF (-1)\r
-\r
-// --- Standard IO ---\r
-extern int printf(const char *format, ...);\r
-extern int vsnprintf(char *buf, size_t __maxlen, const char *format, va_list args);\r
-extern int vsprintf(char *buf, const char *format, va_list args);\r
-extern int sprintf(char *buf, const char *format, ...);\r
-extern int snprintf(char *buf, size_t maxlen, const char *format, ...);\r
-\r
-extern FILE *fopen(const char *file, const char *mode);\r
-extern FILE *freopen(const char *file, const char *mode, FILE *fp);\r
+
+// === CONSTANTS ===
+#define EOF (-1)
+
+// --- Standard IO ---
+extern int printf(const char *format, ...);
+extern int vsnprintf(char *buf, size_t __maxlen, const char *format, va_list args);
+extern int vsprintf(char *buf, const char *format, va_list args);
+extern int sprintf(char *buf, const char *format, ...);
+extern int snprintf(char *buf, size_t maxlen, const char *format, ...);
+
+extern FILE *fopen(const char *file, const char *mode);
+extern FILE *freopen(const char *file, const char *mode, FILE *fp);
extern FILE *fdopen(int fd, const char *modes);
-extern void fclose(FILE *fp);\r
-extern void fflush(FILE *fp);\r
-extern long int ftell(FILE *fp);\r
-extern int fseek(FILE *fp, long int amt, int whence);\r
-\r
-extern size_t fread(void *buf, size_t size, size_t n, FILE *fp);\r
-extern size_t fwrite(void *buf, size_t size, size_t n, FILE *fp);\r
-extern int fgetc(FILE *fp);\r
-extern int fputc(int ch, FILE *fp);\r
-\r
-extern int fprintf(FILE *fp, const char *format, ...);\r
-extern int vfprintf(FILE *fp, const char *format, va_list args);\r
-\r
-extern FILE *stdin;\r
-extern FILE *stdout;\r
-extern FILE *stderr;\r
-
-#endif\r
+extern int fclose(FILE *fp);
+extern void fflush(FILE *fp);
+extern long int ftell(FILE *fp);
+extern int fseek(FILE *fp, long int amt, int whence);
+
+extern size_t fread(void *buf, size_t size, size_t n, FILE *fp);
+extern size_t fwrite(void *buf, size_t size, size_t n, FILE *fp);
+extern int fgetc(FILE *fp);
+extern int fputc(int ch, FILE *fp);
+extern int getchar(void);
+extern int putchar(int ch);
+
+extern int fprintf(FILE *fp, const char *format, ...);
+extern int vfprintf(FILE *fp, const char *format, va_list args);
+
+extern FILE *stdin;
+extern FILE *stdout;
+extern FILE *stderr;
+
+#endif
#ifndef _SYS_SYS_H_\r
#define _SYS_SYS_H_\r
\r
+#include <acess/sys.h>\r
+\r
#include <sys/types.h>\r
\r
+#define O_RDONLY OPENFLAG_READ\r
+#define O_WRONLY OPENFLAG_WRITE\r
+#define O_CREAT (OPENFLAG_CREATE|OPENFLAG_WRITE)\r
+#define O_TRUNC OPENFLAG_WRITE\r
+#define O_APPEND OPENFLAG_WRITE\r
+\r
+\r
+#if 0\r
#define OPEN_FLAG_READ 1\r
#define OPEN_FLAG_WRITE 2\r
#define OPEN_FLAG_EXEC 4\r
extern int sendmsg(int dest, unsigned int *Data);\r
extern int pollmsg(int *src, unsigned int *Data);\r
extern int getmsg(int *src, unsigned int *Data);\r
+#endif\r
\r
#endif\r