Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 8729 → Rev 8730

/programs/develop/libraries/kolibri-libc/include/ctype.h
6,6 → 6,8
** dependable answers.
*/
 
#include <stddef.h>
 
#define __ALNUM 1
#define __ALPHA 2
#define __CNTRL 4
39,7 → 41,7
#define isascii(c) (!((c)&(~0x7f)))
#define toascii(c) ((c)&0x7f)
 
extern unsigned char tolower(unsigned char c);
extern unsigned char toupper(unsigned char c);
extern int _FUNC(tolower)(int c);
extern int _FUNC(toupper)(int c);
 
#endif
#endif
/programs/develop/libraries/kolibri-libc/include/stdio.h
47,11 → 47,9
 
typedef size_t fpos_t;
 
#define _STDIO_F_R 1 << 0 // Read
#define _STDIO_F_W 1 << 1 // Write
#define _STDIO_F_A 1 << 2 // Append
#define _STDIO_F_X 1 << 3 // eXclusive
#define _STDIO_F_B 1 << 4 // Binary
#define _FILEMODE_R 1 << 0 // Read
#define _FILEMODE_W 1 << 1 // Write
#define _FILEMODE_A 1 << 2 // Append
 
typedef struct FILE_s {
char *name;
58,12 → 56,8
fpos_t position;
int error;
int eof;
int kind; // 0 - undiefned, 1 - text, 2 - binary
int orientation; // 0 - undiefned, 1 - byte, 2 - wide
int mode; // flags _STDIO_F_*
int append_offset; // do not seek before this point ("a" mode)
int mode; // flags _FILEMODE_*
int __ungetc_emu_buff; // Uses __ungetc_emu (temporary solution!)
int start_size;
} FILE;
 
#define _IOFBF 0
99,7 → 93,7
extern int _FUNC(fscanf)(FILE *restrict, const char *restrict, ...);
extern size_t _FUNC(fwrite)(const void *restrict, size_t size, size_t count, FILE *restrict);
extern int _FUNC(getc)(FILE *);
#define getc _FUNC(fgetc)
#define getc() _FUNC(fgetc)(stdin)
extern int _FUNC(getchar)(void);
extern int _FUNC(printf)(const char *restrict, ...);
extern int _FUNC(putc)(int, FILE *);
/programs/develop/libraries/kolibri-libc/include/sys/ksys.h
884,7 → 884,12
k.p21 = name;
int status;
unsigned bytes_read_v;
_ksys_work_files(&k);
asm_inline(
"int $0x40"
:"=a"(status), "=b"(bytes_read_v)
:"a"(70), "b"(&k)
:"memory"
);
if (!status) {
*bytes_read = bytes_read_v;
}
/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,43 → 1,48
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#define READ_MAX 255
 
static char test_str1[] = "123454567890abcdefghijklmnopqrstufvwxyz";
static char test_str2[READ_MAX];
 
int main(int argc, char **argv)
{
 
int i;
char c;
int i=0;
FILE *f;
FILE *fin;
FILE *fout;
 
//write to file
debug_printf("Write file...\n");
f=fopen("testfile.txt","w");
 
for(i=0;i<50;i++)
{
fputc('1',f);
while(test_str1[i]!='a'){
fputc(test_str1[i],f);
i++;
}
fclose(f);
 
//append to file
debug_printf("Apend file...\n");
f=fopen("testfile.txt","a");
fputs(test_str1+i,f);
char null_term = '\0';
fwrite(&null_term, sizeof(char), 1, f);
fclose(f);
 
for(i=0;i<50;i++)
{
fputc('2',f);
//copy from testfile.txt to copyfile.txt
debug_printf("Read file...\n");
f=fopen("testfile.txt","r");
i=0;
while((test_str2[i]=fgetc(f))!=EOF && i<READ_MAX){
fputc(test_str2[i], stdout);
i++;
}
printf("\n%s\n", test_str1);
if(!strcmp(test_str2, test_str1)){
puts("TEST: OK!");
}else{
puts("TEST: FAIL!");
}
fclose(f);
 
//copy from testfile.txt to copyfile.txt
 
fin=fopen("testfile.txt","r");
fout=fopen("copyfile.txt","w");
/*
while((c=fgetc(fin))!=EOF)
{
fputc(c,fout);
}*/
fclose(fin);
fclose(fout);
 
}
}
/programs/develop/libraries/kolibri-libc/source/ctype/tolower.c
0,0 → 1,7
#include <ctype.h>
 
int tolower(int c)
{
if (isupper(c)) return c | 32;
return c;
}
/programs/develop/libraries/kolibri-libc/source/ctype/toupper.c
0,0 → 1,7
#include <ctype.h>
 
int toupper(int c)
{
if (islower(c)) return c & 0x5f;
return c;
}
/programs/develop/libraries/kolibri-libc/source/libc.c
1,4 → 1,6
#include "ctype/is.c"
#include "ctype/tolower.c"
#include "ctype/toupper.c"
 
#include "sys/rewinddir.c"
#include "sys/readdir.c"
49,6 → 51,7
#include "stdio/rewind.c"
#include "stdio/vfprintf.c"
#include "stdio/fprintf.c"
#include "stdio/ungetc.c"
 
#include "string/strerror.c"
#include "string/strxfrm.c"
/programs/develop/libraries/kolibri-libc/source/stdio/fgetc.c
2,8 → 2,8
 
int fgetc(FILE* stream)
{
int c=EOF;
if(fwrite(&c, sizeof(int), 1, stream)==1){
int c=0;
if(fread(&c, sizeof(char), 1, stream)==1){
return c;
}else{
return EOF;
/programs/develop/libraries/kolibri-libc/source/stdio/fputc.c
4,7 → 4,7
 
int fputc(int c, FILE *stream)
{
if(fwrite(&c, sizeof(int), 1, stream)==1){
if(fwrite(&c, sizeof(char), 1, stream)==1){
return c;
}else{
return EOF;
/programs/develop/libraries/kolibri-libc/source/stdio/fputs.c
2,5 → 2,10
#include <string.h>
 
int fputs(const char *str, FILE *stream){
return fwrite(str, sizeof(char), strlen(str), stream);
size_t str_len = strlen(str);
if(str_len == fwrite(str, sizeof(char), str_len , stream)){
return str[str_len-1];
}else{
return EOF;
}
}
/programs/develop/libraries/kolibri-libc/source/stdio/fread.c
8,20 → 8,24
unsigned bytes_count = size * nmemb;
if(!stream){
errno = EINVAL;
errno = EBADF;
return 0;
}
if(stream==stdin){
__con_init();
__con_gets((char*)ptr, bytes_count);
__con_gets((char*)ptr, bytes_count+1);
return nmemb;
}
 
else{
if(stream->mode != _STDIO_F_W){
if(stream->mode & _FILEMODE_R){
if(!stream->__ungetc_emu_buff){
((char*) ptr)[0]=(char)stream->__ungetc_emu_buff;
//debug_printf("Ungetc: %x\n", ((char*) ptr)[0]);
}
unsigned status = _ksys_file_read_file(stream->name, stream->position, bytes_count, ptr , &bytes_read);
if (status != KSYS_FS_ERR_SUCCESS) {
if (status) {
errno = EIO;
stream->error = errno;
return 0;
/programs/develop/libraries/kolibri-libc/source/stdio/freopen.c
1,3 → 1,4
#include "stddef.h"
#include "sys/ksys.h"
#include <errno.h>
#include <stdio.h>
4,39 → 5,49
#include <stdlib.h>
#include <string.h>
 
#define CREATE_FILE() if(_ksys_file_create(_name)){ \
errno= EIO; \
free(out); \
out = NULL; \
}
 
FILE *freopen(const char *restrict _name, const char *restrict _mode, FILE *restrict out) {
static ksys_bdfe_t info;
info.size=0;
if (!out) {
errno = ENOMEM;
if(!_name || !_mode || !out){
errno = EINVAL;
return NULL;
}
 
_ksys_file_get_info(_name, &info);
if (strchr(_mode, 'r')) { out->mode = _FILEMODE_R; }
if (strchr(_mode, 'a')) { out->mode = _FILEMODE_A; }
if (strchr(_mode, 'w')) { out->mode = _FILEMODE_W; }
 
ksys_bdfe_t info;
int no_file = _ksys_file_get_info(_name, &info);
out->eof=0;
out->error=0;
out->position=0;
out->name = strdup(_name);
out->position = 0;
out->error = 0;
out->eof = 0;
out->kind = 0;
out->orientation = 0;
out->mode = 0;
out->start_size = info.size;
 
if (strchr(_mode, 'b')) { out->mode |= _STDIO_F_B; }
if (strchr(_mode, 'x')) { out->mode |= _STDIO_F_X; }
if (strchr(_mode, 'a')) { out->mode |= _STDIO_F_A; }
if (strchr(_mode, 'r')) { out->mode |= _STDIO_F_R; }
if (strchr(_mode, 'w')) { out->mode |= _STDIO_F_W; }
if (strchr(_mode, '+')) { out->mode |= _STDIO_F_R | _STDIO_F_W; }
 
if (out->mode & _STDIO_F_A) {
switch (out->mode) {
case _FILEMODE_A :
if(no_file){
CREATE_FILE();
}
out->position = info.size;
out->append_offset = info.size;
} else if(out->mode & _STDIO_F_W){
if(_ksys_file_create(_name)){
return NULL;
break;
case _FILEMODE_W :
CREATE_FILE();
break;
case _FILEMODE_R :
if(no_file){
free(out);
out = NULL;
}
break;
default:
free(out);
out = NULL;
break;
}
return out;
}
}
/programs/develop/libraries/kolibri-libc/source/stdio/fwrite.c
9,7 → 9,7
unsigned bytes_count = size * nmemb;
if(!stream){
errno = EINVAL;
errno = EBADF;
return 0;
}
25,7 → 25,7
}
}
else{
if(stream->mode != _STDIO_F_R){
if(stream->mode != _FILEMODE_R){
unsigned status = _ksys_file_write_file(stream->name, stream->position, bytes_count, ptr, &bytes_written);
if (status != KSYS_FS_ERR_SUCCESS) {
errno = EIO;
/programs/develop/libraries/kolibri-libc/source/stdio/getchar.c
2,7 → 2,9
#include "conio.h"
 
int getchar(void) {
int c = __con_getch();
__con_init();
char c = 0;
__con_gets(&c, 2);
if (c == 0) {
c = EOF;
}
/programs/develop/libraries/kolibri-libc/source/stdio/ungetc.c
11,12 → 11,12
return EOF;
}
 
if (file->mode != _STDIO_F_R){
if (file->mode != _FILEMODE_R){
errno = EACCES;
return EOF;
}
 
if (file->position > file->start_size || file->position == 0 || c == EOF || file->__ungetc_emu_buff != EOF)
if (file->position == 0 || c == EOF)
{
errno = EOF;
return EOF;
/programs/develop/libraries/kolibri-libc/source/symbols.txt
40,6 → 40,7
vfscanf
vsnprintf
vsscanf
ungetc
!____STDLIB____
abs
atoi
125,5 → 126,7
setjmp
!____CTYPE____
__is
tolower
toupper
!___CONIO___
con_set_title