Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 9229 → Rev 9230

/programs/develop/ktcc/trunk/libc.obj/include/stdio.h
50,6 → 50,7
#define _FILEMODE_R 1 << 0 // Read
#define _FILEMODE_W 1 << 1 // Write
#define _FILEMODE_A 1 << 2 // Append
#define _FILEMODE_PLUS 1 << 3 // Plus
 
typedef struct FILE_s {
char *name;
/programs/develop/ktcc/trunk/libc.obj/include/stdlib.h
43,6 → 43,7
extern void _FUNC(__assert_fail)(const char *expr, const char *file, int line, const char *func);
extern void _FUNC(qsort)(void *base0, size_t n, size_t size, int (*compar)(const void *, const void *));
 
extern double _FUNC(strtod)(const char *s, char **sret);
extern double _FUNC(atof)(const char *ascii);
 
#endif
/programs/develop/ktcc/trunk/libc.obj/source/libc.c
100,6 → 100,7
#include "stdlib/rand.c"
#include "stdlib/qsort.c"
#include "stdlib/assert.c"
#include "stdlib/strtod.c"
#include "stdlib/atof.c"
 
#include "math/acosh.c"
/programs/develop/ktcc/trunk/libc.obj/source/stdio/fclose.c
1,7 → 1,9
#include "stddef.h"
#include <stdio.h>
#include <stdlib.h>
 
int fclose(FILE *stream) {
free(stream);
stream = NULL;
return 0;
}
/programs/develop/ktcc/trunk/libc.obj/source/stdio/fread.c
24,7 → 24,7
return nmemb;
}
 
if(stream->mode & _FILEMODE_R){
if(stream->mode != _FILEMODE_W && stream->mode != _FILEMODE_A){
if(!stream->__ungetc_emu_buff){
((char*) ptr)[0]=(char)stream->__ungetc_emu_buff;
//debug_printf("Ungetc: %x\n", ((char*) ptr)[0]);
/programs/develop/ktcc/trunk/libc.obj/source/stdio/freopen.c
1,53 → 1,62
#include "stddef.h"
#include "sys/ksys.h"
#include <stddef.h>
#include <sys/ksys.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/dirent.h>
 
#define CREATE_FILE() if(_ksys_file_create(_name)){ \
errno= EIO; \
free(out); \
out = NULL; \
 
static FILE* _set_errno(FILE *out, int err){
errno = err;
if(out){
free(out->name);
free(out);
}
out = NULL;
return out;
}
 
static void _create_file(char *name, FILE *out){
if(_ksys_file_create(name)){
_set_errno(out, EIO);
}
}
 
FILE *freopen(const char *restrict _name, const char *restrict _mode, FILE *restrict out) {
if(!_name || !_mode || !out){
errno = EINVAL;
return NULL;
return _set_errno(out, EINVAL);
}
 
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);
if(!no_file && info.attributes & IS_FOLDER){
return _set_errno(out, EISDIR);
}
out->eof=0;
out->error=0;
out->position=0;
out->name = strdup(_name);
switch (out->mode) {
case _FILEMODE_A :
if (strchr(_mode, 'r')) { out->mode = _FILEMODE_R; }
if (strchr(_mode, 'w')) { out->mode = _FILEMODE_W; }
if (strchr(_mode, 'a')) { out->mode = _FILEMODE_A; }
if (strchr(_mode, '+')) { out->mode |= _FILEMODE_PLUS; }
 
if(out->mode & _FILEMODE_A){
if(no_file){
CREATE_FILE();
_create_file(out->name, out);
}
out->position = info.size;
break;
case _FILEMODE_W :
CREATE_FILE();
break;
case _FILEMODE_R :
}else if(out->mode & _FILEMODE_W){
_create_file(out->name, out);
}else if((out->mode & _FILEMODE_R)){
if(no_file){
free(out);
out = NULL;
_set_errno(out, ENOENT);
}
break;
default:
free(out);
out = NULL;
break;
}else{
_set_errno(out, EINVAL);
}
return out;
}
/programs/develop/ktcc/trunk/libc.obj/source/stdlib/atof.c
1,8 → 1,7
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
 
double
atof(const char *ascii)
double atof(const char *ascii)
{
return strtod(ascii, 0);
}
/programs/develop/ktcc/trunk/libc.obj/source/stdlib/strtod.c
0,0 → 1,96
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include <math.h>
 
#define unconst(__v, __t) __extension__ ({union { const __t __cp; __t __p; } __q; __q.__cp = __v; __q.__p;})
 
double strtod(const char *s, char **sret)
{
long double r; /* result */
int e; /* exponent */
long double d; /* scale */
int sign; /* +- 1.0 */
int esign;
int i;
int flags=0;
 
r = 0.0;
sign = 1.0;
e = 0;
esign = 1;
 
while ((*s == ' ') || (*s == '\t'))
s++;
if (*s == '+')
s++;
else if (*s == '-')
{
sign = -1;
s++;
}
 
while ((*s >= '0') && (*s <= '9'))
{
flags |= 1;
r *= 10.0;
r += *s - '0';
s++;
}
 
if (*s == '.')
{
d = 0.1L;
s++;
while ((*s >= '0') && (*s <= '9'))
{
flags |= 2;
r += d * (*s - '0');
s++;
d *= 0.1L;
}
}
 
if (flags == 0)
{
if (sret)
*sret = unconst(s, char *);
return 0;
}
 
if ((*s == 'e') || (*s == 'E'))
{
s++;
if (*s == '+')
s++;
else if (*s == '-')
{
s++;
esign = -1;
}
if ((*s < '0') || (*s > '9'))
{
if (sret)
*sret = unconst(s, char *);
return r;
}
 
while ((*s >= '0') && (*s <= '9'))
{
e *= 10;
e += *s - '0';
s++;
}
}
if (esign < 0)
for (i = 1; i <= e; i++)
r *= 0.1L;
else
for (i = 1; i <= e; i++)
r *= 10.0;
 
if (sret)
*sret = unconst(s, char *);
return r * sign;
}
/programs/develop/ktcc/trunk/libc.obj/source/symbols.txt
63,6 → 63,7
srand
rand
qsort
strtod
__assert_fail
!____STRING____
!memcpy