forked from KolibriOS/kolibrios
libc testsuite + fixes
git-svn-id: svn://kolibrios.org@6433 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
18
programs/develop/ktcc/trunk/libc/include/assert.h
Normal file
18
programs/develop/ktcc/trunk/libc/include/assert.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef __ASSERT_H
|
||||
|
||||
#ifdef NDEBUG
|
||||
# define assert(a) (void)0
|
||||
#else
|
||||
# define assert(a) ((a) ? (void)0 : __assert_func (__FILE__, __LINE__, #a))
|
||||
#endif
|
||||
|
||||
#ifdef NDEBUG
|
||||
# define TRACE(s) void(0)
|
||||
#else
|
||||
# define TRACE(s) (__trace_func (__FILE__, __LINE__, #s))
|
||||
#endif
|
||||
|
||||
void __assert_func(char*,int,char*);
|
||||
void __trace_func(char*,int,char*);
|
||||
|
||||
#endif
|
@@ -33,3 +33,5 @@ extern unsigned short __is[128];
|
||||
#define isascii(c) (!((c)&(~0x7f)))
|
||||
#define toascii(c) ((c)&0x7f)
|
||||
|
||||
extern unsigned char tolower(unsigned char c);
|
||||
extern unsigned char toupper(unsigned char c);
|
||||
|
@@ -54,4 +54,12 @@
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef NAN
|
||||
# define NAN (__nan__)
|
||||
#endif
|
||||
|
||||
#ifndef INFINITY
|
||||
# define INFINITY (__inf__)
|
||||
#endif
|
||||
|
||||
#endif /* _FLOAT_H_ */
|
||||
|
@@ -166,6 +166,13 @@ extern float lgammaf_r(float, int *);
|
||||
double round (double x);
|
||||
long double roundl (long double x);
|
||||
|
||||
#ifndef NAN
|
||||
# define NAN (__nan__)
|
||||
#endif
|
||||
|
||||
#ifndef INFINITY
|
||||
# define INFINITY (__inf__)
|
||||
#endif
|
||||
|
||||
|
||||
//#endif /* !_POSIX_SOURCE */
|
||||
|
@@ -14,13 +14,16 @@ typedef char *va_list;
|
||||
# define NULL ((void*)0)
|
||||
#endif
|
||||
|
||||
typedef unsigned int fpos_t; // 32bit is not enough! 4Gb limit
|
||||
typedef unsigned int size_t;
|
||||
|
||||
int format_print(char *dest, size_t maxlen,const char *fmt0, va_list argp);
|
||||
|
||||
typedef struct {
|
||||
char* buffer;
|
||||
dword buffersize;
|
||||
dword filesize;
|
||||
dword filepos;
|
||||
dword filesize; // too small
|
||||
dword filepos; // too small
|
||||
char* filename;
|
||||
int mode;
|
||||
} FILE;
|
||||
@@ -33,10 +36,12 @@ typedef struct {
|
||||
#define FILE_OPEN_APPEND 2
|
||||
#define FILE_OPEN_TEXT 4
|
||||
#define FILE_OPEN_PLUS 8
|
||||
#define EOF -1
|
||||
#define EOF (-1)
|
||||
#define BUFSIZ (256)
|
||||
#define FILENAME_MAX (0x400)
|
||||
|
||||
extern FILE* fopen(const char* filename, const char *mode);
|
||||
extern void fclose(FILE* file);
|
||||
extern int fclose(FILE* file);
|
||||
extern int feof(FILE* file);
|
||||
extern int fflush(FILE* file);
|
||||
extern int fgetc(FILE* file);
|
||||
@@ -62,6 +67,7 @@ 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)
|
||||
#define putc(a, b) fputc(a, b)
|
||||
char * fgets (char * str, int num, FILE * stream);
|
||||
int putchar (int ch);
|
||||
int getchar (void);
|
||||
@@ -76,7 +82,29 @@ int scanf ( const char * format, ...);
|
||||
int vsscanf ( const char * s, const char * format, va_list arg );
|
||||
int sscanf ( const char * s, const char * format, ...);
|
||||
int vfscanf ( FILE * stream, const char * format, va_list arg );
|
||||
int fputs ( const char * str, FILE * file );
|
||||
void clearerr ( FILE * stream );
|
||||
int ferror ( FILE * stream );
|
||||
void perror ( const char * str );
|
||||
int vprintf ( const char * format, va_list arg );
|
||||
int vsprintf (char * s, const char * format, va_list arg );
|
||||
int vfprintf ( FILE * stream, const char * format, va_list arg );
|
||||
|
||||
|
||||
extern int errno;
|
||||
/* errors codes from KOS, but minus */
|
||||
#define E_SUCCESS (0)
|
||||
#define E_UNSUPPORTED (-2)
|
||||
#define E_UNKNOWNFS (-3)
|
||||
#define E_NOTFOUND (-5)
|
||||
#define E_EOF (-6)
|
||||
#define E_INVALIDPTR (-7)
|
||||
#define E_DISKFULL (-8)
|
||||
#define E_FSYSERROR (-9)
|
||||
#define E_ACCESS (-10)
|
||||
#define E_HARDWARE (-11)
|
||||
#define E_NOMEM (-12)
|
||||
/* conversion errors */
|
||||
#define ERANGE (-20)
|
||||
#define EINVAL (-21)
|
||||
|
||||
#endif
|
||||
|
@@ -3,14 +3,15 @@
|
||||
#include "kolibrisys.h"
|
||||
|
||||
#define RAND_MAX 65535
|
||||
#ifndef NULL
|
||||
# define NULL ((void*)0)
|
||||
#endif
|
||||
|
||||
//#define isspace(c) ((c)==' ')
|
||||
#define abs(i) (((i)<0)?(-(i)):(i))
|
||||
#define labs(li) abs(li)
|
||||
|
||||
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 char *itoab(int n,char* s,int b);
|
||||
extern char *itoa(int n,char* s);
|
||||
|
||||
@@ -25,6 +26,20 @@ double strtod (const char* str, char** endptr);
|
||||
long double strtold (const char* str, char** endptr);
|
||||
float strtof (const char* str, char** endptr);
|
||||
|
||||
void* calloc (size_t num, size_t size);
|
||||
|
||||
#define exit(a) _ksys_exit()
|
||||
#endif
|
||||
#define abort() exit(-1)
|
||||
|
||||
typedef struct {
|
||||
int quot;
|
||||
int rem;
|
||||
} div_t;
|
||||
|
||||
typedef div_t ldiv_t;
|
||||
|
||||
div_t div (int numer, int denom);
|
||||
#define ldiv(a, b) div(a, b)
|
||||
#define atol(a) atoi(a)
|
||||
|
||||
#endif
|
||||
|
@@ -1,26 +1,35 @@
|
||||
#ifndef string_h
|
||||
#define string_h
|
||||
extern void* memchr(const void*,int,int);
|
||||
extern int memcmp(const void*,const void*,int);
|
||||
extern void* memcpy(void*,const void*,int);
|
||||
extern void* memmove(void*,const void*,int);
|
||||
extern void* memset(void*,int,int);
|
||||
typedef unsigned int size_t;
|
||||
|
||||
|
||||
extern void* memchr(const void*,int,size_t);
|
||||
extern int memcmp(const void*,const void*,size_t);
|
||||
extern void* memcpy(void*,const void*,size_t);
|
||||
extern void* memmove(void*,const void*,size_t);
|
||||
extern void* memset(void*,int,size_t);
|
||||
extern char* strcat(char*,const char*);
|
||||
extern char* strchr(const char*,int);
|
||||
extern int strcmp(const char*,const char*);
|
||||
extern int strcoll(const char*,const char*);
|
||||
extern char* strcpy(char*,const char*);
|
||||
extern int strcspn(const char*,const char*);
|
||||
extern size_t strcspn(const char*,const char*);
|
||||
extern int strlen(const char*);
|
||||
extern char* strncat(char*,const char*,int);
|
||||
extern int strncmp(const char*,const char*,int);
|
||||
extern char* strncpy(char*,const char*,int);
|
||||
extern char* strncat(char*,const char*,size_t);
|
||||
extern int strncmp(const char*,const char*,size_t);
|
||||
extern char* strncpy(char*,const char*,size_t);
|
||||
extern char* strpbrk(const char*,const char*);
|
||||
extern char* strrchr(const char*,int);
|
||||
extern int strspn(const char*,const char*);
|
||||
extern size_t strspn(const char*,const char*);
|
||||
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);
|
||||
char * strerror ( int errnum );
|
||||
|
||||
#ifndef NULL
|
||||
# define NULL ((void*)0)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@@ -8,31 +8,31 @@ public realloc
|
||||
|
||||
align 4
|
||||
malloc:
|
||||
|
||||
push ebx
|
||||
mov eax,68
|
||||
mov ebx,12
|
||||
mov ecx,[esp+4] ;size
|
||||
mov ecx,[esp+8] ;size
|
||||
int 0x40
|
||||
|
||||
pop ebx
|
||||
ret 4
|
||||
|
||||
align 4
|
||||
free:
|
||||
|
||||
push ebx
|
||||
mov eax,68
|
||||
mov ebx,13
|
||||
mov ecx,[esp+4]
|
||||
mov ecx,[esp+8]
|
||||
int 0x40
|
||||
|
||||
pop ebx
|
||||
ret 4
|
||||
|
||||
align 4
|
||||
realloc:
|
||||
|
||||
push ebx
|
||||
mov ebx,20
|
||||
mov eax,68
|
||||
mov edx,[esp+4] ; pointer
|
||||
mov ecx,[esp+8] ; size
|
||||
mov edx,[esp+8] ; pointer
|
||||
mov ecx,[esp+12] ; size
|
||||
int 0x40
|
||||
|
||||
pop ebx
|
||||
ret 8
|
||||
|
22
programs/develop/ktcc/trunk/libc/stdio/clearerr.c
Normal file
22
programs/develop/ktcc/trunk/libc/stdio/clearerr.c
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
void clearerr ( FILE * stream )
|
||||
{
|
||||
errno = 0;
|
||||
}
|
||||
|
||||
int ferror ( FILE * stream )
|
||||
{
|
||||
return errno;
|
||||
}
|
||||
|
||||
void perror ( const char * str )
|
||||
{
|
||||
char *msg = strerror(errno);
|
||||
|
||||
if (str)
|
||||
fprintf(stderr, "%s:%s\n", str, msg);
|
||||
else
|
||||
fprintf(stderr, "%s\n", msg);
|
||||
}
|
@@ -2,8 +2,17 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void fclose(FILE* file)
|
||||
int fclose(FILE* file)
|
||||
{
|
||||
free(file->buffer);
|
||||
if(!file)
|
||||
{
|
||||
errno = E_INVALIDPTR;
|
||||
return EOF;
|
||||
}
|
||||
|
||||
if(file->buffer)
|
||||
free(file->buffer);
|
||||
free(file);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -1,5 +1,11 @@
|
||||
#include <stdio.h>
|
||||
int feof(FILE* file)
|
||||
{
|
||||
return file->filepos>=file->filesize;
|
||||
}
|
||||
if(!file)
|
||||
{
|
||||
errno = E_INVALIDPTR;
|
||||
return EOF;
|
||||
}
|
||||
|
||||
return file->filepos>=file->filesize;
|
||||
}
|
||||
|
@@ -1,7 +1,9 @@
|
||||
#include <stdio.h>
|
||||
int fflush(FILE* file)
|
||||
// file can be zero, as flush all
|
||||
{
|
||||
if ((file->mode & 3)==FILE_OPEN_READ)
|
||||
if (file && (file->mode & 3)==FILE_OPEN_READ)
|
||||
return 0;
|
||||
return(EOF);
|
||||
}
|
||||
|
||||
return(0); // always good, as no write buffering
|
||||
}
|
||||
|
@@ -2,6 +2,11 @@
|
||||
int fgetc(FILE* file)
|
||||
{
|
||||
dword res;
|
||||
if(!file)
|
||||
{
|
||||
errno = E_INVALIDPTR;
|
||||
return EOF;
|
||||
}
|
||||
|
||||
if ((file->mode & 3!=FILE_OPEN_READ) && (file->mode & FILE_OPEN_PLUS==0)) return EOF;
|
||||
|
||||
@@ -17,6 +22,10 @@ int fgetc(FILE* file)
|
||||
file->filepos++;
|
||||
return (int)file->buffer[0];
|
||||
}
|
||||
else return(res);
|
||||
else
|
||||
{
|
||||
errno = -res;
|
||||
return EOF; // errors are < 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,12 @@
|
||||
#include <stdio.h>
|
||||
int fgetpos(FILE* file,fpos_t* pos)
|
||||
{
|
||||
if(!file || !pos)
|
||||
{
|
||||
errno = E_INVALIDPTR;
|
||||
return EOF;
|
||||
}
|
||||
|
||||
*pos=file->filepos;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@@ -1,12 +1,21 @@
|
||||
#include <stdio.h>
|
||||
|
||||
char * fgets ( char * str, int num, FILE * stream )
|
||||
char * fgets ( char * str, int num, FILE * file )
|
||||
// need to ignore \r\n in text mode
|
||||
{
|
||||
int rd = 0;
|
||||
char c;
|
||||
while (rd < num - 1)
|
||||
|
||||
if(!file || !str)
|
||||
{
|
||||
errno = E_INVALIDPTR;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
while (rd < num - 1)
|
||||
{
|
||||
c = fgetc(stream);
|
||||
c = fgetc(file);
|
||||
if (EOF == c) break;
|
||||
if ('\n' == c)
|
||||
{
|
||||
@@ -17,8 +26,8 @@ char * fgets ( char * str, int num, FILE * stream )
|
||||
str[rd++] = c;
|
||||
}
|
||||
if (0 == rd) return NULL;
|
||||
else
|
||||
{
|
||||
else
|
||||
{
|
||||
str[rd] = '\0';
|
||||
return str;
|
||||
}
|
||||
|
@@ -5,6 +5,9 @@
|
||||
extern char __argv;
|
||||
extern char __path;
|
||||
|
||||
int errno = 0;
|
||||
|
||||
|
||||
const char* getfullpath(const char *path){
|
||||
|
||||
int i,j,relpath_pos,localpath_size;
|
||||
@@ -39,14 +42,20 @@ const char* getfullpath(const char *path){
|
||||
|
||||
if (local_path==1)
|
||||
{
|
||||
i=0x400;
|
||||
i=FILENAME_MAX;
|
||||
//find local path of program
|
||||
while(*(programpath+i)!='/')
|
||||
{
|
||||
i--;
|
||||
}
|
||||
localpath_size=i;
|
||||
newpath=malloc(0x400);
|
||||
newpath=malloc(FILENAME_MAX);
|
||||
if(!newpath)
|
||||
{
|
||||
errno = E_NOMEM;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
//copy local path to the new path
|
||||
for(i=0;i<=localpath_size;i++)
|
||||
{
|
||||
@@ -61,7 +70,7 @@ const char* getfullpath(const char *path){
|
||||
}
|
||||
|
||||
//if we here than path is a relative
|
||||
i=0x400;
|
||||
i=FILENAME_MAX;
|
||||
//find local path of program
|
||||
while(*(programpath+i)!='/')
|
||||
{
|
||||
@@ -75,7 +84,12 @@ const char* getfullpath(const char *path){
|
||||
i++;
|
||||
}
|
||||
filename_size=i;
|
||||
newpath=malloc(0x400);
|
||||
newpath=malloc(FILENAME_MAX);
|
||||
if(!newpath)
|
||||
{
|
||||
errno = E_NOMEM;
|
||||
return NULL;
|
||||
}
|
||||
//copy local path to the new path
|
||||
for(i=0;i<=localpath_size;i++)
|
||||
{
|
||||
@@ -109,6 +123,11 @@ FILE* fopen(const char* filename, const char *mode)
|
||||
mode++;
|
||||
}else
|
||||
return 0;
|
||||
if (*mode=='+')
|
||||
{
|
||||
imode|=FILE_OPEN_PLUS;
|
||||
mode++;
|
||||
}
|
||||
if (*mode=='t')
|
||||
{
|
||||
imode|=FILE_OPEN_TEXT;
|
||||
@@ -121,14 +140,22 @@ FILE* fopen(const char* filename, const char *mode)
|
||||
mode++;
|
||||
}
|
||||
if (*mode!=0)
|
||||
return 0;
|
||||
return NULL;
|
||||
res=malloc(sizeof(FILE));
|
||||
res->buffer=malloc(256);
|
||||
res->buffersize=256;
|
||||
res->filesize=0;
|
||||
res->filepos=0;
|
||||
res->mode=imode;
|
||||
res->filename=(char*)getfullpath(filename);
|
||||
if (res)
|
||||
{
|
||||
res->buffer=malloc(BUFSIZ);
|
||||
res->buffersize=BUFSIZ;
|
||||
res->filesize=0;
|
||||
res->filepos=0;
|
||||
res->mode=imode;
|
||||
res->filename=(char*)getfullpath(filename);
|
||||
}
|
||||
if(!res || !res->buffer || !res->filename)
|
||||
{
|
||||
errno = E_NOMEM;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((imode==FILE_OPEN_READ) || (imode==FILE_OPEN_APPEND))
|
||||
{
|
||||
|
@@ -77,7 +77,7 @@ int copy_and_align(char *dest, int width, char *src, int src_len, char sign, int
|
||||
int rc = 0, sign_len;
|
||||
char fill;
|
||||
|
||||
fill = (flags & flag_lead_zeros) ? '0' : ' ';
|
||||
fill = (flags & flag_lead_zeros)&&((flags & flag_left_just)==0) ? '0' : ' ';
|
||||
if(sign == 'x' || sign == 'X')
|
||||
{
|
||||
sign_len = 2;
|
||||
@@ -160,7 +160,7 @@ int formatted_double_to_string_scientific(long double number, int format1, int f
|
||||
if (flags & flag_space_plus) sign = ' ';
|
||||
}
|
||||
// normalize
|
||||
while (norm_digit < 1.0) { norm_digit *= 10; mul--; }
|
||||
while (norm_digit < 1.0 && norm_digit > 0) { norm_digit *= 10; mul--; }
|
||||
while (norm_digit >= 10.0) { norm_digit /= 10; mul++; }
|
||||
|
||||
len = formatted_double_to_string(norm_digit, 0, format2, buf, flags & ~(flag_plus | flag_space_plus));
|
||||
@@ -612,7 +612,10 @@ int format_print(char *dest, size_t maxlen, const char *fmt0, va_list argp)
|
||||
//prec special case, this is just workaround
|
||||
if (flag_long <= 1) doubledigit = va_arg(argp, double); else
|
||||
if (flag_long == 2) doubledigit = va_arg(argp, long double);
|
||||
length = formatted_double_to_string(doubledigit, fmt1, fmt2, buf, flags);
|
||||
if (flags & flag_point)
|
||||
length = formatted_double_to_string(doubledigit, fmt1, fmt2, buf, flags);
|
||||
else
|
||||
length = formatted_double_to_string(doubledigit, fmt1, 1, buf, flags | flag_point);
|
||||
i = formatted_double_to_string_scientific(doubledigit, fmt1, fmt2, buf + sizeof buf / 2, flags);
|
||||
if(length > i)
|
||||
{
|
||||
|
@@ -336,11 +336,7 @@ int format_scan(const void *src, const char *fmt, va_list argp, virtual_getc vge
|
||||
else
|
||||
fmt2 = fmt2 * 10 + (*fmt -'0');
|
||||
break;
|
||||
case '*':
|
||||
if (flag_point == 0)
|
||||
fmt1 = va_arg(argp, int);
|
||||
else
|
||||
fmt2 = va_arg(argp, int);
|
||||
case '*': // ignoring
|
||||
break;
|
||||
case '.':
|
||||
flags |= flag_point;
|
||||
|
@@ -1,23 +1,44 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
|
||||
int fprintf(FILE* file, const char* format, ...)
|
||||
{
|
||||
va_list arg;
|
||||
char *buf;
|
||||
int printed;
|
||||
//int data[4];
|
||||
|
||||
va_start (arg, format);
|
||||
buf=malloc(4096*2); //8kb max
|
||||
//data[0]=(int)&arg-(int)&format;
|
||||
va_list arg;
|
||||
va_start (arg, format);
|
||||
|
||||
return vfprintf(file, format, arg);
|
||||
|
||||
}
|
||||
|
||||
int vfprintf ( FILE * file, const char * format, va_list arg )
|
||||
{
|
||||
char *buf;
|
||||
int printed, rc = 0;
|
||||
|
||||
if(!file || !format)
|
||||
{
|
||||
errno = E_INVALIDPTR;
|
||||
return errno;
|
||||
}
|
||||
|
||||
buf=malloc(4096*2); //8kb max
|
||||
if(!buf)
|
||||
{
|
||||
errno = E_NOMEM;
|
||||
return errno;
|
||||
}
|
||||
|
||||
printed=format_print(buf,8191, format,arg);
|
||||
if (file == stderr)
|
||||
debug_out_str(buf);
|
||||
else
|
||||
fwrite(buf,printed,1,file);
|
||||
rc = fwrite(buf,printed,1,file);
|
||||
free(buf);
|
||||
|
||||
return(printed);
|
||||
if (rc < 0)
|
||||
return rc;
|
||||
else
|
||||
return(printed);
|
||||
}
|
||||
|
@@ -2,8 +2,17 @@
|
||||
int fputc(int c,FILE* file)
|
||||
{
|
||||
dword res;
|
||||
if(!file)
|
||||
{
|
||||
errno = E_INVALIDPTR;
|
||||
return EOF;
|
||||
}
|
||||
|
||||
if ((file->mode & 3)==FILE_OPEN_READ) return EOF;
|
||||
if ((file->mode & 3)==FILE_OPEN_READ)
|
||||
{
|
||||
errno = E_ACCESS;
|
||||
return EOF;
|
||||
}
|
||||
|
||||
file->buffer[0]=c;
|
||||
if ((file->mode & 3)==FILE_OPEN_APPEND)
|
||||
@@ -11,25 +20,37 @@ int fputc(int c,FILE* file)
|
||||
file->filepos=file->filesize;
|
||||
file->filesize++;
|
||||
res=_ksys_appendtofile(file->filename,file->filepos,1,file->buffer);
|
||||
if (res!=0) return(res);
|
||||
if (res!=0)
|
||||
{
|
||||
errno = -res;
|
||||
return EOF;
|
||||
}
|
||||
file->filepos++;
|
||||
return(0);
|
||||
return c;
|
||||
}
|
||||
if ((file->mode & 3)==FILE_OPEN_WRITE)
|
||||
{
|
||||
if (file->filepos==0)
|
||||
{ //file not craeted
|
||||
{ //file not created
|
||||
res=_ksys_rewritefile(file->filename,1,file->buffer);
|
||||
if (res!=0) return(res);
|
||||
if (res!=0)
|
||||
{
|
||||
errno = -res;
|
||||
return EOF;
|
||||
}
|
||||
file->filepos++;
|
||||
return 0;
|
||||
return c;
|
||||
}
|
||||
else
|
||||
{ //file craeted and need append one byte
|
||||
{ //file created and need append one byte
|
||||
res=_ksys_appendtofile(file->filename,file->filepos,1,file->buffer);
|
||||
if (res!=0) return(res);
|
||||
if (res!=0)
|
||||
{
|
||||
errno = -res;
|
||||
return EOF;
|
||||
}
|
||||
file->filepos++;
|
||||
return 0;
|
||||
return c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
27
programs/develop/ktcc/trunk/libc/stdio/fputs.c
Normal file
27
programs/develop/ktcc/trunk/libc/stdio/fputs.c
Normal file
@@ -0,0 +1,27 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int fputs ( const char * str, FILE * file )
|
||||
{
|
||||
int rc;
|
||||
|
||||
if(!file || !str)
|
||||
{
|
||||
errno = E_INVALIDPTR;
|
||||
return EOF;
|
||||
}
|
||||
|
||||
if ((file->mode & 3)==FILE_OPEN_READ)
|
||||
{
|
||||
errno = E_ACCESS;
|
||||
return EOF;
|
||||
}
|
||||
|
||||
while(*str)
|
||||
{
|
||||
rc = fputc(*str, file);
|
||||
if (rc < 0) return rc;
|
||||
str++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@@ -6,10 +6,20 @@ int fread(void *buffer,int size,int count,FILE* file)
|
||||
dword res;
|
||||
dword fullsize;
|
||||
|
||||
if ((file->mode!=FILE_OPEN_READ) || (file->mode==FILE_OPEN_PLUS)) return 0;
|
||||
if(!file || !buffer)
|
||||
{
|
||||
errno = E_INVALIDPTR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((file->mode &3)!=FILE_OPEN_READ && (file->mode & FILE_OPEN_PLUS==0))
|
||||
{
|
||||
errno = E_ACCESS;
|
||||
return 0;
|
||||
}
|
||||
|
||||
fullsize=count*size;
|
||||
if ((fullsize+file->filepos)>(file->filesize))
|
||||
if ((fullsize+file->filepos)>=(file->filesize))
|
||||
{
|
||||
fullsize=file->filesize-file->filepos;
|
||||
if (fullsize<=0) return(0);
|
||||
@@ -17,10 +27,14 @@ int fread(void *buffer,int size,int count,FILE* file)
|
||||
|
||||
res=_ksys_readfile(file->filename,file->filepos,fullsize,buffer);
|
||||
if (res==0)
|
||||
{
|
||||
{
|
||||
file->filepos=file->filepos+fullsize;
|
||||
fullsize=fullsize/size;
|
||||
return(fullsize);
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
errno = -res;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@@ -2,6 +2,12 @@
|
||||
int fseek(FILE* file,long offset,int origin)
|
||||
{
|
||||
fpos_t pos;
|
||||
if(!file)
|
||||
{
|
||||
errno = E_INVALIDPTR;
|
||||
return errno;
|
||||
}
|
||||
|
||||
if (origin==SEEK_CUR)
|
||||
offset+=file->filepos;
|
||||
else if (origin==SEEK_END)
|
||||
@@ -9,5 +15,5 @@ int fseek(FILE* file,long offset,int origin)
|
||||
else if (origin!=SEEK_SET)
|
||||
return EOF;
|
||||
pos = offset;
|
||||
return fsetpos(file, &pos);
|
||||
}
|
||||
return fsetpos(file, &pos);
|
||||
}
|
||||
|
@@ -1,6 +1,12 @@
|
||||
#include <stdio.h>
|
||||
int fsetpos(FILE* file,const fpos_t * pos)
|
||||
{
|
||||
if(!file || !pos)
|
||||
{
|
||||
errno = E_INVALIDPTR;
|
||||
return errno;
|
||||
}
|
||||
|
||||
if (*pos>=0)
|
||||
{
|
||||
file->filepos=*pos;
|
||||
@@ -8,4 +14,4 @@ int fsetpos(FILE* file,const fpos_t * pos)
|
||||
}
|
||||
else
|
||||
return EOF;
|
||||
}
|
||||
}
|
||||
|
@@ -1,5 +1,11 @@
|
||||
#include <stdio.h>
|
||||
long ftell(FILE* file)
|
||||
{
|
||||
if(!file)
|
||||
{
|
||||
errno = E_INVALIDPTR;
|
||||
return -1L;
|
||||
}
|
||||
|
||||
return file->filepos;
|
||||
}
|
||||
}
|
||||
|
@@ -6,12 +6,24 @@ int fwrite(void *buffer,int size,int count,FILE* file)
|
||||
dword res;
|
||||
dword fullsize;
|
||||
|
||||
if (file->mode==FILE_OPEN_READ) return 0;
|
||||
if(!file || !buffer)
|
||||
{
|
||||
errno = E_INVALIDPTR;
|
||||
return EOF;
|
||||
}
|
||||
|
||||
if (file->mode==FILE_OPEN_APPEND)
|
||||
|
||||
if ((file->mode & 3)==FILE_OPEN_READ)
|
||||
{
|
||||
errno = E_ACCESS;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ((file->mode &3)==FILE_OPEN_APPEND)
|
||||
file->filepos=file->filesize;
|
||||
fullsize=count*size;
|
||||
|
||||
|
||||
fullsize=count*size;
|
||||
|
||||
if ((file->filesize)<(file->filepos+fullsize)) file->filesize=file->filepos+fullsize;
|
||||
|
||||
/*
|
||||
@@ -26,33 +38,39 @@ int fwrite(void *buffer,int size,int count,FILE* file)
|
||||
return(fullsize);
|
||||
}
|
||||
else return(0);
|
||||
|
||||
|
||||
}
|
||||
*/
|
||||
if ((file->mode==FILE_OPEN_WRITE) || (file->mode==FILE_OPEN_APPEND))
|
||||
if ((file->mode &3)==FILE_OPEN_WRITE || (file->mode&3)==FILE_OPEN_APPEND) // always true, as read checked previous
|
||||
{
|
||||
if (file->filepos==0)
|
||||
{ //file mot craeted yet
|
||||
{ //file mot created yet
|
||||
res=_ksys_rewritefile(file->filename,fullsize,buffer);
|
||||
if (res==0)
|
||||
{
|
||||
file->filepos+=fullsize;
|
||||
fullsize=fullsize/count;
|
||||
return(fullsize);
|
||||
}
|
||||
else return(0);
|
||||
} else
|
||||
{
|
||||
errno = -res;
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
res=_ksys_appendtofile(file->filename,file->filepos,fullsize,buffer);
|
||||
{
|
||||
res=_ksys_appendtofile(file->filename,file->filepos,fullsize,buffer);
|
||||
if (res==0)
|
||||
{
|
||||
file->filepos+=fullsize;
|
||||
fullsize=fullsize/count;
|
||||
return(fullsize);
|
||||
}
|
||||
else return(0);
|
||||
} else
|
||||
{
|
||||
errno = -res;
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
else return(0);
|
||||
}
|
||||
}
|
||||
|
@@ -1,25 +1,32 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <conio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
int printf(const char *format, ...)
|
||||
{
|
||||
va_list arg;
|
||||
va_start(arg, format);
|
||||
|
||||
return vprintf(format, arg);
|
||||
}
|
||||
|
||||
|
||||
int vprintf ( const char * format, va_list arg )
|
||||
{
|
||||
int i = 0;
|
||||
int printed_simbols = 0;
|
||||
va_list arg;
|
||||
char *s;
|
||||
|
||||
va_start(arg,format);
|
||||
|
||||
i=con_init_console_dll();
|
||||
|
||||
if (i==0)
|
||||
if (i == 0)
|
||||
{
|
||||
s=malloc(4096);
|
||||
printed_simbols=format_print(s,4096,format,arg);
|
||||
s = malloc(4096);
|
||||
printed_simbols = format_print(s, 4096, format, arg);
|
||||
con_write_string(s, printed_simbols);
|
||||
free(s);
|
||||
}
|
||||
|
||||
return(printed_simbols);
|
||||
}
|
||||
|
||||
|
@@ -1,5 +1,11 @@
|
||||
#include <stdio.h>
|
||||
void rewind(FILE* file)
|
||||
{
|
||||
if(!file)
|
||||
{
|
||||
errno = E_INVALIDPTR;
|
||||
return;
|
||||
}
|
||||
|
||||
file->filepos=0;
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#include <kolibrisys.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
@@ -4,13 +4,24 @@ int ungetc(int c,FILE* file)
|
||||
{
|
||||
dword res;
|
||||
|
||||
if ((file->mode & 3!=FILE_OPEN_READ) && (file->mode & FILE_OPEN_PLUS==0)) return EOF;
|
||||
if(!file)
|
||||
{
|
||||
errno = E_INVALIDPTR;
|
||||
return EOF;
|
||||
}
|
||||
|
||||
if ((file->mode & 3!=FILE_OPEN_READ) && (file->mode & FILE_OPEN_PLUS==0))
|
||||
{
|
||||
errno = E_ACCESS;
|
||||
return EOF;
|
||||
}
|
||||
|
||||
if (file->filepos>file->filesize || file->filepos==0)
|
||||
{
|
||||
errno = E_EOF;
|
||||
return EOF;
|
||||
}
|
||||
file->filepos--;
|
||||
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
@@ -2,14 +2,13 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int format_print(char *dest, size_t maxlen, const char *fmt,
|
||||
va_list argp);
|
||||
|
||||
|
||||
int vsnprintf(char *dest, size_t size,const char *format,va_list ap)
|
||||
int vsnprintf(char *dest, size_t size, const char *format, va_list ap)
|
||||
{
|
||||
|
||||
return format_print(dest,size, format, ap);
|
||||
}
|
||||
|
||||
|
||||
int vsprintf (char * dest, const char * format, va_list ap )
|
||||
{
|
||||
return format_print(dest, 4096, format, ap);
|
||||
}
|
||||
|
21
programs/develop/ktcc/trunk/libc/stdlib/assert.c
Normal file
21
programs/develop/ktcc/trunk/libc/stdlib/assert.c
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <kolibrisys.h>
|
||||
|
||||
|
||||
void __assert_func (char *file, int line, char *ass)
|
||||
{
|
||||
char buf[100];
|
||||
|
||||
snprintf(buf,100,"Assertion failed: %s, file %s, line %d\n", ass, file, line);
|
||||
debug_out_str(buf);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
void __trace_func (char *file, int line, char *msg)
|
||||
{
|
||||
char buf[100];
|
||||
snprintf(buf,100,"Trace: %s, file %s, line %d\n", msg, file, line);
|
||||
debug_out_str(buf);
|
||||
}
|
10
programs/develop/ktcc/trunk/libc/stdlib/div.c
Normal file
10
programs/develop/ktcc/trunk/libc/stdlib/div.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
div_t div (int numer, int denom)
|
||||
{
|
||||
div_t res;
|
||||
res.quot = numer / denom;
|
||||
res.rem = numer % denom;
|
||||
|
||||
return res;
|
||||
}
|
@@ -1,3 +1,4 @@
|
||||
#include <stdlib.h>
|
||||
/*
|
||||
** return lower-case of c if upper-case, else c
|
||||
*/
|
||||
|
@@ -1,3 +1,4 @@
|
||||
#include <stdlib.h>
|
||||
/*
|
||||
** return upper-case of c if it is lower-case, else c
|
||||
*/
|
||||
|
13
programs/develop/ktcc/trunk/libc/string/calloc.c
Normal file
13
programs/develop/ktcc/trunk/libc/string/calloc.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void* calloc (size_t num, size_t size)
|
||||
{
|
||||
size_t bytes = num * size;
|
||||
void *p = malloc(bytes);
|
||||
|
||||
if(p)
|
||||
memset(p, 0, bytes);
|
||||
|
||||
return p;
|
||||
}
|
@@ -1,8 +1,10 @@
|
||||
void* memchr(const void* buf,int c,int count)
|
||||
#include <string.h>
|
||||
|
||||
void* memchr(const void* buf,int c,size_t count)
|
||||
{
|
||||
int i;
|
||||
for (i=0;i<count;i++)
|
||||
if (*(char*)buf==c)
|
||||
if (*(char*)buf==(char)c)
|
||||
return (void*)buf;
|
||||
else
|
||||
buf++;
|
||||
|
@@ -1,12 +1,14 @@
|
||||
#include <string.h>
|
||||
|
||||
typedef unsigned char uc;
|
||||
int memcmp(const void* buf1,const void* buf2,int count)
|
||||
int memcmp(const void* buf1,const void* buf2,size_t count)
|
||||
{
|
||||
int i;
|
||||
for (i=0;i<count;i++)
|
||||
{
|
||||
if (*(uc*)buf1<*(uc*)buf2)
|
||||
return -1;
|
||||
if (*(uc*)buf1>*(uc*)buf2)
|
||||
if (*(uc*)buf1>*(uc*)buf2)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
@@ -7,29 +7,47 @@ public memcpy
|
||||
public memmove
|
||||
|
||||
proc memcpy c, to:dword,from:dword,count:dword
|
||||
|
||||
mov ecx,[count]
|
||||
push esi
|
||||
push edi
|
||||
mov ecx,[count]
|
||||
test ecx,ecx
|
||||
jz no_copy_block
|
||||
|
||||
mov esi,[from]
|
||||
mov esi,[from]
|
||||
mov edi,[to]
|
||||
cld
|
||||
rep movsb
|
||||
no_copy_block:
|
||||
no_copy_block:
|
||||
|
||||
pop edi
|
||||
pop esi
|
||||
mov eax, [to]
|
||||
ret
|
||||
endp
|
||||
|
||||
proc memmove c, to:dword,from:dword,count:dword
|
||||
|
||||
push esi
|
||||
push edi
|
||||
mov ecx,[count]
|
||||
test ecx,ecx
|
||||
jz no_copy_block_
|
||||
|
||||
mov esi,[from]
|
||||
mov edi,[to]
|
||||
cmp esi, edi
|
||||
je no_copy_block_
|
||||
jg copy_
|
||||
add esi, ecx
|
||||
add edi, ecx
|
||||
dec esi
|
||||
dec edi
|
||||
std
|
||||
copy_:
|
||||
rep movsb
|
||||
no_copy_block_:
|
||||
cld
|
||||
no_copy_block_:
|
||||
|
||||
pop edi
|
||||
pop esi
|
||||
mov eax,[to]
|
||||
ret
|
||||
endp
|
||||
endp
|
||||
|
@@ -10,6 +10,6 @@ memset:
|
||||
cld
|
||||
rep stosb
|
||||
.no_set:
|
||||
mov eax, [esp+8]
|
||||
pop edi
|
||||
ret
|
||||
|
@@ -1,8 +1,10 @@
|
||||
#include <string.h>
|
||||
|
||||
char* strcat(char* strDest, const char* strSource)
|
||||
{
|
||||
char* res;
|
||||
res=strDest;
|
||||
while (*strDest) strDest++;
|
||||
while (*strDest++ = *strSource++) ;
|
||||
while ((*strDest++ = *strSource++)) ;
|
||||
return res;
|
||||
}
|
||||
|
@@ -1,10 +1,11 @@
|
||||
#include <string.h>
|
||||
|
||||
char* strchr(const char* string, int c)
|
||||
{
|
||||
while (*string)
|
||||
{
|
||||
if (*string==c)
|
||||
do {
|
||||
if (*string == (char)c)
|
||||
return (char*)string;
|
||||
string++;
|
||||
}
|
||||
return (char*)0;
|
||||
} while (*string++);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
@@ -1,3 +1,5 @@
|
||||
#include <string.h>
|
||||
|
||||
int strcmp(const char* string1, const char* string2)
|
||||
{
|
||||
while (1)
|
||||
|
@@ -1,7 +1,9 @@
|
||||
char* strcpy(char* strDest,char* strSource)
|
||||
#include <string.h>
|
||||
|
||||
char* strcpy(char* strDest,const char* strSource)
|
||||
{
|
||||
char* res;
|
||||
res=strDest;
|
||||
while(*strDest++ = *strSource++) ;
|
||||
return res;
|
||||
}
|
||||
while((*strDest++ = *strSource++)) ;
|
||||
return res;
|
||||
}
|
||||
|
@@ -1,9 +1,11 @@
|
||||
int strcspn(const char* string, const char* strCharSet)
|
||||
#include <string.h>
|
||||
|
||||
size_t strcspn(const char* string, const char* strCharSet)
|
||||
{
|
||||
const char* temp;
|
||||
int i;
|
||||
i=0;
|
||||
while(1)
|
||||
while(*string)
|
||||
{
|
||||
temp=strCharSet;
|
||||
while (*temp!='\0')
|
||||
@@ -14,4 +16,5 @@ int strcspn(const char* string, const char* strCharSet)
|
||||
}
|
||||
i++;string++;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@ char* strdup(const char* str)
|
||||
int len;
|
||||
len=strlen(str)+1;
|
||||
res=malloc(len);
|
||||
memcpy(res,str,len);
|
||||
if(res)
|
||||
memcpy(res,str,len);
|
||||
return res;
|
||||
}
|
||||
|
@@ -1,4 +1,59 @@
|
||||
#include <string.h>
|
||||
|
||||
char* strerror(int err)
|
||||
{
|
||||
return (char*)0;
|
||||
char *msg;
|
||||
switch(err)
|
||||
{
|
||||
case 0:
|
||||
msg = "success";
|
||||
break;
|
||||
case -1:
|
||||
msg = "end of file";
|
||||
break;
|
||||
case -2:
|
||||
msg = "function is not supported for the given file system";
|
||||
break;
|
||||
case -3:
|
||||
msg = "unknown file system";
|
||||
break;
|
||||
case -5:
|
||||
msg = "file not found";
|
||||
break;
|
||||
case -6:
|
||||
msg = "end of file, EOF";
|
||||
break;
|
||||
case -7:
|
||||
msg = "pointer lies outside of application memory";
|
||||
break;
|
||||
case -8:
|
||||
msg = "disk is full";
|
||||
break;
|
||||
case -9:
|
||||
msg = "file system error";
|
||||
break;
|
||||
case -10:
|
||||
msg = "access denied";
|
||||
break;
|
||||
case -11:
|
||||
msg = "device error";
|
||||
break;
|
||||
case -12:
|
||||
msg = "file system requires more memory";
|
||||
break;
|
||||
case -30:
|
||||
msg = "not enough memory";
|
||||
break;
|
||||
case -31:
|
||||
msg = "file is not executable";
|
||||
break;
|
||||
case -32:
|
||||
msg = "too many processes";
|
||||
break;
|
||||
default:
|
||||
msg = "unknown error";
|
||||
break;
|
||||
}
|
||||
|
||||
return msg;
|
||||
}
|
||||
|
@@ -1,3 +1,5 @@
|
||||
#include <string.h>
|
||||
|
||||
char* strpbrk(const char* string, const char* strCharSet)
|
||||
{
|
||||
const char* temp;
|
||||
|
@@ -1,13 +1,15 @@
|
||||
char* strncat(char* strDest,const char* strSource,int count)
|
||||
#include <string.h>
|
||||
|
||||
char* strncat(char* strDest,const char* strSource,size_t count)
|
||||
{
|
||||
char* res;
|
||||
res=strDest;
|
||||
while (*strDest++) ;
|
||||
while(count-->0)
|
||||
while (*strDest) strDest++;
|
||||
while(count-- > 0)
|
||||
{
|
||||
if(*strDest++ = *strSource++) continue;
|
||||
if((*strDest++ = *strSource++)) continue;
|
||||
return(res);
|
||||
}
|
||||
*strDest = 0;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
@@ -1,12 +1,14 @@
|
||||
int strncmp(const char* string1, const char* string2, int count)
|
||||
#include <string.h>
|
||||
|
||||
int strncmp(const char* string1, const char* string2, size_t count)
|
||||
{
|
||||
while(count>0 && *string1==*string2)
|
||||
while(count>0 && (*string1==*string2))
|
||||
{
|
||||
if (*string1) return 0;
|
||||
if ('\0' == *string1) return 0;
|
||||
++string1;
|
||||
++string2;
|
||||
--count;
|
||||
}
|
||||
if(count) return (*string1 - *string2);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,6 @@
|
||||
char* strncpy(char* strDest,const char* strSource,int count)
|
||||
#include <string.h>
|
||||
|
||||
char* strncpy(char* strDest,const char* strSource,size_t count)
|
||||
{
|
||||
char* res;
|
||||
res=strDest;
|
||||
@@ -11,4 +13,4 @@ char* strncpy(char* strDest,const char* strSource,int count)
|
||||
count--;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
@@ -1,3 +1,5 @@
|
||||
#include <string.h>
|
||||
|
||||
char* strrchr(const char* s,int c)
|
||||
{
|
||||
char* res;
|
||||
|
@@ -1,12 +1,14 @@
|
||||
#include <string.h>
|
||||
|
||||
char* strrev(char *p)
|
||||
{
|
||||
char *q = p, *res = p, z;
|
||||
while(q && *q) ++q; /* find eos */
|
||||
for(--q; p < q; ++p, --q)
|
||||
{
|
||||
for(--q; p < q; ++p, --q)
|
||||
{
|
||||
z = *p;
|
||||
*p = *q;
|
||||
*q = z;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,6 @@
|
||||
int strspn(const char* string,const char* strCharSet)
|
||||
#include <string.h>
|
||||
|
||||
size_t strspn(const char* string,const char* strCharSet)
|
||||
{
|
||||
int i;
|
||||
const char* temp;
|
||||
@@ -6,14 +8,15 @@ int strspn(const char* string,const char* strCharSet)
|
||||
while (*string!='\0')
|
||||
{
|
||||
temp=strCharSet;
|
||||
while (temp!='\0')
|
||||
while (*temp!='\0')
|
||||
{
|
||||
if (*temp==*string)
|
||||
break;
|
||||
}
|
||||
if (temp=='\0')
|
||||
temp++;
|
||||
}
|
||||
if (*temp=='\0')
|
||||
break;
|
||||
*string++;
|
||||
string++;
|
||||
i++;
|
||||
}
|
||||
return i;
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#include<string.h>
|
||||
#include <string.h>
|
||||
|
||||
char* strstr(const char* s, const char* find)
|
||||
{
|
||||
|
@@ -1,14 +1,25 @@
|
||||
#include "string.h"
|
||||
#include <string.h>
|
||||
|
||||
char* strtok(char* s,const char* delim)
|
||||
// non reentrant
|
||||
{
|
||||
char* res;
|
||||
if (*s=='\0')
|
||||
return (char*)0;
|
||||
s+=strspn(s,delim);
|
||||
if (*s=='\0')
|
||||
return (char*)0;
|
||||
res=s;
|
||||
s+=strcspn(s,delim);
|
||||
*s=='\0';
|
||||
static char* savep;
|
||||
char* res;
|
||||
|
||||
if(s)
|
||||
savep = NULL;
|
||||
else
|
||||
s = savep;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user