bugfixing
git-svn-id: svn://kolibrios.org@6412 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
2b5de6aa60
commit
9bafc8aa7b
@ -6,8 +6,8 @@ echo ####################################################
|
||||
rem #### CONFIG SECTION ####
|
||||
set LIBNAME=libck.a
|
||||
set INCLUDE=include
|
||||
set CC=kos32-tcc
|
||||
set CFLAGS=-c -nostdinc -DGNUC -I"%cd%\%INCLUDE%"
|
||||
set CC=kos32-tcc
|
||||
set CFLAGS=-c -nostdinc -DGNUC -I"%cd%\%INCLUDE%" -Wall
|
||||
set AR=kos32-ar
|
||||
set ASM=fasm
|
||||
set dirs=stdio memory kolibrisys string stdlib
|
||||
|
57
programs/develop/ktcc/trunk/libc/include/float.h
Normal file
57
programs/develop/ktcc/trunk/libc/include/float.h
Normal file
@ -0,0 +1,57 @@
|
||||
#ifndef _FLOAT_H_
|
||||
#define _FLOAT_H_
|
||||
|
||||
#define FLT_RADIX 2
|
||||
|
||||
/* IEEE float */
|
||||
#define FLT_MANT_DIG 24
|
||||
#define FLT_DIG 6
|
||||
#define FLT_ROUNDS 1
|
||||
#define FLT_EPSILON 1.19209290e-07F
|
||||
#define FLT_MIN_EXP (-125)
|
||||
#define FLT_MIN 1.17549435e-38F
|
||||
#define FLT_MIN_10_EXP (-37)
|
||||
#define FLT_MAX_EXP 128
|
||||
#define FLT_MAX 3.40282347e+38F
|
||||
#define FLT_MAX_10_EXP 38
|
||||
|
||||
/* IEEE double */
|
||||
#define DBL_MANT_DIG 53
|
||||
#define DBL_DIG 15
|
||||
#define DBL_EPSILON 2.2204460492503131e-16
|
||||
#define DBL_MIN_EXP (-1021)
|
||||
#define DBL_MIN 2.2250738585072014e-308
|
||||
#define DBL_MIN_10_EXP (-307)
|
||||
#define DBL_MAX_EXP 1024
|
||||
#define DBL_MAX 1.7976931348623157e+308
|
||||
#define DBL_MAX_10_EXP 308
|
||||
|
||||
/* horrible intel long double */
|
||||
#ifdef __i386__
|
||||
|
||||
#define LDBL_MANT_DIG 64
|
||||
#define LDBL_DIG 18
|
||||
#define LDBL_EPSILON 1.08420217248550443401e-19L
|
||||
#define LDBL_MIN_EXP (-16381)
|
||||
#define LDBL_MIN 3.36210314311209350626e-4932L
|
||||
#define LDBL_MIN_10_EXP (-4931)
|
||||
#define LDBL_MAX_EXP 16384
|
||||
#define LDBL_MAX 1.18973149535723176502e+4932L
|
||||
#define LDBL_MAX_10_EXP 4932
|
||||
|
||||
#else
|
||||
|
||||
/* same as IEEE double */
|
||||
#define LDBL_MANT_DIG 53
|
||||
#define LDBL_DIG 15
|
||||
#define LDBL_EPSILON 2.2204460492503131e-16
|
||||
#define LDBL_MIN_EXP (-1021)
|
||||
#define LDBL_MIN 2.2250738585072014e-308
|
||||
#define LDBL_MIN_10_EXP (-307)
|
||||
#define LDBL_MAX_EXP 1024
|
||||
#define LDBL_MAX 1.7976931348623157e+308
|
||||
#define LDBL_MAX_10_EXP 308
|
||||
|
||||
#endif
|
||||
|
||||
#endif /* _FLOAT_H_ */
|
15
programs/develop/ktcc/trunk/libc/include/stdarg.h
Normal file
15
programs/develop/ktcc/trunk/libc/include/stdarg.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef _STDARG_H
|
||||
#define _STDARG_H
|
||||
|
||||
typedef char *va_list;
|
||||
|
||||
/* only correct for i386 */
|
||||
#define va_start(ap,last) ap = ((char *)&(last)) + ((sizeof(last)+3)&~3)
|
||||
#define va_arg(ap,type) (ap += (sizeof(type)+3)&~3, *(type *)(ap - ((sizeof(type)+3)&~3)))
|
||||
#define va_end(ap)
|
||||
|
||||
/* fix a buggy dependency on GCC in libio.h */
|
||||
typedef va_list __gnuc_va_list;
|
||||
#define _VA_LIST_DEFINED
|
||||
|
||||
#endif
|
10
programs/develop/ktcc/trunk/libc/include/stdbool.h
Normal file
10
programs/develop/ktcc/trunk/libc/include/stdbool.h
Normal file
@ -0,0 +1,10 @@
|
||||
#ifndef _STDBOOL_H
|
||||
#define _STDBOOL_H
|
||||
|
||||
/* ISOC99 boolean */
|
||||
|
||||
#define bool _Bool
|
||||
#define true 1
|
||||
#define false 0
|
||||
|
||||
#endif /* _STDBOOL_H */
|
21
programs/develop/ktcc/trunk/libc/include/stddef.h
Normal file
21
programs/develop/ktcc/trunk/libc/include/stddef.h
Normal file
@ -0,0 +1,21 @@
|
||||
#ifndef _STDDEF_H
|
||||
#define _STDDEF_H
|
||||
|
||||
#define NULL ((void *)0)
|
||||
typedef __SIZE_TYPE__ size_t;
|
||||
typedef __WCHAR_TYPE__ wchar_t;
|
||||
typedef __PTRDIFF_TYPE__ ptrdiff_t;
|
||||
#define offsetof(type, field) ((size_t) &((type *)0)->field)
|
||||
|
||||
/* need to do that because of glibc 2.1 bug (should have a way to test
|
||||
presence of 'long long' without __GNUC__, or TCC should define
|
||||
__GNUC__ ? */
|
||||
#if !defined(__int8_t_defined) && !defined(__dietlibc__)
|
||||
#define __int8_t_defined
|
||||
typedef char int8_t;
|
||||
typedef short int int16_t;
|
||||
typedef int int32_t;
|
||||
typedef long long int int64_t;
|
||||
#endif
|
||||
|
||||
#endif
|
@ -10,7 +10,7 @@ typedef char *va_list;
|
||||
#define va_end(ap) (ap = (va_list)0)
|
||||
|
||||
#define NULL ((void*)0)
|
||||
//extern int stdcall format_print(char *dest, size_t maxlen, const char *fmt0, va_list argp);
|
||||
int format_print(char *dest, size_t maxlen,const char *fmt0, va_list argp);
|
||||
|
||||
typedef struct {
|
||||
char* buffer;
|
||||
@ -54,4 +54,6 @@ extern int vsnprintf(char *dest, size_t size,const char *format,va_list ap);
|
||||
extern int cdecl snprintf(char *dest, size_t size, const char *format,...);
|
||||
extern int cdecl sprintf(char *dest,const char *format,...);
|
||||
|
||||
#define getc(a) fgetc(a)
|
||||
|
||||
#endif
|
||||
|
@ -11,8 +11,8 @@ extern int atoib(char *s,int b);
|
||||
extern int atoi(char *s);
|
||||
extern unsigned char tolower(unsigned char c);
|
||||
extern unsigned char toupper(unsigned char c);
|
||||
extern void itoab(int n,char* s,int b);
|
||||
extern void itoa(int n,char* s);
|
||||
extern char *itoab(int n,char* s,int b);
|
||||
extern char *itoa(int n,char* s);
|
||||
|
||||
extern void* stdcall malloc(dword size);
|
||||
extern void stdcall free(void *pointer);
|
||||
|
@ -22,4 +22,5 @@ extern char* strstr(const char*,const char*);
|
||||
extern char* strtok(char*,const char*);
|
||||
extern int strxfrm(char*,const char*,int);
|
||||
extern char* strdup(const char*);
|
||||
extern char* strrev(char *p);
|
||||
#endif
|
||||
|
11
programs/develop/ktcc/trunk/libc/include/varargs.h
Normal file
11
programs/develop/ktcc/trunk/libc/include/varargs.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef _VARARGS_H
|
||||
#define _VARARGS_H
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#define va_dcl
|
||||
#define va_alist __va_alist
|
||||
#undef va_start
|
||||
#define va_start(ap) ap = __builtin_varargs_start
|
||||
|
||||
#endif
|
@ -31,8 +31,8 @@ realloc:
|
||||
|
||||
mov ebx,20
|
||||
mov eax,68
|
||||
mov ecx,[esp+4]
|
||||
mov edx,[esp+8]
|
||||
mov edx,[esp+4] ; pointer
|
||||
mov ecx,[esp+8] ; size
|
||||
int 0x40
|
||||
|
||||
ret 8
|
||||
|
@ -128,7 +128,7 @@ FILE* fopen(const char* filename, const char *mode)
|
||||
res->filesize=0;
|
||||
res->filepos=0;
|
||||
res->mode=imode;
|
||||
res->filename=getfullpath(filename);
|
||||
res->filename=(char*)getfullpath(filename);
|
||||
|
||||
if ((imode==FILE_OPEN_READ) || (imode==FILE_OPEN_APPEND))
|
||||
{
|
||||
|
@ -414,9 +414,11 @@ int format_print(char *dest, size_t maxlen,const char *fmt0, va_list argp)
|
||||
flag_unsigned=1;
|
||||
break;
|
||||
case 'x':
|
||||
case 'p':
|
||||
format_flag=1;
|
||||
break;
|
||||
case 'X':
|
||||
case 'P':
|
||||
flag_register=1;
|
||||
format_flag=1;
|
||||
break;
|
||||
@ -451,7 +453,7 @@ int format_print(char *dest, size_t maxlen,const char *fmt0, va_list argp)
|
||||
{
|
||||
case 'c':
|
||||
case 'C':
|
||||
if ((pos+1)<maxlen)
|
||||
if ((pos+1)<=maxlen)
|
||||
{
|
||||
//*s=(int)va_arg(argp,char*);
|
||||
*s=*((char *)argp);
|
||||
@ -461,97 +463,93 @@ int format_print(char *dest, size_t maxlen,const char *fmt0, va_list argp)
|
||||
break;
|
||||
case 's':
|
||||
case 'S':
|
||||
str=va_arg(argp,char*);
|
||||
length=strlen(str);
|
||||
if ((pos+length)<maxlen)
|
||||
{
|
||||
memcpy(s,str,length);
|
||||
s=s+length;pos=pos+length;
|
||||
}
|
||||
break;
|
||||
str=va_arg(argp,char*);
|
||||
length=strlen(str);
|
||||
if (pos + length > maxlen)
|
||||
length = maxlen - pos;
|
||||
memcpy(s,str,length);
|
||||
s=s+length;pos=pos+length;
|
||||
break;
|
||||
case 'd':
|
||||
case 'D':
|
||||
case 'i':
|
||||
case 'I':
|
||||
if (flag_long==0) {intdigit=va_arg(argp,int);}
|
||||
if (flag_long==1) {intdigit=va_arg(argp,long);}
|
||||
if (flag_long==2) {intdigit=va_arg(argp,long long);}
|
||||
//intdigit=*((long*)argp);
|
||||
//argp=argp+4;
|
||||
if ((intdigit>0) && (flag_plus==1) && (pos+1<maxlen))
|
||||
{
|
||||
*s='+';
|
||||
s++;
|
||||
pos++;
|
||||
}
|
||||
length=formatted_long_to_string(intdigit,0,buf);
|
||||
if ((pos+length)<maxlen)
|
||||
{
|
||||
memcpy(s,buf,length);
|
||||
s=s+length;pos=pos+length;
|
||||
}
|
||||
break;
|
||||
if (flag_long==0) {intdigit=va_arg(argp,int);}
|
||||
if (flag_long==1) {intdigit=va_arg(argp,long);}
|
||||
if (flag_long==2) {intdigit=va_arg(argp,long long);}
|
||||
//intdigit=*((long*)argp);
|
||||
//argp=argp+4;
|
||||
if ((intdigit>0) && (flag_plus==1) && (pos+1<=maxlen))
|
||||
{
|
||||
*s='+';
|
||||
s++;
|
||||
pos++;
|
||||
}
|
||||
length=formatted_long_to_string(intdigit,0,buf);
|
||||
if (pos + length > maxlen)
|
||||
length = maxlen - pos;
|
||||
memcpy(s,buf,length);
|
||||
s=s+length;pos=pos+length;
|
||||
break;
|
||||
case 'o':
|
||||
if (flag_long==0) {intdigit=va_arg(argp,int);}
|
||||
if (flag_long==1) {intdigit=va_arg(argp,long);}
|
||||
if (flag_long==2) {intdigit=va_arg(argp,long long);}
|
||||
//intdigit=*((long int *)argp);
|
||||
//argp=argp+4;
|
||||
if (flag_long==0) {intdigit=va_arg(argp,int);}
|
||||
if (flag_long==1) {intdigit=va_arg(argp,long);}
|
||||
if (flag_long==2) {intdigit=va_arg(argp,long long);}
|
||||
//intdigit=*((long int *)argp);
|
||||
//argp=argp+4;
|
||||
|
||||
length=formatted_octa_to_string(intdigit,0,flag_register,buf);
|
||||
if ((pos+length)<maxlen)
|
||||
{
|
||||
memcpy(s,buf,length);
|
||||
s=s+length;pos=pos+length;
|
||||
}
|
||||
break;
|
||||
length=formatted_octa_to_string(intdigit,0,flag_register,buf);
|
||||
if (pos + length > maxlen)
|
||||
length = maxlen - pos;
|
||||
memcpy(s,buf,length);
|
||||
s=s+length;pos=pos+length;
|
||||
break;
|
||||
case 'u':
|
||||
case 'U':
|
||||
if (flag_long==0) {intdigit=va_arg(argp,int);}
|
||||
if (flag_long==1) {intdigit=va_arg(argp,long int);}
|
||||
if (flag_long==2) {intdigit=va_arg(argp,long long);}
|
||||
if (flag_long==0) {intdigit=va_arg(argp,int);}
|
||||
if (flag_long==1) {intdigit=va_arg(argp,long int);}
|
||||
if (flag_long==2) {intdigit=va_arg(argp,long long);}
|
||||
|
||||
if (flag_unsigned==1) {
|
||||
if (intdigit<0) {intdigit=-intdigit;}
|
||||
}
|
||||
if (flag_unsigned==1) {
|
||||
if (intdigit<0) {intdigit=-intdigit;}
|
||||
}
|
||||
|
||||
length=formatted_long_to_string(intdigit,0,buf);
|
||||
if ((pos+length)<maxlen)
|
||||
{
|
||||
memcpy(s,buf,length);
|
||||
s=s+length;pos=pos+length;
|
||||
}
|
||||
break;
|
||||
length=formatted_long_to_string(intdigit,0,buf);
|
||||
if (pos + length > maxlen)
|
||||
length = maxlen - pos;
|
||||
memcpy(s,buf,length);
|
||||
s=s+length;pos=pos+length;
|
||||
break;
|
||||
case 'p':
|
||||
case 'P':
|
||||
case 'x':
|
||||
case 'X':
|
||||
if (flag_long==0) {intdigit=va_arg(argp,int);}
|
||||
if (flag_long==1) {intdigit=va_arg(argp,long);}
|
||||
if (flag_long==2) {intdigit=va_arg(argp,long long);}
|
||||
//intdigit=*((long int *)argp);
|
||||
//argp=argp+4;
|
||||
if (flag_long==0) {intdigit=va_arg(argp,int);}
|
||||
if (flag_long==1) {intdigit=va_arg(argp,long);}
|
||||
if (flag_long==2) {intdigit=va_arg(argp,long long);}
|
||||
//intdigit=*((long int *)argp);
|
||||
//argp=argp+4;
|
||||
|
||||
length=formatted_hex_to_string(intdigit,0,flag_register,buf);
|
||||
if ((pos+length)<maxlen)
|
||||
{
|
||||
memcpy(s,buf,length);
|
||||
s=s+length;pos=pos+length;
|
||||
}
|
||||
break;
|
||||
length=formatted_hex_to_string(intdigit,0,flag_register,buf);
|
||||
if (pos + length > maxlen)
|
||||
length = maxlen - pos;
|
||||
memcpy(s,buf,length);
|
||||
s=s+length;pos=pos+length;
|
||||
break;
|
||||
case 'z':
|
||||
case 'Z':
|
||||
intdigit=va_arg(argp,size_t);
|
||||
intdigit=va_arg(argp,size_t);
|
||||
|
||||
if (flag_unsigned==1) {
|
||||
if (intdigit<0) {intdigit=-intdigit;}
|
||||
}
|
||||
if (flag_unsigned==1) {
|
||||
if (intdigit<0) {intdigit=-intdigit;}
|
||||
}
|
||||
|
||||
length=formatted_long_to_string(intdigit,0,buf);
|
||||
if ((pos+length)<maxlen)
|
||||
{
|
||||
memcpy(s,buf,length);
|
||||
s=s+length;pos=pos+length;
|
||||
}
|
||||
break;
|
||||
length=formatted_long_to_string(intdigit,0,buf);
|
||||
if (pos + length > maxlen)
|
||||
length = maxlen - pos;
|
||||
memcpy(s,buf,length);
|
||||
s=s+length;pos=pos+length;
|
||||
break;
|
||||
default:;
|
||||
|
||||
}
|
||||
@ -717,10 +715,7 @@ int format_print(char *dest, size_t maxlen,const char *fmt0, va_list argp)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (*fmt=='\0') {break;}
|
||||
*s=*fmt;
|
||||
fmt++;
|
||||
s++;
|
||||
if (!(*s++ = *fmt++)) break;
|
||||
pos++;
|
||||
}
|
||||
exit_check:;
|
||||
|
@ -1,4 +1,5 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int format_print(char *dest, size_t maxlen, const char *fmt,va_list argp);
|
||||
|
||||
|
@ -4,7 +4,7 @@ void skipspaces(FILE* file)
|
||||
int c;
|
||||
while(1)
|
||||
{
|
||||
c=getc(file);
|
||||
c=fgetc(file);
|
||||
if (c!=' ' && c!='\r' && c!='\n')
|
||||
{
|
||||
ungetc(c,file);
|
||||
@ -12,6 +12,7 @@ void skipspaces(FILE* file)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int fscanf(FILE* file,const char* format, ...)
|
||||
{
|
||||
int res;
|
||||
@ -34,7 +35,7 @@ int fscanf(FILE* file,const char* format, ...)
|
||||
c=fgetc(file);
|
||||
if (c!=*format)
|
||||
{
|
||||
fungetc(c,file);
|
||||
ungetc(c,file);
|
||||
return -1;
|
||||
}
|
||||
format++;
|
||||
|
@ -1,11 +1,13 @@
|
||||
#include <stdio.h>
|
||||
int fseek(FILE* file,long offset,int origin)
|
||||
{
|
||||
fpos_t pos;
|
||||
if (origin==SEEK_CUR)
|
||||
offset+=file->filepos;
|
||||
else if (origin==SEEK_END)
|
||||
offset+=file->filesize;
|
||||
else if (origin!=SEEK_SET)
|
||||
return EOF;
|
||||
return fsetpos(file,offset);
|
||||
pos = offset;
|
||||
return fsetpos(file, &pos);
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <kolibrisys.h>
|
||||
|
@ -1,11 +1,12 @@
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "ctype.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
** itoa(n,s) - Convert n to characters in s
|
||||
*/
|
||||
void itoa(int n,char* s)
|
||||
char* itoa(int n,char* s)
|
||||
{
|
||||
int sign;
|
||||
char *ptr;
|
||||
@ -16,6 +17,6 @@ void itoa(int n,char* s)
|
||||
} while ((n = n / 10) > 0);
|
||||
if (sign < 0) *ptr++ = '-';
|
||||
*ptr = '\0';
|
||||
reverse(s);
|
||||
return strrev(s);
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,13 @@
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
#include "ctype.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
** itoab(n,s,b) - Convert "unsigned" n to characters in s using base b.
|
||||
** NOTE: This is a non-standard function.
|
||||
*/
|
||||
void itoab(int n,char* s,int b)
|
||||
char* itoab(int n,char* s,int b)
|
||||
{
|
||||
char *ptr;
|
||||
int lowbit;
|
||||
@ -20,5 +21,5 @@ void itoab(int n,char* s,int b)
|
||||
++ptr;
|
||||
} while(n /= b);
|
||||
*ptr = 0;
|
||||
reverse (s);
|
||||
return strrev(s);
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
#include <string.h>
|
||||
|
||||
int strcoll(const char* string1,const char* string2)
|
||||
{
|
||||
return strcmp(string1,string2);
|
||||
|
@ -1,4 +1,7 @@
|
||||
char* strdup(char* str)
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
char* strdup(const char* str)
|
||||
{
|
||||
char* res;
|
||||
int len;
|
||||
|
@ -1,13 +1,13 @@
|
||||
char* strpbrk(const char* string, const char* strCharSet)
|
||||
{
|
||||
char* temp;
|
||||
const char* temp;
|
||||
while (*string!='\0')
|
||||
{
|
||||
temp=strCharSet;
|
||||
while (*temp!='\0')
|
||||
{
|
||||
if (*string==*temp)
|
||||
return string;
|
||||
return (char*)string;
|
||||
temp++;
|
||||
}
|
||||
string++;
|
||||
|
12
programs/develop/ktcc/trunk/libc/string/strrev.c
Normal file
12
programs/develop/ktcc/trunk/libc/string/strrev.c
Normal file
@ -0,0 +1,12 @@
|
||||
char* strrev(char *p)
|
||||
{
|
||||
char *q = p, *res = p, z;
|
||||
while(q && *q) ++q; /* find eos */
|
||||
for(--q; p < q; ++p, --q)
|
||||
{
|
||||
z = *p;
|
||||
*p = *q;
|
||||
*q = z;
|
||||
}
|
||||
return res;
|
||||
}
|
@ -1,11 +1,12 @@
|
||||
extern int strncmp(char* s1,char* s2,int len);
|
||||
#include<string.h>
|
||||
|
||||
char* strstr(const char* s, const char* find)
|
||||
{
|
||||
int len;
|
||||
len=strlen(find);
|
||||
while (1)
|
||||
{
|
||||
if (strncmp(s,find,len)==0) return s;
|
||||
if (strncmp(s,find,len)==0) return (char*)s;
|
||||
if (*s=='\0')
|
||||
return (char*) 0;
|
||||
s++;
|
||||
|
Loading…
Reference in New Issue
Block a user