Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 8786 → Rev 8787

/programs/develop/libraries/kolibri-libc/compile_flags.txt
1,5 → 1,5
-D
_KOLIBRI_LIBC_OBJ
_BUILD_LIBC
-I
include
 
/programs/develop/libraries/kolibri-libc/include/libc_version.h
File deleted
Property changes:
Deleted: svn:keywords
-r
\ No newline at end of property
/programs/develop/libraries/kolibri-libc/include/ctype.h
20,7 → 20,7
#define __UPPER 512
#define __XDIGIT 1024
 
#ifdef _KOLIBRI_LIBC_OBJ
#ifdef _BUILD_LIBC
extern unsigned short __is[129];
#else
extern unsigned short *__is;
/programs/develop/libraries/kolibri-libc/include/errno.h
7,7 → 7,13
extern "C" {
#endif
 
extern int errno;
#ifdef _BUILD_LIBC
extern int _errno;
#define errno _errno
#else
extern int* _errno;
#define errno *_errno
#endif
 
#define EPERM 1 /* Operation not permitted */
#define ENOENT 2 /* No such file or directory */
/programs/develop/libraries/kolibri-libc/include/limits.h
3,6 → 3,7
 
 
#define INT_MAX 2147483647
#define INT_MIN -2147483648
#define UINT_MAX (INT_MAX * 2U + 1)
 
 
/programs/develop/libraries/kolibri-libc/include/stddef.h
26,7 → 26,7
#define NULL ((void*)0)
#endif
 
#ifdef _KOLIBRI_LIBC_OBJ
#ifdef _BUILD_LIBC
#define _FUNC(func) func
#else
#define _FUNC(func) (*func)
/programs/develop/libraries/kolibri-libc/include/sys/socket.h
76,169 → 76,16
}optstruct;
#pragma pack(pop)
 
static inline
void _conv_socket_err(){
switch(errno){
case 1: errno = ENOBUFS; break;
case 2: errno = EINPROGRESS; break;
case 4: errno = EOPNOTSUPP; break;
case 6: errno = EWOULDBLOCK; break;
case 9: errno = ENOTCONN; break;
case 10: errno = EALREADY; break;
case 11: errno = EINVAL; break;
case 12: errno = EMSGSIZE; break;
case 18: errno = ENOMEM; break;
case 20: errno = EADDRINUSE; break;
case 61: errno = ECONNREFUSED; break;
case 52: errno = ECONNRESET; break;
case 56: errno = EISCONN; break;
case 60: errno = ETIMEDOUT; break;
case 54: errno = ECONNABORTED; break;
default: errno = 0; break;
}
}
extern int _FUNC(socket)(int domain, int type, int protocol);
extern int _FUNC(close)(int socket);
extern int _FUNC(bind)(int socket, const struct sockaddr *addres, int addres_len);
extern int _FUNC(listen)(int socket, int backlog);
extern int _FUNC(connect)(int socket, const struct sockaddr* address, int socket_len);
extern int _FUNC(accept)(int socket, const struct sockaddr *address, int address_len);
extern int _FUNC(send)(int socket, const void *message, size_t msg_len, int flag);
extern int _FUNC(recv)(int socket, void *buffer, size_t buff_len, int flag);
extern int _FUNC(setsockopt)(int socket,const optstruct* opt);
extern int _FUNC(getsockopt)(int socket, optstruct* opt);
extern int _FUNC(socketpair)(int *socket1, int *socket2);
 
static inline
int socket(int domain, int type, int protocol)
{
int socket;
asm_inline(
"int $0x40"
:"=b"(errno), "=a"(socket)
:"a"(75), "b"(0), "c"(domain), "d"(type), "S"(protocol)
);
_conv_socket_err();
return socket;
}
 
static inline
int close(int socket)
{
int status;
asm_inline(
"int $0x40"
:"=b"(errno), "=a"(status)
:"a"(75), "b"(1), "c"(socket)
);
_conv_socket_err();
return status;
}
 
static inline
int bind(int socket, const struct sockaddr *addres, int addres_len)
{
int status;
asm_inline(
"int $0x40"
:"=b"(errno), "=a"(status)
:"a"(75), "b"(2), "c"(socket), "d"(addres), "S"(addres_len)
);
_conv_socket_err();
return status;
}
 
static inline
int listen(int socket, int backlog)
{
int status;
asm_inline(
"int $0x40"
:"=b"(errno), "=a"(status)
:"a"(75), "b"(3), "c"(socket), "d"(backlog)
);
_conv_socket_err();
return status;
}
 
static inline
int connect(int socket, const struct sockaddr* address, int socket_len)
{
int status;
asm_inline(
"int $0x40"
:"=b"(errno), "=a"(status)
:"a"(75), "b"(4), "c"(socket), "d"(address), "S"(socket_len)
);
_conv_socket_err();
return status;
}
 
static inline int
accept(int socket, const struct sockaddr *address, int address_len)
{
int new_socket;
asm_inline(
"int $0x40"
:"=b"(errno), "=a"(new_socket)
:"a"(75), "b"(5), "c"(socket), "d"(address), "S"(address_len)
);
_conv_socket_err();
return new_socket;
}
 
static inline
int send(int socket, const void *message, size_t msg_len, int flag)
{
int status;
asm_inline(
"int $0x40"
:"=b"(errno), "=a"(status)
:"a"(75), "b"(6), "c"(socket), "d"(message), "S"(msg_len), "D"(flag)
);
_conv_socket_err();
return status;
}
 
static inline
int recv(int socket, void *buffer, size_t buff_len, int flag)
{
int status;
asm_inline(
"int $0x40"
:"=b"(errno), "=a"(status)
:"a"(75), "b"(7), "c"(socket), "d"(buffer), "S"(buff_len), "D"(flag)
);
_conv_socket_err();
return status;
}
 
static inline
int setsockopt(int socket,const optstruct* opt)
{
int status;
asm_inline(
"int $0x40"
:"=b"(errno), "=a"(status)
:"a"(75), "b"(8), "c"(socket),"d"(opt)
);
_conv_socket_err();
return status;
}
 
static inline
int getsockopt(int socket, optstruct* opt)
{
int status;
asm_inline(
"int $0x40"
:"=b"(errno), "=a"(status)
:"a"(75), "b"(9), "c"(socket),"d"(opt)
);
_conv_socket_err();
return status;
}
 
static inline
int socketpair(int *socket1, int *socket2)
{
asm_inline(
"int $0x40"
:"=b"(*socket2), "=a"(*socket1)
:"a"(75), "b"(10)
);
errno=*socket2;
_conv_socket_err();
return *socket1;
}
 
#endif //_SOCKET_H_
/programs/develop/libraries/kolibri-libc/include/time.h
8,6 → 8,7
#define clock() _ksys_get_clock()
#define CLOCKS_PER_SEC 100
 
#pragma pack(push, 1)
struct tm {
int tm_sec; /* seconds after the minute 0-61*/
int tm_min; /* minutes after the hour 0-59 */
19,12 → 20,12
int tm_yday; /* days since January 1 0-365 */
int tm_isdst; /* Daylight Saving Time flag */
};
#pragma pack(pop)
 
extern time_t _FUNC(mktime)(struct tm * timeptr);
extern time_t _FUNC(time)(time_t* timer);
extern struct tm * _FUNC(localtime)(const time_t * timer); /* non-standard! ignore parameter and return just time now, not generate tm_isdst, tm_yday, tm_wday == -1 */
extern struct tm * _FUNC(localtime)(const time_t * timer);
extern double _FUNC(difftime)(time_t end, time_t beginning);
extern char* _FUNC(asctime)(const struct tm *tm);
 
extern struct tm buffertime;
 
#endif
/programs/develop/libraries/kolibri-libc/lib/libc.obj.a
Cannot display: file marked as a binary type.
svn:mime-type = application/x-archive
/programs/develop/libraries/kolibri-libc/samples/file_io.c
1,6 → 1,7
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
 
#define READ_MAX 255
 
28,6 → 29,7
fputs(test_str1+i,f);
char null_term = '\0';
fwrite(&null_term, sizeof(char), 1, f);
printf("Error: %s\n",strerror(errno));
fclose(f);
 
//copy from testfile.txt to copyfile.txt
/programs/develop/libraries/kolibri-libc/samples/whois.c
13,6 → 13,7
#include <stdlib.h>
#include <sys/socket.h>
#include <clayer/network.h>
#include <conio.h>
 
FILE *out=stdout;
 
61,7 → 62,8
exit(0);
}
if(out==stdout){
con_set_title("Whois");
con_init();
(*con_set_title)("Whois");
}
get_whois_data(domain , &data);
exit(0);
/programs/develop/libraries/kolibri-libc/source/Makefile
5,7 → 5,7
KPACK=kpack
FASM=fasm
 
CFLAGS = -c -nostdinc -I../include -DGNUC -D_KOLIBRI_LIBC_OBJ -Os -fno-common -fno-builtin -fno-leading-underscore -fno-pie
CFLAGS = -c -nostdinc -I../include -DGNUC -D_BUILD_LIBC -fno-common -Os -fno-builtin -fno-leading-underscore -fno-pie
 
SRC=libc.c
LIB=../lib/libc.obj
/programs/develop/libraries/kolibri-libc/source/Tupfile.lua
2,7 → 2,7
HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../../../../" or tup.getconfig("HELPERDIR")
tup.include(HELPERDIR .. "/use_gcc.lua")
 
CFLAGS = " -c -w -nostdinc -DGNUC -D_KOLIBRI_LIBC_OBJ -Os -fno-common -fno-builtin -fno-leading-underscore -fno-pie"
CFLAGS = " -c -w -nostdinc -DGNUC -D_BUILD_LIBC -Os -fno-common -fno-builtin -fno-leading-underscore -fno-pie"
INCLUDES = " -I../include"
 
tup.rule("../linuxtools/src/ExportGen.c", "gcc %f -o %o" , "../linuxtools/ExportGen")
/programs/develop/libraries/kolibri-libc/source/libc.c
1,9 → 1,3
#include <libc_version.h>
 
unsigned _libc_get_version(){
return _LIBC_VERSION;
}
 
#include "ctype/is.c"
#include "ctype/tolower.c"
#include "ctype/toupper.c"
15,6 → 9,7
#include "sys/telldir.c"
#include "sys/closedir.c"
#include "sys/dir.c"
#include "sys/socket.c"
 
#include "stdio/clearerr.c"
#include "stdio/gets.c"
93,11 → 88,8
#include "stdlib/free.c"
#include "stdlib/llabs.c"
#include "stdlib/exit.c"
#include "stdlib/mktime.c"
#include "stdlib/atoi.c"
#include "stdlib/localtime.c"
#include "stdlib/labs.c"
#include "stdlib/difftime.c"
#include "stdlib/realloc.c"
#include "stdlib/ldiv.c"
#include "stdlib/abs.c"
104,7 → 96,6
#include "stdlib/div.c"
#include "stdlib/atol.c"
#include "stdlib/itoa.c"
#include "stdlib/time.c"
#include "stdlib/strtol.c"
#include "stdlib/rand.c"
 
118,6 → 109,12
#include "math/sinh.c"
#include "math/tanh.c"
 
#include "time/difftime.c"
#include "time/localtime.c"
#include "time/mktime.c"
#include "time/time.c"
#include "time/asctime.c"
 
__asm__(
".include \"math/acos.s\"\n\t"
".include \"math/asin.s\"\n\t"
135,6 → 132,7
".include \"math/pow.s\"\n\t"
".include \"math/pow2.s\"\n\t"
".include \"math/pow10.s\"\n\t"
".include \"math/sqrt.s\"\n\t"
);
 
__asm__(
142,5 → 140,6
".include \"setjmp/setjmp.s\""
);
 
#include "libtcc/libtcc1.c"
#include "stdlib/___chkstk_ms.c"
#include "exports/exports.c"
/programs/develop/libraries/kolibri-libc/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/libraries/kolibri-libc/source/stdlib/mktime.c
File deleted
/programs/develop/libraries/kolibri-libc/source/stdlib/difftime.c
File deleted
/programs/develop/libraries/kolibri-libc/source/stdlib/localtime.c
File deleted
/programs/develop/libraries/kolibri-libc/source/stdlib/time.c
File deleted
/programs/develop/libraries/kolibri-libc/source/string/strerror.c
3,7 → 3,7
#include <string.h>
#include <errno.h>
 
int errno;
int _errno;
 
char* strerror(int err)
{
/programs/develop/libraries/kolibri-libc/source/symbols.txt
47,7 → 47,6
atol
atoll
calloc
difftime
div
exit
free
56,20 → 55,17
ldiv
llabs
lldiv
localtime
malloc
mktime
realloc
strtol
time
srand
rand
!____STRING____
memcpy
!memcpy
memchr
memcmp
memmove
memset
!memmove
!memset
strncat
strchr
strcat
89,6 → 85,7
strstr
strtok
strxfrm
_errno
!____SYS____
closedir
opendir
101,6 → 98,17
rmdir
setcwd
getcwd
!____SOCKET____
socket
close
bind
listen
connect
accept
send
recv
setsockopt
socketpair
!____UNISTD____
!____MATH____
acosh
156,5 → 164,9
con_cls
con_get_cursor_pos
con_set_cursor_pos
!___LIBC_VERSION___
_libc_get_version
!____TIME____
mktime
time
localtime
asctime
difftime
/programs/develop/libraries/kolibri-libc/source/sys/socket.c
0,0 → 1,155
#include <sys/socket.h>
 
static void _conv_socket_err(){
switch(errno){
case 1: errno = ENOBUFS; break;
case 2: errno = EINPROGRESS; break;
case 4: errno = EOPNOTSUPP; break;
case 6: errno = EWOULDBLOCK; break;
case 9: errno = ENOTCONN; break;
case 10: errno = EALREADY; break;
case 11: errno = EINVAL; break;
case 12: errno = EMSGSIZE; break;
case 18: errno = ENOMEM; break;
case 20: errno = EADDRINUSE; break;
case 61: errno = ECONNREFUSED; break;
case 52: errno = ECONNRESET; break;
case 56: errno = EISCONN; break;
case 60: errno = ETIMEDOUT; break;
case 54: errno = ECONNABORTED; break;
default: errno = 0; break;
}
}
 
int socket(int domain, int type, int protocol)
{
int socket;
asm_inline(
"int $0x40"
:"=b"(errno), "=a"(socket)
:"a"(75), "b"(0), "c"(domain), "d"(type), "S"(protocol)
);
_conv_socket_err();
return socket;
}
int close(int socket)
{
int status;
asm_inline(
"int $0x40"
:"=b"(errno), "=a"(status)
:"a"(75), "b"(1), "c"(socket)
);
_conv_socket_err();
return status;
}
int bind(int socket, const struct sockaddr *addres, int addres_len)
{
int status;
asm_inline(
"int $0x40"
:"=b"(errno), "=a"(status)
:"a"(75), "b"(2), "c"(socket), "d"(addres), "S"(addres_len)
);
_conv_socket_err();
return status;
}
int listen(int socket, int backlog)
{
int status;
asm_inline(
"int $0x40"
:"=b"(errno), "=a"(status)
:"a"(75), "b"(3), "c"(socket), "d"(backlog)
);
_conv_socket_err();
return status;
}
 
int connect(int socket, const struct sockaddr* address, int socket_len)
{
int status;
asm_inline(
"int $0x40"
:"=b"(errno), "=a"(status)
:"a"(75), "b"(4), "c"(socket), "d"(address), "S"(socket_len)
);
_conv_socket_err();
return status;
}
 
int accept(int socket, const struct sockaddr *address, int address_len)
{
int new_socket;
asm_inline(
"int $0x40"
:"=b"(errno), "=a"(new_socket)
:"a"(75), "b"(5), "c"(socket), "d"(address), "S"(address_len)
);
_conv_socket_err();
return new_socket;
}
 
int send(int socket, const void *message, size_t msg_len, int flag)
{
int status;
asm_inline(
"int $0x40"
:"=b"(errno), "=a"(status)
:"a"(75), "b"(6), "c"(socket), "d"(message), "S"(msg_len), "D"(flag)
);
_conv_socket_err();
return status;
}
int recv(int socket, void *buffer, size_t buff_len, int flag)
{
int status;
asm_inline(
"int $0x40"
:"=b"(errno), "=a"(status)
:"a"(75), "b"(7), "c"(socket), "d"(buffer), "S"(buff_len), "D"(flag)
);
_conv_socket_err();
return status;
}
 
int setsockopt(int socket,const optstruct* opt)
{
int status;
asm_inline(
"int $0x40"
:"=b"(errno), "=a"(status)
:"a"(75), "b"(8), "c"(socket),"d"(opt)
);
_conv_socket_err();
return status;
}
int getsockopt(int socket, optstruct* opt)
{
int status;
asm_inline(
"int $0x40"
:"=b"(errno), "=a"(status)
:"a"(75), "b"(9), "c"(socket),"d"(opt)
);
_conv_socket_err();
return status;
}
 
int socketpair(int *socket1, int *socket2)
{
asm_inline(
"int $0x40"
:"=b"(*socket2), "=a"(*socket1)
:"a"(75), "b"(10)
);
errno=*socket2;
_conv_socket_err();
return *socket1;
}
/programs/develop/libraries/kolibri-libc/source/time/asctime.c
0,0 → 1,27
#include <errno.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"};
 
#pragma GCC push_options
#pragma GCC optimize("O0")
 
char *asctime(const struct tm *tm){
static char time_str[30];
if(tm->tm_wday>7 || tm->tm_wday<1 || tm->tm_mon<1 || tm->tm_mon>12){
errno = EINVAL;
return NULL;
}
snprintf(time_str, 26, "%.3s %.3s%3d %2d:%2d:%2d %d\n",
wday_str[tm->tm_wday-1],
mon_str[tm->tm_mon-1],
tm->tm_mday, tm->tm_hour,
tm->tm_min, tm->tm_sec,
1900 + tm->tm_year
);
return time_str;
}
#pragma GCC pop_options
/programs/develop/libraries/kolibri-libc/source/time/difftime.c
0,0 → 1,6
#include <time.h>
 
double difftime (time_t end, time_t beginning)
{
return end - beginning;
}
/programs/develop/libraries/kolibri-libc/source/time/localtime.c
0,0 → 1,108
#include <time.h>
#include <sys/ksys.h>
#include <ctype.h>
#include <errno.h>
#include <limits.h>
 
#define LEAPOCH (946684800LL + 86400*(31+29))
 
#define DAYS_PER_400Y (365*400 + 97)
#define DAYS_PER_100Y (365*100 + 24)
#define DAYS_PER_4Y (365*4 + 1)
 
static int __secs_to_tm(long long t, struct tm *tm)
{
long long days, secs, years;
int remdays, remsecs, remyears;
int qc_cycles, c_cycles, q_cycles;
int months;
int wday, yday, leap;
static const char days_in_month[] = {31,30,31,30,31,31,30,31,30,31,31,29};
 
// Reject time_t values whose year would overflow int
if (t < INT_MIN * 31622400LL || t > INT_MAX * 31622400LL)
return -1;
secs = t - LEAPOCH;
days = secs / 86400;
remsecs = secs % 86400;
if (remsecs < 0) {
remsecs += 86400;
days--;
}
 
wday = (3+days)%7;
if (wday < 0) wday += 7;
 
qc_cycles = days / DAYS_PER_400Y;
remdays = days % DAYS_PER_400Y;
if (remdays < 0) {
remdays += DAYS_PER_400Y;
qc_cycles--;
}
 
c_cycles = remdays / DAYS_PER_100Y;
if (c_cycles == 4) c_cycles--;
remdays -= c_cycles * DAYS_PER_100Y;
 
q_cycles = remdays / DAYS_PER_4Y;
if (q_cycles == 25) q_cycles--;
remdays -= q_cycles * DAYS_PER_4Y;
 
remyears = remdays / 365;
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;
 
years = remyears + 4*q_cycles + 100*c_cycles + 400LL*qc_cycles;
 
for (months=0; days_in_month[months] <= remdays; months++)
remdays -= days_in_month[months];
 
if (months >= 10) {
months -= 12;
years++;
}
 
if (years+100 > INT_MAX || years+100 < INT_MIN)
return -1;
 
tm->tm_year = years + 100;
tm->tm_mon = months + 2;
tm->tm_mday = remdays + 1;
tm->tm_wday = wday;
tm->tm_yday = yday;
 
tm->tm_hour = remsecs / 3600;
tm->tm_min = remsecs / 60 % 60;
tm->tm_sec = remsecs % 60;
 
return 0;
}
 
struct tm *__localtime_r(const time_t *restrict t, struct tm *restrict tm)
{
// Reject time_t values whose year would overflow int because
// __secs_to_zone cannot safely handle them.
if (*t < INT_MIN * 31622400LL || *t > INT_MAX * 31622400LL) {
errno = EOVERFLOW;
return NULL;
}
//__secs_to_zone(*t, 0, &tm->tm_isdst, &tm->__tm_gmtoff, 0, &tm->__tm_zone);
if (__secs_to_tm((long long)*t,tm) < 0) {
errno = EOVERFLOW;
return NULL;
}
return tm;
}
 
struct tm * localtime (const time_t * timer)
{
static struct tm tm;
return __localtime_r(timer, &tm);
}
/programs/develop/libraries/kolibri-libc/source/time/mktime.c
0,0 → 1,23
#include <time.h>
 
time_t mktime (struct tm * timeptr)
{
int utcdiff = -3;
const int mon_days [] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
unsigned long int tyears, tdays, leaps, utc_hrs;
int i;
tyears = timeptr->tm_year - 70 ;// tm->tm_year is from 1900.
leaps = (tyears + 2) / 4; // no of next two lines until year 2100.
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];
tdays += timeptr->tm_mday-1; // days of month passed.
tdays = tdays + (tyears * 365) + leaps;
 
utc_hrs = timeptr->tm_hour + utcdiff; // for your time zone.
return (tdays * 86400) + (utc_hrs * 3600) + (timeptr->tm_min * 60) + timeptr->tm_sec;
}
/programs/develop/libraries/kolibri-libc/source/time/time.c
0,0 → 1,34
#include <time.h>
#include <sys/ksys.h>
 
static struct tm __buffertime;
 
time_t time(time_t *timer){
int kos_date, kos_time;
kos_date = _ksys_get_date();
kos_time = _ksys_get_clock();
int bcd_day = (kos_date >> 16);
int bcd_mon = ((kos_date & 0xFF00) >> 8);
int bcd_year = (kos_date & 0xFF);
__buffertime.tm_mday = ((bcd_day & 0xF0)>>4)*10 + (bcd_day & 0x0F);
__buffertime.tm_mon = ((bcd_mon & 0xF0)>>4)*10 + (bcd_mon & 0x0F) - 1;
__buffertime.tm_year = ((bcd_year & 0xF0)>>4)*10 + (bcd_year & 0x0F) + 100;
__buffertime.tm_wday = __buffertime.tm_yday = __buffertime.tm_isdst = -1; /* temporary */
int bcd_sec = (kos_time >> 16);
int bcd_min = ((kos_time & 0xFF00) >> 8);
int bcd_hour = (kos_time & 0xFF);
__buffertime.tm_sec = ((bcd_sec & 0xF0)>>4)*10 + (bcd_sec & 0x0F);
__buffertime.tm_min = ((bcd_min & 0xF0)>>4)*10 + (bcd_min & 0x0F);
__buffertime.tm_hour = ((bcd_hour & 0xF0)>>4)*10 + (bcd_hour & 0x0F);
time_t ret = mktime(&__buffertime);
if(timer){
*timer=ret;
}
return ret;
}