Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 6432 → Rev 6433

/programs/develop/ktcc/trunk/libc/stdio/clearerr.c
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);
}
/programs/develop/ktcc/trunk/libc/stdio/fclose.c
2,8 → 2,17
#include <string.h>
#include <stdlib.h>
 
void fclose(FILE* file)
int fclose(FILE* file)
{
if(!file)
{
errno = E_INVALIDPTR;
return EOF;
}
 
if(file->buffer)
free(file->buffer);
free(file);
}
 
return 0;
}
/programs/develop/ktcc/trunk/libc/stdio/feof.c
1,5 → 1,11
#include <stdio.h>
int feof(FILE* file)
{
if(!file)
{
errno = E_INVALIDPTR;
return EOF;
}
 
return file->filepos>=file->filesize;
}
}
/programs/develop/ktcc/trunk/libc/stdio/fflush.c
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
}
/programs/develop/ktcc/trunk/libc/stdio/fgetc.c
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
file->filepos++;
return (int)file->buffer[0];
}
else return(res);
else
{
errno = -res;
return EOF; // errors are < 0
}
}
}
}
/programs/develop/ktcc/trunk/libc/stdio/fgetpos.c
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;
}
}
/programs/develop/ktcc/trunk/libc/stdio/fgets.c
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;
 
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)
{
/programs/develop/ktcc/trunk/libc/stdio/fopen.c
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,7 → 42,7
 
if (local_path==1)
{
i=0x400;
i=FILENAME_MAX;
//find local path of program
while(*(programpath+i)!='/')
{
46,7 → 49,13
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
}
 
//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
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
mode++;
}else
return 0;
if (*mode=='+')
{
imode|=FILE_OPEN_PLUS;
mode++;
}
if (*mode=='t')
{
imode|=FILE_OPEN_TEXT;
121,14 → 140,22
mode++;
}
if (*mode!=0)
return 0;
return NULL;
res=malloc(sizeof(FILE));
res->buffer=malloc(256);
res->buffersize=256;
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))
{
/programs/develop/ktcc/trunk/libc/stdio/format_print.c
77,7 → 77,7
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
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
//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);
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)
{
/programs/develop/ktcc/trunk/libc/stdio/format_scan.c
336,11 → 336,7
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;
/programs/develop/ktcc/trunk/libc/stdio/fprintf.c
1,23 → 1,44
#include <stdio.h>
#include <stdlib.h>
 
 
 
int fprintf(FILE* file, const char* 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;
//int data[4];
int printed, rc = 0;
va_start (arg, format);
if(!file || !format)
{
errno = E_INVALIDPTR;
return errno;
}
 
buf=malloc(4096*2); //8kb max
//data[0]=(int)&arg-(int)&format;
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);
 
if (rc < 0)
return rc;
else
return(printed);
}
/programs/develop/ktcc/trunk/libc/stdio/fputc.c
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
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;
}
}
}
/programs/develop/ktcc/trunk/libc/stdio/fputs.c
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;
}
/programs/develop/ktcc/trunk/libc/stdio/fread.c
6,10 → 6,20
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);
22,5 → 32,9
fullsize=fullsize/size;
return(fullsize);
}
else return 0;
}
else
{
errno = -res;
return 0;
}
}
/programs/develop/ktcc/trunk/libc/stdio/fseek.c
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)
/programs/develop/ktcc/trunk/libc/stdio/fsetpos.c
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;
/programs/develop/ktcc/trunk/libc/stdio/ftell.c
1,5 → 1,11
#include <stdio.h>
long ftell(FILE* file)
{
if(!file)
{
errno = E_INVALIDPTR;
return -1L;
}
 
return file->filepos;
}
}
/programs/develop/ktcc/trunk/libc/stdio/fwrite.c
6,10 → 6,22
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;
if ((file->filesize)<(file->filepos+fullsize)) file->filesize=file->filepos+fullsize;
29,10 → 41,10
}
*/
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)
{
39,8 → 51,11
file->filepos+=fullsize;
fullsize=fullsize/count;
return(fullsize);
} else
{
errno = -res;
return(0);
}
else return(0);
}
else
{
50,9 → 65,12
file->filepos+=fullsize;
fullsize=fullsize/count;
return(fullsize);
} else
{
errno = -res;
return(0);
}
else return(0);
}
}
else return(0);
}
}
/programs/develop/ktcc/trunk/libc/stdio/printf.c
1,16 → 1,23
#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)
20,6 → 27,6
con_write_string(s, printed_simbols);
free(s);
}
 
return(printed_simbols);
}
 
/programs/develop/ktcc/trunk/libc/stdio/rewind.c
1,5 → 1,11
#include <stdio.h>
void rewind(FILE* file)
{
if(!file)
{
errno = E_INVALIDPTR;
return;
}
 
file->filepos=0;
}
}
/programs/develop/ktcc/trunk/libc/stdio/snprintf.c
1,4 → 1,4
#include <kolibrisys.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
 
/programs/develop/ktcc/trunk/libc/stdio/ungetc.c
4,13 → 4,24
{
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;
}
}
/programs/develop/ktcc/trunk/libc/stdio/vsnprintf.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)
{
 
return format_print(dest,size, format, ap);
}
 
 
int vsprintf (char * dest, const char * format, va_list ap )
{
return format_print(dest, 4096, format, ap);
}