Changeset 1136 for Whitix

Show
Ignore:
Timestamp:
10/14/08 19:40:04 (1 month ago)
Author:
mwhitworth
Message:

Add various stub functions, prototypes and defines.

Location:
Whitix/branches/keobject/user/libc
Files:
10 modified

Legend:

Unmodified
Added
Removed
  • Whitix/branches/keobject/user/libc/include/stdarg.h

    r608 r1136  
    22#define STDC_STDARG_H 
    33 
    4 typedef unsigned char* va_list; 
     4typedef __builtin_va_list va_list; 
    55 
    66/* Just get the memory location after the last argument */ 
    77#define va_start(list,lastArg) \ 
    8         (list=((va_list)&(lastArg)+va_size(lastArg))); 
     8        __builtin_va_start(list, lastArg) 
    99 
    1010/* Must be the other way round because of the comma operator */ 
    1111#define va_arg(list,type) \ 
    12         (list+=__va_rounded_size(type), \ 
    13         *((type*)(list-__va_rounded_size(type)))) 
     12        __builtin_va_arg(list, type) 
    1413 
    15 /* Stacks are int-aligned */ 
    16 #define __va_rounded_size(type) \ 
    17         (((sizeof(type)+sizeof(int)-1)/sizeof(int))*sizeof(int)) 
    18  
    19 #define va_size(type) \ 
    20         ((sizeof(type)+sizeof(int)-1) \ 
    21         & ~(sizeof(int)-1)) 
    22  
    23 #define va_copy(dst,src) ((void)((dst)=(src))) 
     14#define va_copy(dst,src) __builtin_va_copy(dst, src) 
    2415 
    2516/* Just for a certain cleanliness */ 
    26 #define va_end(list) 
     17#define va_end(list) __builtin_va_end(list) 
    2718 
    2819#endif 
  • Whitix/branches/keobject/user/libc/include/stdint.h

    r608 r1136  
    33 
    44typedef long int intmax_t; 
     5typedef unsigned long long uintmax_t; 
    56 
    67#include <inttypes.h> 
  • Whitix/branches/keobject/user/libc/include/stdlib.h

    r910 r1136  
    7575typedef long int int_fast32_t; 
    7676 
     77#define alloca(size) __builtin_alloca(size) 
     78 
    7779#endif 
  • Whitix/branches/keobject/user/libc/include/syscalls.h

    r912 r1136  
    1212#endif 
    1313 
    14 #ifndef BYTE 
    15 typedef unsigned char BYTE; 
    16 #endif 
    17  
    1814/* Some useful structures for syscalls */ 
    1915 
    2016struct DirEntry 
    2117{ 
    22         DWORD vNodeNum; 
    23         DWORD offset; 
    24         WORD length; 
     18        unsigned long vNodeNum; 
     19        unsigned long offset; 
     20        unsigned short length; 
     21        unsigned short type; 
    2522        char name[1]; 
    2623}; 
     
    3330struct Stat 
    3431{ 
    35         DWORD size; 
    36         DWORD vNum; 
    37         DWORD mode; 
     32        unsigned long size; 
     33        unsigned long vNum; 
     34        unsigned long mode; 
    3835        unsigned long aTime,cTime,mTime; 
    3936}; 
  • Whitix/branches/keobject/user/libc/include/sysdefs.h

    r912 r1136  
    1616SYSCALL(14,int,SysChangeDir,4,(char* newDir)); 
    1717SYSCALL(15,int,SysChangeRoot,4,(char* newRoot)); 
    18 SYSCALL(16,int,SysMount,16,(char* mountPoint,char* deviceName,char* fsName,void* data)); 
     18SYSCALL(16,int,SysMount,16,(char* deviceName,char* mountName,char* fsName,void* data)); 
    1919SYSCALL(17,int,SysUnmount,4,(char* mountPoint)); 
    2020SYSCALL(18,int,SysGetDirEntries,12,(int fd,void* entries,unsigned long numBytes)); 
  • Whitix/branches/keobject/user/libc/stdio/get.c

    r910 r1136  
    9494        }else{ 
    9595                printf("ungetc: TODO\n"); 
     96                exit(0); 
    9697        } 
    9798 
  • Whitix/branches/keobject/user/libc/stdlib/Makefile

    r684 r1136  
    11include ../make.inc 
    22 
    3 OBJS = alloca.o mem.o exit.o atoi.o div.o math.o system.o qsort.o env.o time.o rand.o bsearch.o 
     3OBJS = mem.o exit.o atoi.o div.o math.o system.o qsort.o env.o time.o rand.o bsearch.o 
    44 
    55build: $(OBJS) 
  • Whitix/branches/keobject/user/libc/stdlib/env.c

    r910 r1136  
    99                return NULL; 
    1010                 
    11         printf("getenv(%s)\n", name); 
     11//      if (!strcmp(name, "LDEMULATION")) 
     12//              return "elf_i386"; 
     13                 
     14//      printf("getenv(%s)\n", name); 
    1215        return NULL; 
    1316} 
     
    1518int putenv(const char* name) 
    1619{ 
    17         printf("putenv(%s)\n", name); 
     20//      printf("putenv(%s)\n", name); 
    1821        return 0; 
    1922} 
  • Whitix/branches/keobject/user/libc/stdlib/exit.c

    r910 r1136  
    66{ 
    77        printf("Abnormal program termination from %#X\n",__builtin_return_address(0)); 
     8         
     9        /* FIXME: TEMP */ 
     10        DWORD* esp; 
     11         
     12        asm volatile("mov %%esp, %%eax" : "=a"(esp)); 
     13         
     14        int i; 
     15         
     16        for (i=0; i<10; i++) 
     17        { 
     18                printf("%#X\n", *esp++); 
     19        } 
     20         
    821        SysExit(1); 
    922} 
     
    1629int atexit(void (*function)()) 
    1730{ 
     31        printf("atexit(%#X)\n", function); 
    1832        return 0; 
    1933} 
  • Whitix/branches/keobject/user/libc/string/str.c

    r910 r1136  
    7474int strncmp(const char* s1,const char* s2,size_t num) 
    7575{ 
    76         char result=0; 
    77  
    78     while (num) 
    79         { 
    80                 if ((result=*s1-*s2++) || !*s1++) 
    81                         break; 
    82  
    83                 --num; 
    84         } 
    85  
    86     return result; 
     76        unsigned char c1, c2; 
     77 
     78    while (num-- > 0) 
     79        { 
     80                c1 = (unsigned char)*s1++; 
     81                c2 = (unsigned char)*s2++; 
     82                 
     83                if (c1 != c2) 
     84                        return c1-c2; 
     85                 
     86                if (c1 == '\0') 
     87                        return 0; 
     88        } 
     89 
     90    return 0; 
    8791} 
    8892 
     
    261265void perror(const char* string) 
    262266{ 
    263         fprintf(stderr,"%s: %s\n",string,strerror(errno)); 
     267        fprintf(stderr,"%s: %s (from %#X)\n",string,strerror(errno), __builtin_return_address(0)); 
    264268} 
    265269 
     
    440444} 
    441445 
    442 unsigned long int strtoul(const char *nptr, char **endptr, int base) 
     446unsigned long int strtoul(const char *str, char **endptr, int base) 
     447{ 
     448        int negative=0; 
     449        unsigned long number = 0; 
     450         
     451        while (isspace(str)) 
     452                str++; 
     453 
     454        /* Optional sign */ 
     455        switch (*str) 
     456        { 
     457                case '-': 
     458                        negative=1; 
     459                case '+': 
     460                        str++; 
     461        } 
     462         
     463        if (!(base & ~0x10)) 
     464        { 
     465                base += 10; 
     466                if (*str == '0') 
     467                { 
     468                        base -=2; 
     469                        str++; 
     470                         
     471                        if (tolower(*str) == 'x') 
     472                        { 
     473                                ++str; 
     474                                base += base; 
     475                        } 
     476                } 
     477                 
     478                if (base > 16) 
     479                        base = 16; 
     480        } 
     481         
     482        if (((unsigned)(base - 2)) < 35) 
     483        { 
     484                unsigned long cutOffDigit, cutOff; /* Use. ULONG_MAX */ 
     485                 
     486                do 
     487                { 
     488                        unsigned char digit; 
     489                         
     490                        if ((*str - '0') <= 9) 
     491                                digit = *str - '0'; 
     492                        else if (*str >= 'A') 
     493                                digit = tolower(*str)-'a'+10; 
     494                        else 
     495                                digit = 40; 
     496                         
     497                        if (digit >= base) 
     498                                break; 
     499                                 
     500                        ++str; 
     501                         
     502                        number = number*base + digit; 
     503                } while(1); 
     504        } 
     505         
     506        if (endptr) 
     507                *endptr=str; 
     508         
     509        return negative ? (unsigned long)(-((long)number)) : number; 
     510} 
     511 
     512unsigned long long int strtoull(const char *nptr, char **endptr, int base) 
    443513{ 
    444514        TODO; 
    445 } 
    446  
    447 unsigned long long int strtoull(const char *nptr, char **endptr, int base) 
    448 { 
    449         TODO; 
     515        while (1); 
    450516} 
    451517 
     
    743809} 
    744810 
     811int strcmpi(const char* s1, const char* s2) 
     812{ 
     813        return strncasecmp(s1, s2, ~0); 
     814} 
     815 
    745816size_t strxfrm(char* dest, const char* src, size_t n) 
    746817{