Subversion Repositories Kolibri OS

Compare Revisions

No changes between revisions

Regard whitespace Rev 9764 → Rev 9765

/programs/develop/ktcc/trunk/libc.obj/source/ctype/tolower.c
2,6 → 2,7
 
int tolower(int c)
{
if (isupper(c)) return c | 32;
if (isupper(c))
return c | 32;
return c;
}
/programs/develop/ktcc/trunk/libc.obj/source/ctype/toupper.c
2,6 → 2,7
 
int toupper(int c)
{
if (islower(c)) return c & 0x5f;
if (islower(c))
return c & 0x5f;
return c;
}
/programs/develop/ktcc/trunk/libc.obj/source/libc.c
4,103 → 4,101
#include "ctype/tolower.c"
#include "ctype/toupper.c"
 
#include "sys/closedir.c"
#include "sys/dir.c"
#include "sys/opendir.c"
#include "sys/readdir.c"
#include "sys/rewinddir.c"
#include "sys/readdir.c"
#include "sys/seekdir.c"
#include "sys/opendir.c"
#include "sys/socket.c"
#include "sys/telldir.c"
#include "sys/closedir.c"
#include "sys/dir.c"
#include "sys/socket.c"
 
#include "stdio/clearerr.c"
#include "stdio/gets.c"
#include "stdio/setbuf.c"
#include "stdio/conio.c"
#include "stdio/debug_printf.c"
#include "stdio/fclose.c"
#include "stdio/feof.c"
#include "stdio/ferror.c"
#include "stdio/fflush.c"
#include "stdio/fgetc.c"
#include "stdio/fgetpos.c"
#include "stdio/fgets.c"
#include "stdio/fopen.c"
#include "stdio/format_print.c"
#include "stdio/vprintf.c"
#include "stdio/feof.c"
#include "stdio/fwrite.c"
#include "stdio/format_scan.c"
#include "stdio/fprintf.c"
#include "stdio/fputc.c"
#include "stdio/fputs.c"
#include "stdio/fread.c"
#include "stdio/freopen.c"
#include "stdio/fscanf.c"
#include "stdio/fseek.c"
#include "stdio/fgetpos.c"
#include "stdio/fclose.c"
#include "stdio/snprintf.c"
#include "stdio/rename.c"
#include "stdio/fsetpos.c"
#include "stdio/ftell.c"
#include "stdio/fwrite.c"
#include "stdio/getchar.c"
#include "stdio/gets.c"
#include "stdio/perror.c"
#include "stdio/printf.c"
#include "stdio/puts.c"
#include "stdio/remove.c"
#include "stdio/ferror.c"
#include "stdio/tmpfile.c"
#include "stdio/fputs.c"
#include "stdio/fputc.c"
#include "stdio/fgets.c"
#include "stdio/fflush.c"
#include "stdio/format_scan.c"
#include "stdio/printf.c"
#include "stdio/fscanf.c"
#include "stdio/debug_printf.c"
#include "stdio/fsetpos.c"
#include "stdio/rename.c"
#include "stdio/rewind.c"
#include "stdio/scanf.c"
#include "stdio/setbuf.c"
#include "stdio/setvbuf.c"
#include "stdio/snprintf.c"
#include "stdio/sprintf.c"
#include "stdio/sscanf.c"
#include "stdio/scanf.c"
#include "stdio/freopen.c"
#include "stdio/puts.c"
#include "stdio/sprintf.c"
#include "stdio/vsnprintf.c"
#include "stdio/conio.c"
#include "stdio/perror.c"
#include "stdio/ftell.c"
#include "stdio/tmpfile.c"
#include "stdio/tmpnam.c"
#include "stdio/rewind.c"
#include "stdio/ungetc.c"
#include "stdio/vfprintf.c"
#include "stdio/fprintf.c"
#include "stdio/ungetc.c"
#include "stdio/vprintf.c"
#include "stdio/vsnprintf.c"
 
#include "string/strerror.c"
#include "string/strxfrm.c"
#include "string/strrchr.c"
#include "string/strcspn.c"
#include "string/strlen.c"
#include "string/strrev.c"
#include "string/memccpy.c"
#include "string/memchr.c"
#include "string/memcmp.c"
#include "string/memcpy.c"
#include "string/strcat.c"
#include "string/strchr.c"
#include "string/strcmp.c"
#include "string/strcoll.c"
#include "string/strpbrk.c"
#include "string/strstr.c"
#include "string/memcmp.c"
#include "string/strspn.c"
#include "string/strcpy.c"
#include "string/strncpy.c"
#include "string/strcspn.c"
#include "string/strdup.c"
#include "string/strcat.c"
#include "string/memchr.c"
#include "string/strerror.c"
#include "string/strlen.c"
#include "string/strncat.c"
#include "string/strncmp.c"
#include "string/strncat.c"
#include "string/strncpy.c"
#include "string/strpbrk.c"
#include "string/strrchr.c"
#include "string/strrev.c"
#include "string/strspn.c"
#include "string/strstr.c"
#include "string/strtok.c"
#include "string/strcmp.c"
#include "string/memset.c"
#include "string/memcpy.c"
#include "string/memmove.c"
#include "string/strxfrm.c"
 
#include "stdlib/abs.c"
#include "stdlib/assert.c"
#include "stdlib/atof.c"
#include "stdlib/atoi.c"
#include "stdlib/atol.c"
#include "stdlib/atoll.c"
#include "stdlib/calloc.c"
#include "stdlib/malloc.c"
#include "stdlib/atoll.c"
#include "stdlib/exit.c"
#include "stdlib/free.c"
#include "stdlib/itoa.c"
#include "stdlib/labs.c"
#include "stdlib/llabs.c"
#include "stdlib/exit.c"
#include "stdlib/atoi.c"
#include "stdlib/labs.c"
#include "stdlib/malloc.c"
#include "stdlib/qsort.c"
#include "stdlib/rand.c"
#include "stdlib/realloc.c"
#include "stdlib/abs.c"
#include "stdlib/atol.c"
#include "stdlib/itoa.c"
#include "stdlib/strtod.c"
#include "stdlib/strtol.c"
#include "stdlib/rand.c"
#include "stdlib/qsort.c"
#include "stdlib/assert.c"
#include "stdlib/strtod.c"
#include "stdlib/atof.c"
 
#include "math/acosh.c"
#include "math/asinh.c"
112,11 → 110,11
#include "math/sinh.c"
#include "math/tanh.c"
 
#include "time/asctime.c"
#include "time/difftime.c"
#include "time/localtime.c"
#include "time/mktime.c"
#include "time/time.c"
#include "time/asctime.c"
 
#include "misc/basename.c"
#include "misc/dirname.c"
140,18 → 138,17
".include \"math/pow10.s\"\n\t"
".include \"math/sqrt.s\"\n\t"
".include \"math/sin.s\"\n\t"
".include \"math/tan.s\"\n\t"
);
".include \"math/tan.s\"\n\t");
 
__asm__(
".include \"string/memmove.s\"\n\t"
".include \"string/memset.s\"\n\t"
".include \"setjmp/longjmp.s\"\n\t"
".include \"setjmp/setjmp.s\""
);
".include \"setjmp/setjmp.s\"");
 
#include "libtcc1/libtcc1.c"
#include "stdlib/___chkstk_ms.c"
 
 
ksys_dll_t EXPORTS[] = {
{"clearerr", &clearerr},
{"debug_printf", &debug_printf},
236,7 → 233,7
{"strstr", &strstr},
{"strtok", &strtok},
{"strxfrm", &strxfrm},
{"_errno", &_errno},
{ "__errno", &__errno },
{"closedir", &closedir},
{"opendir", &opendir},
{"readdir", &readdir},
/programs/develop/ktcc/trunk/libc.obj/source/libtcc1/libtcc1.c
44,8 → 44,7
Wtype low, high;
};
 
typedef union
{
typedef union {
struct DWstruct s;
DWtype ll;
} DWunion;
68,8 → 67,7
#define HIDDEND (1 << 20)
#define EXPD(fp) (((fp.l.upper) >> 20) & 0x7FF)
#define SIGND(fp) ((fp.l.upper) & SIGNBIT)
#define MANTD(fp) (((((fp.l.upper) & 0xFFFFF) | HIDDEND) << 10) | \
(fp.l.lower >> 22))
#define MANTD(fp) (((((fp.l.upper) & 0xFFFFF) | HIDDEND) << 10) | (fp.l.lower >> 22))
#define HIDDEND_LL ((long long)1 << 52)
#define MANTD_LL(fp) ((fp.ll & (HIDDEND_LL-1)) | HIDDEND_LL)
#define PACKD_LL(s,e,m) (((long long)((s)+((e)<<20))<<32)|(m))
139,7 → 137,8
do { \
USItype __cbtmp; \
__asm__ ("bsrl %1,%0" \
: "=r" (__cbtmp) : "rm" ((USItype) (x))); \
: "=r"(__cbtmp) \
: "rm"((USItype)(x))); \
(count) = __cbtmp ^ 31; \
} while (0)
#else
165,10 → 164,8
n1 = nn.s.high;
 
#if !defined(UDIV_NEEDS_NORMALIZATION)
if (d1 == 0)
{
if (d0 > n1)
{
if (d1 == 0) {
if (d0 > n1) {
/* 0q = nn / 0D */
 
udiv_qrnnd (q0, n0, n1, n0, d0);
175,9 → 172,7
q1 = 0;
 
/* Remainder in n0. */
}
else
{
} else {
/* qq = NN / 0d */
 
if (d0 == 0)
189,8 → 184,7
/* Remainder in n0. */
}
 
if (rp != 0)
{
if (rp != 0) {
rr.s.low = n0;
rr.s.high = 0;
*rp = rr.ll;
199,16 → 193,13
 
#else /* UDIV_NEEDS_NORMALIZATION */
 
if (d1 == 0)
{
if (d0 > n1)
{
if (d1 == 0) {
if (d0 > n1) {
/* 0q = nn / 0D */
 
count_leading_zeros (bm, d0);
 
if (bm != 0)
{
if (bm != 0) {
/* Normalize, i.e. make the most significant bit of the
denominator set. */
 
221,9 → 212,7
q1 = 0;
 
/* Remainder in n0 >> bm. */
}
else
{
} else {
/* qq = NN / 0d */
 
if (d0 == 0)
231,8 → 220,7
 
count_leading_zeros (bm, d0);
 
if (bm == 0)
{
if (bm == 0) {
/* From (n1 >= d0) /\ (the most significant bit of d0 is set),
conclude (the most significant bit of n1 is set) /\ (the
leading quotient digit q1 = 1).
242,9 → 230,7
 
n1 -= d0;
q1 = 1;
}
else
{
} else {
/* Normalize. */
 
b = W_TYPE_SIZE - bm;
264,8 → 250,7
/* Remainder in n0 >> bm. */
}
 
if (rp != 0)
{
if (rp != 0) {
rr.s.low = n0 >> bm;
rr.s.high = 0;
*rp = rr.ll;
273,10 → 258,8
}
#endif /* UDIV_NEEDS_NORMALIZATION */
 
else
{
if (d1 > n1)
{
else {
if (d1 > n1) {
/* 00 = nn / DD */
 
q0 = 0;
283,20 → 266,16
q1 = 0;
 
/* Remainder in n1n0. */
if (rp != 0)
{
if (rp != 0) {
rr.s.low = n0;
rr.s.high = n1;
*rp = rr.ll;
}
}
else
{
} else {
/* 0q = NN / dd */
 
count_leading_zeros (bm, d1);
if (bm == 0)
{
if (bm == 0) {
/* From (n1 >= d1) /\ (the most significant bit of d1 is set),
conclude (the most significant bit of n1 is set) /\ (the
quotient digit q0 = 0 or 1).
305,25 → 284,20
 
/* The condition on the next line takes advantage of that
n1 >= d1 (true due to program flow). */
if (n1 > d1 || n0 >= d0)
{
if (n1 > d1 || n0 >= d0) {
q0 = 1;
sub_ddmmss (n1, n0, n1, n0, d1, d0);
}
else
} else
q0 = 0;
 
q1 = 0;
 
if (rp != 0)
{
if (rp != 0) {
rr.s.low = n0;
rr.s.high = n1;
*rp = rr.ll;
}
}
else
{
} else {
UWtype m1, m0;
/* Normalize. */
 
338,8 → 312,7
udiv_qrnnd (q0, n1, n2, n1, d1);
umul_ppmm (m1, m0, q0, d0);
 
if (m1 > n1 || (m1 == n1 && m0 > n0))
{
if (m1 > n1 || (m1 == n1 && m0 > n0)) {
q0--;
sub_ddmmss (m1, m0, m1, m0, d1, d0);
}
347,8 → 320,7
q1 = 0;
 
/* Remainder in (n1n0 - m1m0) >> bm. */
if (rp != 0)
{
if (rp != 0) {
sub_ddmmss (n1, n0, n1, n0, m1, m0);
rr.s.low = (n1 << b) | (n0 >> bm);
rr.s.high = n1 >> bm;
495,11 → 467,17
{
unsigned c0, c1;
long long ret;
__asm__ __volatile__ ("fnstcw %0" : "=m" (c0));
__asm__ __volatile__("fnstcw %0"
: "=m"(c0));
c1 = c0 | 0x0C00;
__asm__ __volatile__ ("fldcw %0" : : "m" (c1));
__asm__ __volatile__ ("fistpll %0" : "=m" (ret));
__asm__ __volatile__ ("fldcw %0" : : "m" (c0));
__asm__ __volatile__("fldcw %0"
:
: "m"(c1));
__asm__ __volatile__("fistpll %0"
: "=m"(ret));
__asm__ __volatile__("fldcw %0"
:
: "m"(c0));
return ret;
}
#endif
626,7 → 604,8
 
long long __fixsfdi (float a1)
{
long long ret; int s;
long long ret;
int s;
ret = __fixunssfdi((s = a1 >= 0) ? a1 : -a1);
return s ? ret : -ret;
}
633,7 → 612,8
 
long long __fixdfdi (double a1)
{
long long ret; int s;
long long ret;
int s;
ret = __fixunsdfdi((s = a1 >= 0) ? a1 : -a1);
return s ? ret : -ret;
}
640,7 → 620,8
 
long long __fixxfdi (long double a1)
{
long long ret; int s;
long long ret;
int s;
ret = __fixunsxfdi((s = a1 >= 0) ? a1 : -a1);
return s ? ret : -ret;
}
648,8 → 629,8
#if defined(TCC_TARGET_X86_64) && !defined(_WIN64)
 
#ifndef __TINYC__
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#else
/* Avoid including stdlib.h because it is not easily available when
662,7 → 643,9
#endif
 
enum __va_arg_type {
__va_gen_reg, __va_float_reg, __va_stack
__va_gen_reg,
__va_float_reg,
__va_stack
};
 
//This should be in sync with the declaration on our include/stdarg.h
738,9 → 721,9
#elif defined(TCC_TARGET_ARM)
 
#define _GNU_SOURCE
#include <stdio.h>
#include <sys/syscall.h>
#include <unistd.h>
#include <sys/syscall.h>
#include <stdio.h>
 
void __clear_cache(void *beginning, void *end)
{
/programs/develop/ktcc/trunk/libc.obj/source/math/acosh.c
1,8 → 1,7
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <math.h>
 
double
acosh(double x)
double acosh(double x)
{
return log(x + sqrt(x*x - 1));
}
}
/programs/develop/ktcc/trunk/libc.obj/source/math/asinh.c
1,9 → 1,7
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <math.h>
 
double
asinh(double x)
double asinh(double x)
{
return x>0 ? log(x + sqrt(x*x + 1)) : -log(sqrt(x*x+1)-x);
}
 
/programs/develop/ktcc/trunk/libc.obj/source/math/atan2.s
30,7 → 30,7
fpatan
ret
isanan:
movl $1, _errno
movl $1, __errno
fstp %st(0)
fstp %st(0)
fldl nan
/programs/develop/ktcc/trunk/libc.obj/source/math/atanh.c
1,8 → 1,7
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <math.h>
 
double
atanh(double x)
double atanh(double x)
{
return log((1+x)/(1-x)) / 2.0;
}
/programs/develop/ktcc/trunk/libc.obj/source/math/frexp.c
1,8 → 1,7
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <math.h>
 
double
frexp(double x, int *exptr)
double frexp(double x, int* exptr)
{
union {
double d;
/programs/develop/ktcc/trunk/libc.obj/source/math/hypot.c
17,8 → 17,8
*/
 
/// #include <float.h>
#include <errno.h>
#include <math.h>
#include <errno.h>
/* Approximate square roots of DBL_MAX and DBL_MIN. Numbers
between these two shouldn't neither overflow nor underflow
26,15 → 26,13
#define __SQRT_DBL_MAX 1.3e+154
#define __SQRT_DBL_MIN 2.3e-162
double
hypot(double x, double y)
double hypot(double x, double y)
{
double abig = fabs(x), asmall = fabs(y);
double ratio;
/* Make abig = max(|x|, |y|), asmall = min(|x|, |y|). */
if (abig < asmall)
{
if (abig < asmall) {
double temp = abig;
abig = asmall;
53,8 → 51,7
if ((ratio = asmall / abig) > __SQRT_DBL_MIN && abig < __SQRT_DBL_MAX)
return abig * sqrt(1.0 + ratio*ratio);
else
{
else {
/* Slower but safer algorithm due to Moler and Morrison. Never
produces any intermediate result greater than roughly the
larger of X and Y. Should converge to machine-precision
80,8 → 77,7
#include <stdio.h>
int
main(void)
int main(void)
{
printf("hypot(3, 4) =\t\t\t %25.17e\n", hypot(3., 4.));
printf("hypot(3*10^150, 4*10^150) =\t %25.17g\n", hypot(3.e+150, 4.e+150));
/programs/develop/ktcc/trunk/libc.obj/source/math/ldexp.c
2,27 → 2,24
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <math.h>
 
double
ldexp(double v, int e)
double ldexp(double v, int e)
{
double two = 2.0;
 
if (e < 0) {
e = -e; /* This just might overflow on two-complement machines. */
if (e < 0)
{
e = -e; /* This just might overflow on two-complement machines. */
if (e < 0) return 0.0;
while (e > 0)
{
if (e & 1) v /= two;
return 0.0;
while (e > 0) {
if (e & 1)
v /= two;
two *= two;
e >>= 1;
}
}
else if (e > 0)
{
while (e > 0)
{
if (e & 1) v *= two;
} else if (e > 0) {
while (e > 0) {
if (e & 1)
v *= two;
two *= two;
e >>= 1;
}
29,4 → 26,3
}
return v;
}
 
/programs/develop/ktcc/trunk/libc.obj/source/math/sinh.c
3,13 → 3,10
 
double sinh(double x)
{
if(x >= 0.0)
{
if (x >= 0.0) {
const double epos = exp(x);
return (epos - 1.0/epos) / 2.0;
}
else
{
} else {
const double eneg = exp(-x);
return (1.0/eneg - eneg) / 2.0;
}
/programs/develop/ktcc/trunk/libc.obj/source/math/tanh.c
7,11 → 7,9
return 1;
else if (x < -50)
return -1;
else
{
else {
const double ebig = exp(x);
const double esmall = 1.0/ebig;
return (ebig - esmall) / (ebig + esmall);
}
}
 
/programs/develop/ktcc/trunk/libc.obj/source/misc/basename.c
1,13 → 1,15
#include <libgen.h>
#include <string.h>
#include <libgen.h>
 
char *basename(char *s)
{
size_t i;
if (!s || !*s) return ".";
if (!s || !*s)
return ".";
i = strlen(s)-1;
for (; i&&s[i]=='/'; i--) s[i] = 0;
for (; i&&s[i-1]!='/'; i--);
for (; i && s[i] == '/'; i--)
s[i] = 0;
for (; i && s[i - 1] != '/'; i--)
;
return s+i;
}
/programs/develop/ktcc/trunk/libc.obj/source/misc/dirname.c
1,14 → 1,21
#include <libgen.h>
#include <string.h>
#include <libgen.h>
 
char *dirname(char *s)
{
size_t i;
if (!s || !*s) return ".";
if (!s || !*s)
return ".";
i = strlen(s)-1;
for (; s[i]=='/'; i--) if (!i) return "/";
for (; s[i]!='/'; i--) if (!i) return ".";
for (; s[i]=='/'; i--) if (!i) return "/";
for (; s[i] == '/'; i--)
if (!i)
return "/";
for (; s[i] != '/'; i--)
if (!i)
return ".";
for (; s[i] == '/'; i--)
if (!i)
return "/";
s[i+1] = 0;
return s;
}
/programs/develop/ktcc/trunk/libc.obj/source/stdlib/assert.c
1,7 → 1,6
#include <stdio.h>
#include <stdlib.h>
 
 
#pragma GCC push_options
#pragma GCC optimize("O0")
 
/programs/develop/ktcc/trunk/libc.obj/source/stdlib/atoi.c
1,5 → 1,5
#include <ctype.h>
#include <stdlib.h>
#include <ctype.h>
 
/*
** atoi(s) - convert s to integer.
7,15 → 7,19
int atoi(const char *s)
{
int sign, n;
while(isspace(*s)) ++s;
while (isspace(*s))
++s;
sign = 1;
switch(*s) {
case '-': sign = -1;
case '+': ++s;
case '-':
sign = -1;
case '+':
++s;
}
n = 0;
while(isdigit(*s)) n = 10 * n + *s++ - '0';
while (isdigit(*s))
n = 10 * n + *s++ - '0';
return (sign * n);
}
/programs/develop/ktcc/trunk/libc.obj/source/stdlib/atol.c
1,14 → 1,17
#include <ctype.h>
#include <stdlib.h>
#include <ctype.h>
 
long atol(const char *s)
{
long n=0;
int neg=0;
while (isspace(*s)) s++;
while (isspace(*s))
s++;
switch (*s) {
case '-': neg=1;
case '+': s++;
case '-':
neg = 1;
case '+':
s++;
}
/* Compute n as a negative number to avoid overflow on LONG_MIN */
while (isdigit(*s))
/programs/develop/ktcc/trunk/libc.obj/source/stdlib/atoll.c
1,14 → 1,17
#include <ctype.h>
#include <stdlib.h>
#include <ctype.h>
 
long long atoll(const char *s)
{
long long n=0;
int neg=0;
while (isspace(*s)) s++;
while (isspace(*s))
s++;
switch (*s) {
case '-': neg=1;
case '+': s++;
case '-':
neg = 1;
case '+':
s++;
}
/* Compute n as a negative number to avoid overflow on LLONG_MIN */
while (isdigit(*s))
/programs/develop/ktcc/trunk/libc.obj/source/stdlib/calloc.c
1,11 → 1,12
#include <errno.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/ksys.h>
 
void *calloc(size_t num, size_t size) {
void* calloc(size_t num, size_t size)
{
void *ptr = _ksys_alloc(num*size);
if(!ptr){
errno = ENOMEM;
__errno = ENOMEM;
return NULL;
}
memset(ptr, 0, num*size);
/programs/develop/ktcc/trunk/libc.obj/source/stdlib/free.c
1,6 → 1,7
#include <stdlib.h>
#include <sys/ksys.h>
 
void free(void *ptr) {
void free(void* ptr)
{
_ksys_free(ptr);
}
/programs/develop/ktcc/trunk/libc.obj/source/stdlib/malloc.c
1,6 → 1,7
#include <stdlib.h>
#include <sys/ksys.h>
 
void *malloc(size_t size) {
void* malloc(size_t size)
{
return _ksys_alloc(size);
}
/programs/develop/ktcc/trunk/libc.obj/source/stdlib/qsort.c
52,8 → 52,7
* (And there are only three places where this is done).
*/
 
static void
qst(char *base, char *max)
static void qst(char* base, char* max)
{
char c, *i, *j, *jj;
int ii;
72,18 → 71,15
lo = max - base; /* number of elements as chars */
do {
mid = i = base + qsz * ((lo / qsz) >> 1);
if (lo >= mthresh)
{
if (lo >= mthresh) {
j = (qcmp((jj = base), i) > 0 ? jj : i);
if (qcmp(j, (tmp = max - qsz)) > 0)
{
if (qcmp(j, (tmp = max - qsz)) > 0) {
/* switch to first loser */
j = (j == jj ? i : jj);
if (qcmp(j, tmp) < 0)
j = tmp;
}
if (j != i)
{
if (j != i) {
ii = qsz;
do {
c = *i;
95,25 → 91,19
/*
* Semi-standard quicksort partitioning/swapping
*/
for (i = base, j = max - qsz; ; )
{
for (i = base, j = max - qsz;;) {
while (i < mid && qcmp(i, mid) <= 0)
i += qsz;
while (j > mid)
{
if (qcmp(mid, j) <= 0)
{
while (j > mid) {
if (qcmp(mid, j) <= 0) {
j -= qsz;
continue;
}
tmp = i + qsz; /* value of i after swap */
if (i == mid)
{
if (i == mid) {
/* j <-> mid, new mid is j */
mid = jj = j;
}
else
{
} else {
/* i <-> j */
jj = j;
j -= qsz;
120,12 → 110,9
}
goto swap;
}
if (i == mid)
{
if (i == mid) {
break;
}
else
{
} else {
/* i <-> mid, new mid is i */
jj = mid;
tmp = mid = i; /* value of i after swap */
149,15 → 136,12
* of at least size THRESH.
*/
i = (j = mid) + qsz;
if ((lo = j - base) <= (hi = max - i))
{
if ((lo = j - base) <= (hi = max - i)) {
if (lo >= thresh)
qst(base, j);
base = i;
lo = hi;
}
else
{
} else {
if (hi >= thresh)
qst(i, max);
max = j;
172,8 → 156,7
* It's not...
*/
 
void
qsort(void *base0, size_t n, size_t size, int (*compar)(const void *, const void *))
void qsort(void* base0, size_t n, size_t size, int (*compar)(const void*, const void*))
{
char *base = (char *)base0;
char c, *i, *j, *lo, *hi;
186,13 → 169,10
thresh = qsz * THRESH;
mthresh = qsz * MTHRESH;
max = base + n * qsz;
if (n >= THRESH)
{
if (n >= THRESH) {
qst(base, max);
hi = base + thresh;
}
else
{
} else {
hi = max;
}
/*
204,11 → 184,9
for (j = lo = base; (lo += qsz) < hi; )
if (qcmp(j, lo) > 0)
j = lo;
if (j != base)
{
if (j != base) {
/* swap j into place */
for (i = base, hi = base + qsz; i < hi; )
{
for (i = base, hi = base + qsz; i < hi;) {
c = *j;
*j++ = *i;
*i++ = c;
221,13 → 199,11
* Then, do the standard insertion sort shift on a character at a time
* basis for each element in the frob.
*/
for (min = base; (hi = min += qsz) < max; )
{
for (min = base; (hi = min += qsz) < max;) {
while (qcmp(hi -= qsz, min) > 0)
/* void */;
if ((hi += qsz) != min) {
for (lo = min + qsz; --lo >= min; )
{
for (lo = min + qsz; --lo >= min;) {
c = *lo;
for (i = j = lo; (j -= qsz) >= hi; i = j)
*i = *j;
/programs/develop/ktcc/trunk/libc.obj/source/stdlib/rand.c
1,5 → 1,5
#include <stdint.h>
#include <stdlib.h>
#include <stdint.h>
 
static uint64_t seed;
 
/programs/develop/ktcc/trunk/libc.obj/source/stdlib/realloc.c
1,6 → 1,7
#include <stdlib.h>
#include <sys/ksys.h>
 
void *realloc(void *ptr, size_t newsize) {
void* realloc(void* ptr, size_t newsize)
{
return _ksys_realloc(ptr, newsize);
}
/programs/develop/ktcc/trunk/libc.obj/source/stdlib/strtod.c
1,7 → 1,9
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <math.h>
 
#ifndef unconst
#define unconst(__v, __t) __extension__ ({union { const __t __cp; __t __p; } __q; __q.__cp = __v; __q.__p;})
#endif
 
double strtod(const char *s, char **sret)
{
23,14 → 25,12
if (*s == '+')
s++;
else if (*s == '-')
{
else if (*s == '-') {
sign = -1;
s++;
}
 
while ((*s >= '0') && (*s <= '9'))
{
while ((*s >= '0') && (*s <= '9')) {
flags |= 1;
r *= 10.0;
r += *s - '0';
37,13 → 37,11
s++;
}
 
if (*s == '.')
{
if (*s == '.') {
d = 0.1L;
s++;
while ((*s >= '0') && (*s <= '9'))
{
while ((*s >= '0') && (*s <= '9')) {
flags |= 2;
r += d * (*s - '0');
s++;
51,33 → 49,28
}
}
 
if (flags == 0)
{
if (flags == 0) {
if (sret)
*sret = unconst(s, char *);
return 0;
}
 
if ((*s == 'e') || (*s == 'E'))
{
if ((*s == 'e') || (*s == 'E')) {
s++;
if (*s == '+')
s++;
else if (*s == '-')
{
else if (*s == '-') {
s++;
esign = -1;
}
if ((*s < '0') || (*s > '9'))
{
if ((*s < '0') || (*s > '9')) {
if (sret)
*sret = unconst(s, char *);
return r;
}
 
while ((*s >= '0') && (*s <= '9'))
{
while ((*s >= '0') && (*s <= '9')) {
e *= 10;
e += *s - '0';
s++;
/programs/develop/ktcc/trunk/libc.obj/source/stdlib/strtol.c
1,61 → 1,61
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
 
int getdigit(char ch, int base)
{
if (isdigit(ch)) ch-= '0';
if (isdigit(ch))
ch -= '0';
else if (isalpha(ch) && ch <= 'Z')
ch = 10 + ch - 'A';
else if (isalpha(ch))
ch = 10 + ch - 'a';
else
if (isalpha(ch) && ch <= 'Z') ch = 10 + ch - 'A';
else
if (isalpha(ch)) ch = 10 + ch - 'a';
else
return -1;
if (ch / base != 0) return -1;
if (ch / base != 0)
return -1;
 
return ch;
}
 
 
long int strtol (const char* str, char** endptr, int base)
{
long int res = 0;
int sign = 1;
 
if (base > 36)
{
if (base > 36) {
errno = EINVAL;
goto bye;
}
 
while (isspace(*str)) str++;
while (isspace(*str))
str++;
 
if (*str == '-') { sign = -1; str++; }
else
if (*str == '+') str++;
if (*str == '-') {
sign = -1;
str++;
} else if (*str == '+')
str++;
 
if (base == 0 || base == 16)
{
if (*str == '0' && (str[1] == 'x' || str[1] == 'X'))
{
if (base == 0 || base == 16) {
if (*str == '0' && (str[1] == 'x' || str[1] == 'X')) {
base = 16;
str += 2;
}
}
 
if (base == 0 && *str == '0') base = 8;
if (base == 0 && *str == '0')
base = 8;
 
if (base == 0) base = 10;
if (base == 0)
base = 10;
 
 
int digit;
while ((digit = getdigit(*str, base)) >= 0)
{
while ((digit = getdigit(*str, base)) >= 0) {
res = base * res + digit;
str++;
if (res < 0)
{
if (res < 0) {
errno = ERANGE;
if (sign > 0)
res = LONG_MAX;
70,4 → 70,3
 
return res * sign;
}
 
/programs/develop/ktcc/trunk/libc.obj/source/string/memmove.c
File deleted
\ No newline at end of file
/programs/develop/ktcc/trunk/libc.obj/source/string/memset.c
File deleted
\ No newline at end of file
/programs/develop/ktcc/trunk/libc.obj/source/string/memchr.c
1,24 → 1,20
/* memchr( const void *, int, size_t )
 
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
 
#include <assert.h>
#include "unconst.h"
#include <string.h>
 
void * memchr( const void * s, int c, size_t n )
{
const unsigned char * p = ( const unsigned char * ) s;
 
while ( n-- )
{
if ( *p == ( unsigned char ) c )
{
return ( void * ) p;
}
 
++p;
}
 
int d0;
register void* __res;
if (!n)
return NULL;
__asm__ __volatile__(
"repne\n\t"
"scasb\n\t"
"je 1f\n\t"
"movl $1,%0\n"
"1:\tdecl %0"
: "=D"(__res), "=&c"(d0)
: "a"(c), "0"(s), "1"(n));
return __res;
}
/programs/develop/ktcc/trunk/libc.obj/source/string/memcmp.c
1,26 → 1,15
/* memcmp( const void *, const void *, size_t )
 
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
 
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <assert.h>
#include <string.h>
 
int memcmp( const void * s1, const void * s2, size_t n )
{
const unsigned char * p1 = ( const unsigned char * ) s1;
const unsigned char * p2 = ( const unsigned char * ) s2;
 
while ( n-- )
{
if ( *p1 != *p2 )
{
return *p1 - *p2;
if (n != 0) {
const unsigned char *p1 = s1, *p2 = s2;
do {
if (*p1++ != *p2++)
return (*--p1 - *--p2);
} while (--n != 0);
}
 
++p1;
++p2;
}
 
return 0;
}
}
/programs/develop/ktcc/trunk/libc.obj/source/string/memcpy.c
1,20 → 1,19
/* memcpy( void *, const void *, size_t )
 
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
 
#include <string.h>
 
void * memcpy( void * s1, const void * s2, size_t n )
void* memcpy(void* _dest, const void* _src, size_t _n)
{
char * dest = ( char * ) s1;
const char * src = ( const char * ) s2;
 
while ( n-- )
{
*dest++ = *src++;
}
 
return s1;
int d0, d1, d2;
__asm__ __volatile__(
"rep ; movsl\n\t"
"testb $2,%b4\n\t"
"je 1f\n\t"
"movsw\n"
"1:\ttestb $1,%b4\n\t"
"je 2f\n\t"
"movsb\n"
"2:"
: "=&c"(d0), "=&D"(d1), "=&S"(d2)
: "0"(_n / 4), "q"(_n), "1"((long)_dest), "2"((long)_src)
: "memory");
return (_dest);
}
/programs/develop/ktcc/trunk/libc.obj/source/string/memmove.s
0,0 → 1,34
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
 
.global memmove
 
memmove:
pushl %ebp
movl %esp,%ebp
pushl %esi
pushl %edi
movl 8(%ebp),%edi
movl 12(%ebp),%esi
movl 16(%ebp),%ecx
jecxz memmove.L2
cld
cmpl %esi,%edi
jb memmove.L3
 
std
addl %ecx,%esi
addl %ecx,%edi
decl %esi
decl %edi
memmove.L3:
rep
movsb
 
memmove.L2:
cld
popl %edi
popl %esi
movl 8(%ebp),%eax
leave
ret
 
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/programs/develop/ktcc/trunk/libc.obj/source/string/memset.s
0,0 → 1,51
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
.text
.align 4
.global memset
 
memset:
pushl %ebp
movl %esp,%ebp
pushl %edi
movl 8(%ebp),%edi
movl 12(%ebp),%eax
movl 16(%ebp),%ecx
cld
 
# We will handle memsets of <= 15 bytes one byte at a time.
# This avoids some extra overhead for small memsets, and
# knowing we are setting > 15 bytes eliminates some annoying
# checks in the "long move" case.
cmpl $15,%ecx
jle memset.L3
 
# Otherwise, tile the byte value out into %eax.
# 0x41 -> 0x41414141, etc.
movb %al,%ah
movl %eax,%edx
sall $16,%eax
movw %dx,%ax
jmp memset.L2
 
# Handle any cruft necessary to get %edi long-aligned.
memset.L1: stosb
decl %ecx
memset.L2: testl $3,%edi
jnz memset.L1
 
# Now slam out all of the longs.
movl %ecx,%edx
shrl $2,%ecx
rep
stosl
 
# Finally, handle any trailing cruft. We know the high three bytes
# of %ecx must be zero, so just put the "slop count" in the low byte.
movb %dl,%cl
andb $3,%cl
memset.L3: rep
stosb
popl %edi
movl 8(%ebp),%eax
leave
ret
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/programs/develop/ktcc/trunk/libc.obj/source/string/strcat.c
1,27 → 1,18
/* strcat( char *, const char * )
 
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
 
#include <string.h>
 
char * strcat( char * s1, const char * s2 )
char* strcat(char* s, const char* append)
{
char * rc = s1;
 
if ( *s1 )
{
while ( *++s1 )
{
/* EMPTY */
}
}
 
while ( ( *s1++ = *s2++ ) )
{
/* EMPTY */
}
 
return rc;
int d0, d1, d2, d3;
__asm__ __volatile__(
"repne\n\t"
"scasb\n\t"
"decl %1\n"
"1:\tlodsb\n\t"
"stosb\n\t"
"testb %%al,%%al\n\t"
"jne 1b"
: "=&S"(d0), "=&D"(d1), "=&a"(d2), "=&c"(d3)
: "0"(append), "1"(s), "2"(0), "3"(0xffffffff)
: "memory");
return s;
}
/programs/develop/ktcc/trunk/libc.obj/source/string/strchr.c
1,20 → 1,21
/* strchr( const char *, int )
 
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
 
#include "unconst.h"
#include <string.h>
 
char * strchr( const char * s, int c )
{
do
{
if ( *s == ( char ) c )
{
return ( char * ) s;
}
} while ( *s++ );
 
return NULL;
int d0;
register char* __res;
__asm__ __volatile__(
"movb %%al,%%ah\n"
"1:\tlodsb\n\t"
"cmpb %%ah,%%al\n\t"
"je 2f\n\t"
"testb %%al,%%al\n\t"
"jne 1b\n\t"
"movl $1,%1\n"
"2:\tmovl %1,%0\n\t"
"decl %0"
: "=a"(__res), "=&S"(d0)
: "1"((unsigned)s), "0"(c));
return __res;
}
/programs/develop/ktcc/trunk/libc.obj/source/string/strcmp.c
1,14 → 1,21
/* strcmp( const char *, const char * )
 
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
 
#include <errno.h>
#include <string.h>
#include <sys/ksys.h>
 
int strcmp(const char * s1, const char * s2)
{
return __strcmp(s1, s2);
}
int d0, d1;
register int __res;
__asm__ __volatile__(
"1:\tlodsb\n\t"
"scasb\n\t"
"jne 2f\n\t"
"testb %%al,%%al\n\t"
"jne 1b\n\t"
"xorl %%eax,%%eax\n\t"
"jmp 3f\n"
"2:\tsbbl %%eax,%%eax\n\t"
"orb $1,%%al\n"
"3:"
: "=a"(__res), "=&S"(d0), "=&D"(d1)
: "1"(s1), "2"(s2));
return __res;
}
/programs/develop/ktcc/trunk/libc.obj/source/string/strcoll.c
1,13 → 1,7
/* strcoll( const char *, const char * )
 
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
 
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
 
int strcoll( const char * s1, const char * s2 )
{
/* FIXME: This should access _PDCLIB_lc_collate. */
return strcmp( s1, s2 );
}
/programs/develop/ktcc/trunk/libc.obj/source/string/strcpy.c
1,19 → 1,16
/* strcpy( char *, const char * )
 
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
 
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
 
char * strcpy( char * s1, const char * s2 )
char* strcpy(char* to, const char* from)
{
char * rc = s1;
 
while ( ( *s1++ = *s2++ ) )
{
/* EMPTY */
int d0, d1, d2;
__asm__ __volatile__(
"1:\tlodsb\n\t"
"stosb\n\t"
"testb %%al,%%al\n\t"
"jne 1b"
: "=&S"(d0), "=&D"(d1), "=&a"(d2)
: "0"(from), "1"(to)
: "memory");
return to;
}
 
return rc;
}
/programs/develop/ktcc/trunk/libc.obj/source/string/strcspn.c
1,30 → 1,17
/* strcspn( const char *, const char * )
 
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
 
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
 
size_t strcspn( const char * s1, const char * s2 )
{
size_t len = 0;
const char * p;
const char *p, *spanp;
char c, sc;
 
while ( s1[len] )
{
p = s2;
 
while ( *p )
{
if ( s1[len] == *p++ )
{
return len;
for (p = s1;;) {
c = *p++;
spanp = s2;
do {
if ((sc = *spanp++) == c)
return p - 1 - s1;
} while (sc != 0);
}
}
 
++len;
}
 
return len;
}
/programs/develop/ktcc/trunk/libc.obj/source/string/strdup.c
1,5 → 1,5
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
 
char* strdup(const char *str)
{
/programs/develop/ktcc/trunk/libc.obj/source/string/strerror.c
3,7 → 3,7
#include <string.h>
#include <errno.h>
 
int _errno;
int __errno;
 
char* strerror(int err)
{
10,59 → 10,27
char *msg;
switch(err){
case 0: msg = "No errors"; break;
case EPERM: msg = "Operation not permitted"; break;
case ENOENT: msg = "No such file or directory"; break;
case ESRCH: msg = "No such process"; break;
case EINTR: msg = "Interrupted system call"; break;
case EIO: msg = "Input/output error"; break;
case ENXIO: msg = "Device not configured"; break;
case E2BIG: msg = "Argument list too long"; break;
 
case ENOTSUP: msg = "Function is not supported"; break;
case EUNKNFS: msg = "Unknown file system"; break;
case ENOTFOUND: msg = "File not found"; break;
case EEOF: msg = "End of file"; break;
case EFAULT: msg = "Bad address"; break;
case EDQUOT: msg = "Disc quota exceeded"; break;
case EFS: msg = "File system error"; break;
case EACCES: msg = "Permission denied"; break;
case EDEV: msg = "Device error"; break;
case ENOMEMFS: msg = "File system requires more memory"; break;
 
case ENOMEM: msg = "Not enough memory"; break;
case ENOEXEC: msg = "Exec format error"; break;
case EBADF: msg = "Bad file descriptor"; break;
case ECHILD: msg = "No child processes"; break;
case EDEADLK: msg = "Resource deadlock avoided"; break;
case ENOMEM: msg = "Cannot allocate memory"; break;
case EACCES: msg = "Permission denied"; break;
case EFAULT: msg = "Bad address"; break;
case ENOTBLK: msg = "Block device required"; break;
case EBUSY: msg = "Device / Resource busy"; break;
case EEXIST: msg = "File exists"; break;
case EXDEV: msg = "Cross-device link"; break;
case ENODEV: msg = "Operation not supported by device"; break;
case ENOTDIR: msg = "Not a directory"; break;
case EISDIR: msg = "Is a directory"; break;
case EPROCLIM: msg = "Too many processes"; break;
case EINVAL: msg = "Invalid argument"; break;
case ENFILE: msg = "Too many open files in system"; break;
case EMFILE: msg = "Too many open files"; break;
case ENOTTY: msg = "Inappropriate ioctl for device"; break;
case ETXTBSY: msg = "Text file busy"; break;
case EFBIG: msg = "File too large"; break;
case ENOSPC: msg = "No space left on device"; break;
case ESPIPE: msg = "Illegal seek"; break;
case EROFS: msg = "Read-only file system"; break;
case EMLINK: msg = "Too many links"; break;
case EPIPE: msg = "Broken pipe"; break;
 
// math software
case EDOM: msg = "Numerical argument out of domain"; break;
case ERANGE: msg = "Result too large"; break;
case EILSEQ: msg = "Illegal byte sequence"; break;
 
// should be rearranged
case EHOSTDOWN: msg = "Host is down"; break;
case EHOSTUNREACH: msg = "No route to host"; break;
case ENOTEMPTY: msg = "Directory not empty"; break;
 
// quotas & mush
case EPROCLIM: msg = "Too many processes"; break;
case EUSERS: msg = "Too many users"; break;
case EDQUOT: msg = "Disc quota exceeded"; break;
 
// Intelligent device errors
case EPWROFF: msg = "Device power is off"; break;
case EDEVERR: msg = "Device error, e.g. paper out"; break;
case EOVERFLOW: msg = "Value too large to be stored in data type"; break;
 
// Socket errors
case ENOBUFS: msg = "Broken buffer"; break;
case EINPROGRESS: msg = "Operation now in progress"; break;
case EOPNOTSUPP: msg = "Operation not supported on transport endpoint"; break;
/programs/develop/ktcc/trunk/libc.obj/source/string/strlen.c
1,19 → 1,16
/* strlen( const char * )
 
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
 
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
 
size_t strlen( const char * s )
size_t strlen(const char* str)
{
size_t rc = 0;
 
while ( s[rc] )
{
++rc;
int d0;
register int __res;
__asm__ __volatile__(
"repne\n\t"
"scasb\n\t"
"notl %0\n\t"
"decl %0"
: "=c"(__res), "=&D"(d0)
: "1"(str), "a"(0), "0"(0xffffffff));
return __res;
}
 
return rc;
}
/programs/develop/ktcc/trunk/libc.obj/source/string/strncat.c
1,29 → 1,23
/* strncat( char *, const char *, size_t )
 
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
 
#include <string.h>
 
char * strncat( char * s1, const char * s2, size_t n )
char* strncat(char* dst, const char* src, size_t n)
{
char * rc = s1;
 
while ( *s1 )
{
++s1;
}
 
while ( n && ( *s1++ = *s2++ ) )
{
--n;
}
 
if ( n == 0 )
{
*s1 = '\0';
}
 
return rc;
int d0, d1, d2, d3;
__asm__ __volatile__(
"repne\n\t"
"scasb\n\t"
"decl %1\n\t"
"movl %8,%3\n"
"1:\tdecl %3\n\t"
"js 2f\n\t"
"lodsb\n\t"
"stosb\n\t"
"testb %%al,%%al\n\t"
"jne 1b\n"
"2:\txorl %2,%2\n\t"
"stosb"
: "=&S"(d0), "=&D"(d1), "=&a"(d2), "=&c"(d3)
: "0"(src), "1"(dst), "2"(0), "3"(0xffffffff), "g"(n)
: "memory");
return dst;
}
/programs/develop/ktcc/trunk/libc.obj/source/string/strncmp.c
1,26 → 1,24
/* strncmp( const char *, const char *, size_t )
 
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
 
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
 
int strncmp( const char * s1, const char * s2, size_t n )
{
while ( n && *s1 && ( *s1 == *s2 ) )
{
++s1;
++s2;
--n;
register int __res;
int d0, d1, d2;
__asm__ __volatile__(
"1:\tdecl %3\n\t"
"js 2f\n\t"
"lodsb\n\t"
"scasb\n\t"
"jne 3f\n\t"
"testb %%al,%%al\n\t"
"jne 1b\n"
"2:\txorl %%eax,%%eax\n\t"
"jmp 4f\n"
"3:\tsbbl %%eax,%%eax\n\t"
"orb $1,%%al\n"
"4:"
: "=a"(__res), "=&S"(d0), "=&D"(d1), "=&c"(d2)
: "1"(s1), "2"(s2), "3"(n));
return __res;
}
 
if ( n == 0 )
{
return 0;
}
else
{
return ( *( unsigned char * )s1 - * ( unsigned char * )s2 );
}
}
/programs/develop/ktcc/trunk/libc.obj/source/string/strncpy.c
1,29 → 1,21
/* strncpy( char *, const char *, size_t )
 
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
 
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
 
char * strncpy( char * s1, const char * s2, size_t n )
char* strncpy(char* dst, const char* src, size_t n)
{
char * rc = s1;
 
while ( n && ( *s1++ = *s2++ ) )
{
/* Cannot do "n--" in the conditional as size_t is unsigned and we have
to check it again for >0 in the next loop below, so we must not risk
underflow.
*/
--n;
}
 
/* Checking against 1 as we missed the last --n in the loop above. */
while ( n-- > 1 )
{
*s1++ = '\0';
}
 
return rc;
int d0, d1, d2, d3;
__asm__ __volatile__(
"1:\tdecl %2\n\t"
"js 2f\n\t"
"lodsb\n\t"
"stosb\n\t"
"testb %%al,%%al\n\t"
"jne 1b\n\t"
"rep\n\t"
"stosb\n"
"2:"
: "=&S"(d0), "=&D"(d1), "=&c"(d2), "=&a"(d3)
: "0"(src), "1"(dst), "2"(n)
: "memory");
return dst;
}
/programs/develop/ktcc/trunk/libc.obj/source/string/strpbrk.c
1,30 → 1,16
/* strpbrk( const char *, const char * )
 
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
 
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include "unconst.h"
#include <string.h>
 
char * strpbrk( const char * s1, const char * s2 )
{
const char * p1 = s1;
const char * p2;
const char* scanp;
int c, sc;
 
while ( *p1 )
{
p2 = s2;
 
while ( *p2 )
{
if ( *p1 == *p2++ )
{
return ( char * ) p1;
while ((c = *s1++) != 0) {
for (scanp = s2; (sc = *scanp++) != 0;)
if (sc == c)
return unconst(s1 - 1, char*);
}
return 0;
}
 
++p1;
}
 
return NULL;
}
/programs/develop/ktcc/trunk/libc.obj/source/string/strrchr.c
1,27 → 1,18
/* strrchr( const char *, int )
 
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
 
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include "unconst.h"
#include <string.h>
 
char * strrchr( const char * s, int c )
{
size_t i = 0;
 
while ( s[i++] )
{
/* EMPTY */
char cc = c;
const char* sp = (char*)0;
while (*s) {
if (*s == cc)
sp = s;
s++;
}
 
do
{
if ( s[--i] == ( char ) c )
{
return ( char * ) s + i;
if (cc == 0)
sp = s;
return unconst(sp, char*);
}
} while ( i );
 
return NULL;
}
/programs/develop/ktcc/trunk/libc.obj/source/string/strspn.c
1,37 → 1,15
/* strspn( const char *, const char * )
 
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
 
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
 
size_t strspn( const char * s1, const char * s2 )
{
size_t len = 0;
const char * p;
const char *p = s1, *spanp;
char c, sc;
 
while ( s1[ len ] )
{
p = s2;
 
while ( *p )
{
if ( s1[len] == *p )
{
break;
cont:
c = *p++;
for (spanp = s2; (sc = *spanp++) != 0;)
if (sc == c)
goto cont;
return (p - 1 - s1);
}
 
++p;
}
 
if ( ! *p )
{
return len;
}
 
++len;
}
 
return len;
}
/programs/develop/ktcc/trunk/libc.obj/source/string/strstr.c
1,34 → 1,21
/* strstr( const char *, const char * )
 
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
 
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include "unconst.h"
#include <string.h>
 
char * strstr( const char * s1, const char * s2 )
char* strstr(const char* s, const char* find)
{
const char * p1 = s1;
const char * p2;
char c, sc;
size_t len;
 
while ( *s1 )
{
p2 = s2;
 
while ( *p2 && ( *p1 == *p2 ) )
{
++p1;
++p2;
if ((c = *find++) != 0) {
len = strlen(find);
do {
do {
if ((sc = *s++) == 0)
return 0;
} while (sc != c);
} while (strncmp(s, find, len) != 0);
s--;
}
 
if ( ! *p2 )
{
return ( char * ) s1;
return unconst(s, char*);
}
 
++s1;
p1 = s1;
}
 
return NULL;
}
/programs/develop/ktcc/trunk/libc.obj/source/string/strtok.c
1,30 → 1,49
/* strtok( char *, const char * )
 
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
 
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
 
char* strtok(char* s, const char* delim)
{
static char* savep;
char* res;
const char* spanp;
int c, sc;
char* tok;
static char* last;
 
if(s)
savep = NULL;
else
s = savep;
if (s == NULL && (s = last) == NULL)
return (NULL);
 
if (*s == '\0')
return NULL;
s += strspn(s, delim);
if (*s == '\0')
return NULL;
res = s;
s += strcspn(s, delim);
savep = s + 1;
*s = '\0';
return res;
/*
* Skip (span) leading delimiters (s += strspn(s, delim), sort of).
*/
cont:
c = *s++;
for (spanp = delim; (sc = *spanp++) != 0;) {
if (c == sc)
goto cont;
}
 
if (c == 0) { /* no non-delimiter characters */
last = NULL;
return (NULL);
}
tok = s - 1;
 
/*
* Scan token (scan for delimiters: s += strcspn(s, delim), sort of).
* Note that delim must have one NUL; we stop if we see that, too.
*/
for (;;) {
c = *s++;
spanp = delim;
do {
if ((sc = *spanp++) == c) {
if (c == 0)
s = NULL;
else
s[-1] = 0;
last = s;
return (tok);
}
} while (sc != 0);
}
/* NOTREACHED */
}
/programs/develop/ktcc/trunk/libc.obj/source/string/strxfrm.c
1,26 → 1,22
/* strxfrm( char *, const char *, size_t )
 
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
 
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
 
size_t strxfrm( char * s1, const char * s2, size_t n )
size_t strxfrm(char* dst, const char* src, size_t n)
{
size_t len = strlen( s2 );
size_t r = 0;
int c;
 
if ( len < n )
{
/* Cannot use strncpy() here as the filling of s1 with '\0' is not part
of the spec.
*/
/* FIXME: This should access _PDCLIB_lc_collate. */
while ( n-- && ( *s1++ = ( unsigned char )*s2++ ) )
{
/* EMPTY */
if (n != 0) {
while ((c = *src++) != 0) {
r++;
if (--n == 0) {
while (*src++ != 0)
r++;
break;
}
*dst++ = c;
}
 
return len;
*dst = 0;
}
return r;
}
/programs/develop/ktcc/trunk/libc.obj/source/string/unconst.h
0,0 → 1,8
#ifndef _UNCONST_H_
#define _UNCONST_H_
 
#ifndef unconst
#define unconst(__v, __t) __extension__ ({union { const __t __cp; __t __p; } __q; __q.__cp = __v; __q.__p;})
#endif
 
#endif // _UNCONST_H_
Property changes:
Added: svn:executable
+*
\ No newline at end of property
/programs/develop/ktcc/trunk/libc.obj/source/sys/opendir.c
6,7 → 6,7
#include <stdlib.h>
#include <string.h>
 
#define CHECK_DIR_ERR() if(_ksys_work_files(&inf)){ \
#define CHECK_DIR_ERR() if(_ksys70(&inf).status){ \
free((void*)inf.p16); \
errno = ENOTDIR; \
return NULL; \
/programs/develop/ktcc/trunk/libc.obj/source/time/asctime.c
1,8 → 1,8
#include "stddef.h"
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
 
const char *wday_str[7]={"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
const char *mon_str[12]={"Jan", "Feb", "Mar", "Ap", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
12,9 → 12,10
 
#define TIME_STR_MAX 27
 
char *asctime(const struct tm *tm){
char* asctime(const struct tm* tm)
{
if(!tm){
errno = EINVAL;
__errno = EINVAL;
return NULL;
}
if(tm->tm_wday>6 || tm->tm_wday<0 || tm->tm_mon<0 || tm->tm_mon>11){
27,8 → 28,7
mon_str[tm->tm_mon],
tm->tm_mday, tm->tm_hour,
tm->tm_min, tm->tm_sec,
1900 + tm->tm_year
);
1900 + tm->tm_year);
return time_str;
}
#pragma GCC pop_options
/programs/develop/ktcc/trunk/libc.obj/source/time/localtime.c
1,8 → 1,8
#include <time.h>
#include <sys/ksys.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <sys/ksys.h>
#include <time.h>
 
#define LEAPOCH (946684800LL + 86400*(31+29))
 
33,7 → 33,8
}
 
wday = (3+days)%7;
if (wday < 0) wday += 7;
if (wday < 0)
wday += 7;
 
qc_cycles = days / DAYS_PER_400Y;
remdays = days % DAYS_PER_400Y;
43,20 → 44,24
}
 
c_cycles = remdays / DAYS_PER_100Y;
if (c_cycles == 4) c_cycles--;
if (c_cycles == 4)
c_cycles--;
remdays -= c_cycles * DAYS_PER_100Y;
 
q_cycles = remdays / DAYS_PER_4Y;
if (q_cycles == 25) q_cycles--;
if (q_cycles == 25)
q_cycles--;
remdays -= q_cycles * DAYS_PER_4Y;
 
remyears = remdays / 365;
if (remyears == 4) remyears--;
if (remyears == 4)
remyears--;
remdays -= remyears * 365;
 
leap = !remyears && (q_cycles || !c_cycles);
yday = remdays + 31 + 28 + leap;
if (yday >= 365+leap) yday -= 365+leap;
if (yday >= 365 + leap)
yday -= 365 + leap;
 
years = remyears + 4*q_cycles + 100*c_cycles + 400LL*qc_cycles;
 
104,5 → 109,4
{
static struct tm tm;
return __localtime_r(timer, &tm);
}
}
/programs/develop/ktcc/trunk/libc.obj/source/time/mktime.c
12,7 → 12,8
i = (timeptr->tm_year - 100) / 100;
leaps -= ( (i/4)*3 + i%4 );
tdays = 0;
for (i=0; i < timeptr->tm_mon; i++) tdays += mon_days[i];
for (i = 0; i < timeptr->tm_mon; i++)
tdays += mon_days[i];
tdays += timeptr->tm_mday-1; // days of month passed.
tdays = tdays + (tyears * 365) + leaps;
19,5 → 20,4
 
// utc_hrs = timeptr->tm_hour + utcdiff; // for your time zone.
return (tdays * 86400) + (timeptr->tm_hour * 3600) + (timeptr->tm_min * 60) + timeptr->tm_sec;
}
}
/programs/develop/ktcc/trunk/libc.obj/source/time/time.c
1,7 → 1,8
#include <sys/ksys.h>
#include <time.h>
#include <sys/ksys.h>
 
time_t time(time_t *timer){
time_t time(time_t* timer)
{
static struct tm __buffertime;
int kos_date, kos_time;
kos_date = _ksys_get_date().val;