gaPageTable[Addr>>12] &= PF_USER;
gaPageTable[Addr>>12] |= paddr|PF_PRESENT|PF_WRITE;
}
- //LOG("Duplicated page at %p to 0x%x", Addr&~0xFFF, gaPageTable[Addr>>12]);
+
INVLPG( Addr & ~0xFFF );
//LEAVE('-')
return;
// === FUNCTIONS ===
extern int VFS_AddDriver(tVFS_Driver *Info);
extern tVFS_Driver *VFS_GetFSByName(char *Name);
+extern tVFS_ACL *VFS_UnixToAcessACL(Uint Mode, Uint Owner, Uint Group);
// --- Node Cache --
extern int Inode_GetHandle();
// === GLOBALS ===
char *gsInitPath = "/Acess/Bin/init";
-char *gsConfigScript = "/Acess/BootConf.cfg";
+char *gsConfigScript = "/Acess/Conf/BootConf.cfg";
// === CODE ===
void System_Init(char *ArgString)
Dest->Perms = 0;
return 0;
}
+
+/**
+ * \fn tVFS_ACL *VFS_UnixToAcessACL(Uint Mode, Uint Owner, Uint Group)
+ * \brief Converts UNIX permissions to three Acess ACL entries
+ */
+tVFS_ACL *VFS_UnixToAcessACL(Uint Mode, Uint Owner, Uint Group)
+{
+ tVFS_ACL *ret = malloc(sizeof(tVFS_ACL)*3);
+
+ // Error Check
+ if(!ret) return NULL;
+
+ // Owner
+ ret[0].Group = 0; ret[0].ID = Owner;
+ ret[0].Inv = 0; ret[0].Perms = 0;
+ if(Mode & 0400) ret[0].Perms |= VFS_PERM_READ;
+ if(Mode & 0200) ret[0].Perms |= VFS_PERM_WRITE;
+ if(Mode & 0100) ret[0].Perms |= VFS_PERM_EXECUTE;
+
+ // Group
+ ret[1].Group = 1; ret[1].ID = Group;
+ ret[1].Inv = 0; ret[1].Perms = 0;
+ if(Mode & 0040) ret[1].Perms |= VFS_PERM_READ;
+ if(Mode & 0020) ret[1].Perms |= VFS_PERM_WRITE;
+ if(Mode & 0010) ret[1].Perms |= VFS_PERM_EXECUTE;
+
+ // Global
+ ret[2].Group = 1; ret[2].ID = Group;
+ ret[2].Inv = 0; ret[2].Perms = 0;
+ if(Mode & 0004) ret[2].Perms |= VFS_PERM_READ;
+ if(Mode & 0002) ret[2].Perms |= VFS_PERM_WRITE;
+ if(Mode & 0001) ret[2].Perms |= VFS_PERM_EXECUTE;
+
+ // Return buffer
+ return ret;
+}
/*\r
- * Acess2\r
+ * Acess 2\r
* FAT12/16/32 Driver Version (Incl LFN)\r
*/\r
-//INCLUDES\r
+#define DEBUG 0\r
#include <common.h>\r
#include <modules.h>\r
#include <vfs.h>\r
#include "fs_fat.h"\r
\r
-#define DEBUG 0\r
#define VERBOSE 1\r
\r
-#if DEBUG\r
-# define DEBUGS(v...) Log(v)\r
-#else\r
-# define DEBUGS(v...)\r
-# undef ENTER\r
-# undef LOG\r
-# undef LEAVE\r
-# define ENTER(...)\r
-# define LOG(...)\r
-# define LEAVE(...)\r
-#endif\r
-\r
#define CACHE_FAT 1 //!< Caches the FAT in memory\r
#define USE_LFN 1 //!< Enables the use of Long File Names\r
\r
fat_cache[giFAT_PartCount][i] = buf[i&127];\r
}\r
}\r
- DEBUGS(" FAT_InitDisk: FAT Fully Cached\n");\r
+ LOG("FAT Fully Cached");\r
}\r
#endif /*CACHE_FAT*/\r
\r
//Initalise inode cache for FAT\r
gFAT_Disks[giFAT_PartCount].inodeHandle = Inode_GetHandle();\r
- \r
- #if DEBUG\r
- Log(" FAT_InitDisk: Inode Cache handle is %i\n", gFAT_Disks[giFAT_PartCount].inodeHandle);\r
- #endif\r
+ LOG("Inode Cache handle is %i", gFAT_Disks[giFAT_PartCount].inodeHandle);\r
\r
// == VFS Interface\r
node = &gFAT_Disks[giFAT_PartCount].rootNode;\r
*/\r
static void FAT_int_ReadCluster(int Handle, Uint32 Cluster, int Length, void *Buffer)\r
{\r
- #if DEBUG\r
ENTER("iHandle xCluster iLength pBuffer", Handle, Cluster, Length, Buffer);\r
- #endif\r
VFS_ReadAt(\r
gFAT_Disks[Handle].fileHandle,\r
(gFAT_Disks[Handle].firstDataSect + (Cluster-2)*gFAT_Disks[Handle].bootsect.spc )\r
Length,\r
Buffer\r
);\r
- #if DEBUG\r
LEAVE('-');\r
- #endif\r
}\r
\r
/**\r
// === CONSTANTS ===
#define NULL ((void*)0)
#define DEFAULT_TERMINAL "/Devices/VTerm/0"
-#define DEFAULT_SHELL "/Acess/CLIShell"
+#define DEFAULT_SHELL "/Acess/SBin/login"
// === CODE ===
/**
ASFLAGS = -felf\r
LDFLAGS = -x -shared -soname libc.so.1 -Map map.txt -e SoMain -L$(ACESSDIR)/Usermode/Libraries -lacess\r
\r
-OBJ_LIBC = heap.o stdlib.o stub.o env.o fileIO.o signals.o\r
+OBJ_LIBC = heap.o stdlib.o stub.o env.o fileIO.o signals.o string.o\r
BIN = ../libc.so.1\r
\r
.PHONY: all clean\r
#include <acess/sys.h>\r
#include <stdlib.h>\r
#include <stdio.h>\r
+#include <string.h>\r
+#include "lib.h"\r
#include "stdio_int.h"\r
\r
#define DEBUG_BUILD 0\r
\r
// === CONSTANTS ===\r
+#define _stdin 0\r
+#define _stdout 1\r
\r
// === PROTOTYPES ===\r
+EXPORT void itoa(char *buf, unsigned long num, int base, int minLength, char pad);\r
struct sFILE *get_file_struct();\r
\r
// === GLOBALS ===\r
struct sFILE _iob[STDIO_MAX_STREAMS]; // IO Buffer\r
+struct sFILE *stdin = &_iob[0]; // Standard Input\r
+struct sFILE *stdout = &_iob[1]; // Standard Output\r
+struct sFILE *stderr = &_iob[2]; // Standard Error\r
\r
// === CODE ===\r
/**\r
* \fn FILE *freopen(FILE *fp, char *file, char *mode)\r
*/\r
-FILE *freopen(FILE *fp, char *file, char *mode)\r
+EXPORT FILE *freopen(FILE *fp, char *file, char *mode)\r
{\r
int openFlags = 0;\r
int i;\r
\param file String - Filename to open\r
\param mode Mode to open in\r
*/\r
-FILE *fopen(char *file, char *mode)\r
+EXPORT FILE *fopen(char *file, char *mode)\r
{\r
FILE *retFile;\r
\r
return freopen(retFile, file, mode);\r
}\r
\r
-void fclose(FILE *fp)\r
+EXPORT void fclose(FILE *fp)\r
{\r
close(fp->FD);\r
free(fp);\r
}\r
\r
-void fflush(FILE *fp)\r
+EXPORT void fflush(FILE *fp)\r
{\r
///\todo Implement\r
}\r
\r
/**\r
- * \fn int fprintf(FILE *fp, const char *format, ...)\r
- * \brief Print a formatted string to a stream\r
+ * \fn int fprintfv(FILE *fp, const char *format, va_list args)\r
+ * \brief Print to a file from a variable argument list\r
*/\r
-int fprintf(FILE *fp, const char *format, ...)\r
+EXPORT int fprintfv(FILE *fp, const char *format, va_list args)\r
{\r
+ va_list tmpList = args;\r
int size;\r
char *buf;\r
- va_list args;\r
- \r
+ \r
if(!fp || !format) return -1;\r
\r
- // Get Size\r
- va_start(args, format);\r
- size = ssprintfv((char*)format, args);\r
- va_end(args);\r
+ size = ssprintfv((char*)format, tmpList);\r
\r
- // Allocate buffer\r
buf = (char*)malloc(size+1);\r
buf[size] = '\0';\r
\r
// Print\r
- va_start(args, format);\r
sprintfv(buf, (char*)format, args);\r
- va_end(args);\r
\r
// Write to stream\r
write(fp->FD, size+1, buf);\r
return size;\r
}\r
\r
+/**\r
+ * \fn int fprintf(FILE *fp, const char *format, ...)\r
+ * \brief Print a formatted string to a stream\r
+ */\r
+EXPORT int fprintf(FILE *fp, const char *format, ...)\r
+{\r
+ va_list args;\r
+ int ret;\r
+ \r
+ // Get Size\r
+ va_start(args, format);\r
+ ret = fprintfv(fp, (char*)format, args);\r
+ va_end(args);\r
+ \r
+ return ret;\r
+}\r
+\r
+/**\r
+ */\r
+EXPORT size_t fwrite(void *ptr, size_t size, size_t num, FILE *fp)\r
+{\r
+ int ret;\r
+ if(!fp || !fp->FD) return -1;\r
+ \r
+ ret = write(fp->FD, size*num, ptr);\r
+ \r
+ return ret;\r
+}\r
+\r
+/**\r
+ * \fn EXPORT int fputc(int c, FILE *fp)\r
+ * \brief Write a single character to the stream\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
+}\r
+\r
+/**\r
+ * \fn EXPORT int fgetc(FILE *fp)\r
+ * \brief Read a character from the stream\r
+ */\r
+EXPORT int fgetc(FILE *fp)\r
+{\r
+ int ret = 0;\r
+ if(!fp) return -1;\r
+ if(read(fp->FD, 1, &ret) == -1) return -1;\r
+ return ret;\r
+}\r
+\r
// --- INTERNAL ---\r
/**\r
* \fn FILE *get_file_struct()\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
+{\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
+ return len;\r
+}\r
+\r
+//sprintfv\r
+/**\r
+ \fn EXPORT void sprintfv(char *buf, const char *format, va_list args)\r
+ \brief Prints a formatted string to a buffer\r
+ \param buf Pointer - Destination Buffer\r
+ \param format String - Format String\r
+ \param args VarArgs List - Arguments\r
+*/\r
+EXPORT void sprintfv(char *buf, const char *format, va_list args)\r
+{\r
+ char tmp[33];\r
+ int c, arg, minSize;\r
+ int pos = 0;\r
+ char *p;\r
+ char pad;\r
+\r
+ tmp[32] = '\0';\r
+ \r
+ while((c = *format++) != 0)\r
+ {\r
+ //SysDebug("c = '%c'\n", c);\r
+ if (c != '%') {\r
+ buf[pos++] = c;\r
+ continue;\r
+ }\r
+ \r
+ c = *format++;\r
+ if(c == '%') {\r
+ buf[pos++] = '%';\r
+ continue;\r
+ }\r
+ \r
+ // Padding\r
+ if(c == '0') {\r
+ pad = '0';\r
+ c = *format++;\r
+ } else\r
+ pad = ' ';\r
+ minSize = 0;\r
+ if('1' <= c && c <= '9')\r
+ {\r
+ while('0' <= c && c <= '9')\r
+ {\r
+ minSize *= 10;\r
+ minSize += c - '0';\r
+ c = *format++;\r
+ }\r
+ }\r
+ \r
+ p = tmp;\r
+ \r
+ // Get Argument\r
+ arg = va_arg(args, int);\r
+ // Get Type\r
+ switch (c) {\r
+ case 'd':\r
+ case 'i':\r
+ if(arg < 0) {\r
+ buf[pos++] = '-';\r
+ arg = -arg;\r
+ }\r
+ itoa(tmp, arg, 10, minSize, pad);\r
+ goto sprintf_puts;\r
+ // break;\r
+ case 'u':\r
+ itoa(tmp, arg, 10, minSize, pad);\r
+ goto sprintf_puts;\r
+ // break;\r
+ case 'x':\r
+ itoa(tmp, arg, 16, minSize, pad);\r
+ goto sprintf_puts;\r
+ // break;\r
+ case 'o':\r
+ itoa(tmp, arg, 8, minSize, pad);\r
+ goto sprintf_puts;\r
+ // break;\r
+ case 'b':\r
+ itoa(tmp, arg, 2, minSize, pad);\r
+ goto sprintf_puts;\r
+ // break;\r
+\r
+ case 's':\r
+ p = (void*)arg;\r
+ sprintf_puts:\r
+ if(!p) p = "(null)";\r
+ while(*p) buf[pos++] = *p++;\r
+ break;\r
+\r
+ default:\r
+ buf[pos++] = arg;\r
+ break;\r
+ }\r
+ }\r
+ buf[pos++] = '\0';\r
+}\r
+/*\r
+ssprintfv\r
+- Size, Stream, Print Formated, Variable Argument List\r
+*/\r
+/**\r
+ \fn EXPORT int ssprintfv(char *format, va_list args)\r
+ \brief Gets the total character count from a formatted string\r
+ \param format String - Format String\r
+ \param args VarArgs - Argument List\r
+*/\r
+EXPORT int ssprintfv(char *format, va_list args)\r
+{\r
+ char tmp[33];\r
+ int c, arg, minSize;\r
+ int len = 0;\r
+ char *p;\r
+ char pad;\r
+\r
+ tmp[32] = '\0';\r
+ \r
+ while((c = *format++) != 0)\r
+ {\r
+ if (c != '%') {\r
+ len++;\r
+ continue;\r
+ }\r
+ \r
+ c = *format++;\r
+ \r
+ // Literal '%'\r
+ if(c == '%') {\r
+ len++;\r
+ continue;\r
+ }\r
+ \r
+ // Padding\r
+ if(c == '0') {\r
+ pad = '0';\r
+ c = *format++;\r
+ } else\r
+ pad = ' ';\r
+ minSize = 0;\r
+ if('1' <= c && c <= '9')\r
+ {\r
+ while('0' <= c && c <= '9')\r
+ {\r
+ minSize *= 10;\r
+ minSize += c - '0';\r
+ c = *format++;\r
+ }\r
+ }\r
+ \r
+ p = tmp;\r
+ arg = va_arg(args, int);\r
+ switch (c) { \r
+ case 'd':\r
+ case 'i':\r
+ if(arg < 0) {\r
+ len ++;\r
+ arg = -arg;\r
+ }\r
+ itoa(tmp, arg, 10, minSize, pad);\r
+ goto sprintf_puts;\r
+ case 'u':\r
+ itoa(tmp, arg, 10, minSize, pad);\r
+ goto sprintf_puts;\r
+ case 'x':\r
+ itoa(tmp, arg, 16, minSize, pad);\r
+ goto sprintf_puts;\r
+ case 'o':\r
+ itoa(tmp, arg, 8, minSize, pad);\r
+ p = tmp;\r
+ goto sprintf_puts;\r
+ case 'b':\r
+ itoa(tmp, arg, 2, minSize, pad);\r
+ goto sprintf_puts;\r
+\r
+ case 's':\r
+ p = (char*)arg;\r
+ sprintf_puts:\r
+ if(!p) p = "(null)";\r
+ while(*p) len++, p++;\r
+ break;\r
+\r
+ default:\r
+ len ++;\r
+ break;\r
+ }\r
+ }\r
+ return len;\r
+}\r
+\r
+const char cUCDIGITS[] = "0123456789ABCDEF";\r
+/**\r
+ * \fn static void itoa(char *buf, unsigned long num, int base, int minLength, char pad)\r
+ * \brief Convert an integer into a character string\r
+ */\r
+EXPORT void itoa(char *buf, unsigned long num, int base, int minLength, char pad)\r
+{\r
+ char tmpBuf[32];\r
+ int pos=0, i;\r
+\r
+ if(!buf) return;\r
+ if(base > 16) {\r
+ buf[0] = 0;\r
+ return;\r
+ }\r
+ \r
+ while(num > base-1) {\r
+ tmpBuf[pos] = cUCDIGITS[ num % base ];\r
+ num = (long) num / base; //Shift {number} right 1 digit\r
+ pos++;\r
+ }\r
+\r
+ tmpBuf[pos++] = cUCDIGITS[ num % base ]; //Last digit of {number}\r
+ i = 0;\r
+ minLength -= pos;\r
+ while(minLength-- > 0) buf[i++] = pad;\r
+ while(pos-- > 0) buf[i++] = tmpBuf[pos]; //Reverse the order of characters\r
+ buf[i] = 0;\r
+}\r
+\r
+/**\r
+ * \fn EXPORT int printf(const char *format, ...)\r
+ * \brief Print a string to stdout\r
+ */\r
+EXPORT int printf(const char *format, ...)\r
+{\r
+ #if 0\r
+ int size;\r
+ char *buf;\r
+ va_list args;\r
+ \r
+ va_start(args, format);\r
+ size = ssprintfv((char*)format, args);\r
+ va_end(args);\r
+ \r
+ buf = (char*)malloc(size+1);\r
+ buf[size] = '\0';\r
+ \r
+ va_start(args, format);\r
+ sprintfv(buf, (char*)format, args);\r
+ va_end(args);\r
+ \r
+ \r
+ write(_stdout, size+1, buf);\r
+ \r
+ free(buf);\r
+ return size;\r
+ #endif\r
+ \r
+ int ret;\r
+ va_list args;\r
+ va_start(args, format);\r
+ ret = fprintfv(stdout, (char*)format, args);\r
+ va_end(args);\r
+ return ret;\r
+}\r
+\r
+/**\r
+ * \fn EXPORT int sprintf(const char *buf, char *format, ...)\r
+ * \brief Print a formatted string to a buffer\r
+ */\r
+EXPORT int sprintf(char *buf, const char *format, ...)\r
+{\r
+ va_list args;\r
+ va_start(args, format);\r
+ sprintfv((char*)buf, (char*)format, args);\r
+ va_end(args);\r
+ return 1;\r
+}\r
/*\r
-AcessOS Basic C Library\r
-\r
-stdlib.c\r
-*/\r
+ * AcessOS Basic C Library\r
+ * stdlib.c\r
+ */\r
+/**\r
+ * \todo Move half of these to stdio\r
+ */\r
#include <acess/sys.h>\r
#include <stdlib.h>\r
+#include <stdio.h>\r
#include "lib.h"\r
\r
-int _stdout = 1;\r
-int _stdin = 2;\r
+#define _stdout 1\r
+#define _stdin 0\r
+\r
+// === IMPORTS ===\r
+extern int fprintfv(FILE *fp, const char *format, va_list args);\r
\r
-EXPORT int puts(const char *str);\r
-EXPORT void itoa(char *buf, unsigned long num, int base, int minLength, char pad);\r
+// === PROTOTYPES ===\r
EXPORT int atoi(const char *str);\r
-EXPORT int puts(const char *str);\r
-EXPORT int ssprintfv(char *format, va_list args);\r
-EXPORT void sprintfv(char *buf, char *format, va_list args);\r
-EXPORT int printf(const char *format, ...);\r
-EXPORT int strlen(const char *str);\r
-EXPORT int strcmp(char *str1, char *str2);\r
-EXPORT int strncmp(char *str1, char *str2, size_t len);\r
-EXPORT char *strcpy(char *dst, const char *src);\r
+EXPORT void exit(int status);\r
\r
// === CODE ===\r
-EXPORT int putchar(int ch)\r
-{\r
- return write(_stdout, 1, (char*)&ch);\r
-}\r
-\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
- return len;\r
-}\r
-\r
-//sprintfv\r
/**\r
- \fn EXPORT void sprintfv(char *buf, char *format, va_list args)\r
- \brief Prints a formatted string to a buffer\r
- \param buf Pointer - Destination Buffer\r
- \param format String - Format String\r
- \param args VarArgs List - Arguments\r
-*/\r
-EXPORT void sprintfv(char *buf, char *format, va_list args)\r
-{\r
- char tmp[33];\r
- int c, arg, minSize;\r
- int pos = 0;\r
- char *p;\r
- char pad;\r
-\r
- tmp[32] = '\0';\r
- \r
- while((c = *format++) != 0)\r
- {\r
- //SysDebug("c = '%c'\n", c);\r
- if (c != '%') {\r
- buf[pos++] = c;\r
- continue;\r
- }\r
- \r
- c = *format++;\r
- if(c == '%') {\r
- buf[pos++] = '%';\r
- continue;\r
- }\r
- \r
- // Padding\r
- if(c == '0') {\r
- pad = '0';\r
- c = *format++;\r
- } else\r
- pad = ' ';\r
- minSize = 0;\r
- if('1' <= c && c <= '9')\r
- {\r
- while('0' <= c && c <= '9')\r
- {\r
- minSize *= 10;\r
- minSize += c - '0';\r
- c = *format++;\r
- }\r
- }\r
- \r
- p = tmp;\r
- \r
- // Get Argument\r
- arg = va_arg(args, int);\r
- // Get Type\r
- switch (c) {\r
- case 'd':\r
- case 'i':\r
- if(arg < 0) {\r
- buf[pos++] = '-';\r
- arg = -arg;\r
- }\r
- itoa(tmp, arg, 10, minSize, pad);\r
- goto sprintf_puts;\r
- // break;\r
- case 'u':\r
- itoa(tmp, arg, 10, minSize, pad);\r
- goto sprintf_puts;\r
- // break;\r
- case 'x':\r
- itoa(tmp, arg, 16, minSize, pad);\r
- goto sprintf_puts;\r
- // break;\r
- case 'o':\r
- itoa(tmp, arg, 8, minSize, pad);\r
- goto sprintf_puts;\r
- // break;\r
- case 'b':\r
- itoa(tmp, arg, 2, minSize, pad);\r
- goto sprintf_puts;\r
- // break;\r
-\r
- case 's':\r
- p = (void*)arg;\r
- sprintf_puts:\r
- if(!p) p = "(null)";\r
- while(*p) buf[pos++] = *p++;\r
- break;\r
-\r
- default:\r
- buf[pos++] = arg;\r
- break;\r
- }\r
- }\r
- buf[pos++] = '\0';\r
-}\r
-/*\r
-ssprintfv\r
-- Size, Stream, Print Formated, Variable Argument List\r
-*/\r
-/**\r
- \fn EXPORT int ssprintfv(char *format, va_list args)\r
- \brief Gets the total character count from a formatted string\r
- \param format String - Format String\r
- \param args VarArgs - Argument List\r
-*/\r
-EXPORT int ssprintfv(char *format, va_list args)\r
-{\r
- char tmp[33];\r
- int c, arg, minSize;\r
- int len = 0;\r
- char *p;\r
- char pad;\r
-\r
- tmp[32] = '\0';\r
- \r
- while((c = *format++) != 0)\r
- {\r
- if (c != '%') {\r
- len++;\r
- continue;\r
- }\r
- \r
- c = *format++;\r
- \r
- // Literal '%'\r
- if(c == '%') {\r
- len++;\r
- continue;\r
- }\r
- \r
- // Padding\r
- if(c == '0') {\r
- pad = '0';\r
- c = *format++;\r
- } else\r
- pad = ' ';\r
- minSize = 0;\r
- if('1' <= c && c <= '9')\r
- {\r
- while('0' <= c && c <= '9')\r
- {\r
- minSize *= 10;\r
- minSize += c - '0';\r
- c = *format++;\r
- }\r
- }\r
- \r
- p = tmp;\r
- arg = va_arg(args, int);\r
- switch (c) { \r
- case 'd':\r
- case 'i':\r
- if(arg < 0) {\r
- len ++;\r
- arg = -arg;\r
- }\r
- itoa(tmp, arg, 10, minSize, pad);\r
- goto sprintf_puts;\r
- case 'u':\r
- itoa(tmp, arg, 10, minSize, pad);\r
- goto sprintf_puts;\r
- case 'x':\r
- itoa(tmp, arg, 16, minSize, pad);\r
- goto sprintf_puts;\r
- case 'o':\r
- itoa(tmp, arg, 8, minSize, pad);\r
- p = tmp;\r
- goto sprintf_puts;\r
- case 'b':\r
- itoa(tmp, arg, 2, minSize, pad);\r
- goto sprintf_puts;\r
-\r
- case 's':\r
- p = (char*)arg;\r
- sprintf_puts:\r
- if(!p) p = "(null)";\r
- while(*p) len++, p++;\r
- break;\r
-\r
- default:\r
- len ++;\r
- break;\r
- }\r
- }\r
- return len;\r
-}\r
-\r
-const char cUCDIGITS[] = "0123456789ABCDEF";\r
-/**\r
- * \fn static void itoa(char *buf, unsigned long num, int base, int minLength, char pad)\r
- * \brief Convert an integer into a character string\r
+ * \fn EXPORT void exit(int status)\r
+ * \brief Exit\r
*/\r
-EXPORT void itoa(char *buf, unsigned long num, int base, int minLength, char pad)\r
+EXPORT void exit(int status)\r
{\r
- char tmpBuf[32];\r
- int pos=0, i;\r
-\r
- if(!buf) return;\r
- if(base > 16) {\r
- buf[0] = 0;\r
- return;\r
- }\r
- \r
- while(num > base-1) {\r
- tmpBuf[pos] = cUCDIGITS[ num % base ];\r
- num = (long) num / base; //Shift {number} right 1 digit\r
- pos++;\r
- }\r
-\r
- tmpBuf[pos++] = cUCDIGITS[ num % base ]; //Last digit of {number}\r
- i = 0;\r
- minLength -= pos;\r
- while(minLength-- > 0) buf[i++] = pad;\r
- while(pos-- > 0) buf[i++] = tmpBuf[pos]; //Reverse the order of characters\r
- buf[i] = 0;\r
+ _exit(status);\r
}\r
\r
/**\r
if(neg) ret = -ret;\r
return ret;\r
}\r
-\r
-//printf\r
-EXPORT int printf(const char *format, ...)\r
-{\r
- int size;\r
- char *buf;\r
- va_list args;\r
- \r
- va_start(args, format);\r
- size = ssprintfv((char*)format, args);\r
- va_end(args);\r
- \r
- buf = (char*)malloc(size+1);\r
- buf[size] = '\0';\r
- \r
- va_start(args, format);\r
- sprintfv(buf, (char*)format, args);\r
- va_end(args);\r
- \r
- \r
- write(_stdout, size+1, buf);\r
- \r
- free(buf);\r
- return size;\r
-}\r
-\r
-EXPORT int sprintf(const char *buf, char *format, ...)\r
-{\r
- va_list args;\r
- va_start(args, format);\r
- sprintfv((char*)buf, (char*)format, args);\r
- va_end(args);\r
- return 1;\r
-}\r
-\r
-\r
-//MEMORY\r
-EXPORT int strcmp(char *s1, char *s2)\r
-{\r
- while(*s1 == *s2 && *s1 != '\0' && *s2 != '\0') {\r
- s1++; s2++;\r
- }\r
- return (int)*s1 - (int)*s2;\r
-}\r
-EXPORT char *strcpy(char *dst, const char *src)\r
-{\r
- char *_dst = dst;\r
- while(*src) {\r
- *dst = *src;\r
- src++; dst++;\r
- }\r
- *dst = '\0';\r
- return _dst;\r
-}\r
-EXPORT int strlen(const char *str)\r
-{\r
- int retval;\r
- for(retval = 0; *str != '\0'; str++)\r
- retval++;\r
- return retval;\r
-}\r
-\r
-EXPORT int strncmp(char *s1, char *s2, size_t len)\r
-{\r
- while(--len && *s1 == *s2 && *s1 != '\0' && *s2 != '\0') {\r
- s1++; s2++;\r
- }\r
- return (int)*s1 - (int)*s2;\r
-}\r
-\r
-EXPORT void *memcpy(void *dest, void *src, unsigned int count)\r
-{\r
- char *sp = (char *)src;\r
- char *dp = (char *)dest;\r
- for(;count--;) *dp++ = *sp++;\r
- return dest;\r
-}\r
-\r
-EXPORT void *memmove(void *dest, void *src, unsigned int count)\r
-{\r
- char *sp = (char *)src;\r
- char *dp = (char *)dest;\r
- // Check if corruption will happen\r
- if( (unsigned int)dest > (unsigned int)src && (unsigned int)dest < (unsigned int)src+count )\r
- for(;count--;) dp[count] = sp[count];\r
- else\r
- for(;count--;) *dp++ = *sp++;\r
- return dest;\r
-}\r
/*\r
-AcessOS Basic C Library\r
-*/\r
+ * AcessOS Basic C Library\r
+ */\r
+#include "stdio_int.h"\r
\r
extern char **_envp;\r
+extern struct sFILE _iob[];\r
\r
/**\r
* \fn int SoMain()\r
// Init for env.c\r
_envp = envp;\r
\r
+ // Init FileIO Pointers\r
+ _iob[0].FD = 0; _iob[0].Flags = FILE_FLAG_MODE_READ;\r
+ _iob[1].FD = 1; _iob[1].Flags = FILE_FLAG_MODE_WRITE;\r
+ _iob[2].FD = 2; _iob[2].Flags = FILE_FLAG_MODE_WRITE;\r
+ \r
return 1;\r
}\r
#define OPENFLAG_READ 0x02
#define OPENFLAG_WRITE 0x04
#define OPENFLAG_NOLINK 0x40
-#define SEEK_SET 1
-#define SEEK_CUR 0
-#define SEEK_END -1
+#ifndef SEEK_CUR
+# define SEEK_SET 1
+# define SEEK_CUR 0
+# define SEEK_END -1
+#endif
#define CLONE_VM 0x10
#define FILEFLAG_DIRECTORY 0x10
#define FILEFLAG_SYMLINK 0x20
// === FUNCTIONS ===
void _SysDebug(char *str, ...);
// --- Proc ---
+void _exit(int status) __attribute__((noreturn));
void sleep();
void wait(int miliseconds);
int waittid(int id, int *status);
int clone(int flags, void *stack);
int execve(char *path, char **argv, char **envp);
+void setuid(int id);
+void setgid(int id);
// --- VFS ---
int chdir(char *dir);
int open(char *path, int flags);
typedef struct sFILE FILE;
\r
extern int printf(const char *format, ...);\r
-extern void sprintfv(char *buf, char *format, va_list args);\r
+extern void sprintfv(char *buf, const char *format, va_list args);\r
extern int ssprintfv(char *format, va_list args);\r
-extern int sprintf(char *buf, char *format, ...);
+extern int sprintf(char *buf, const char *format, ...);
\r
extern FILE *fopen(char *file, char *mode);\r
extern FILE *freopen(FILE *fp, char *file, char *mode);
extern void fclose(FILE *fp);\r
extern void fflush(FILE *fp);\r
\r
-extern int fprintf(FILE *fp, const char *format, ...);
+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
+\r
+extern FILE *stdin;\r
+extern FILE *stdout;\r
+extern FILE *stderr;\r
#endif\r
\r
// --- StdLib ---\r
extern int atoi(const char *ptr);\r
-\r
-extern void *memcpy(void *dest, void *src, size_t count);\r
-extern void *memmove(void *dest, void *src, size_t count);\r
+extern void exit(int status) __attribute__((noreturn));\r
\r
// --- Environment ---\r
extern char *getenv(const char *name);\r
extern void *realloc(void *oldPos, unsigned int bytes);\r
extern int IsHeap(void *ptr);\r
\r
-// --- Strings ---\r
-extern int strlen(const char *string);\r
-extern int strcmp(char *str1, char *str2);\r
-extern int strncmp(char *str1, char *str2, size_t len);\r
-extern char *strcpy(char *dst, const char *src);\r
-\r
#ifndef SEEK_CUR\r
# define SEEK_CUR 0\r
# define SEEK_SET 1\r