Chameleon

Chameleon Commit Details

Date:2011-08-06 22:47:23 (12 years 8 months ago)
Author:Evan Lojewski
Commit:1308
Parents: 1307
Message:Add a few placeholders for file io
Changes:
A/branches/xZenu/src/modules/klibc/fputc.c
A/branches/xZenu/src/modules/klibc/fputs.c
A/branches/xZenu/src/modules/klibc/fread.c
A/branches/xZenu/src/modules/klibc/fread2.c
A/branches/xZenu/src/modules/klibc/fopen.c
M/branches/xZenu/src/modules/MakeInc.dir
M/branches/xZenu/src/modules/klibc/fwrite.c
M/branches/xZenu/src/modules/Cconfig
M/branches/xZenu/src/modules/Makefile
M/branches/xZenu/src/modules/klibc/Makefile

File differences

branches/xZenu/src/modules/MakeInc.dir
9797
9898
9999
100
100101
101
102102
103103
104104
......
106106
107107
108108
109
109
110110
111111
112112
......
126126
127127
128128
129
129
130130
131131
132132
dylib_LINKER: ${OBJROOT} ${MODULE_OBJECTS} $(SYMROOT)/boot_modules.c $(SYMROOT)/boot_modules.h $(SYMROOT)/$(MODULE_NAME).${ARCH}.linker.dylib
dylib: ${OBJROOT} ${MODULE_OBJECTS} $(SYMROOT)/$(MODULE_NAME).${ARCH}.dylib
#todo use -dot to generate symbol deps graph
###### Build module into the code binary ######
$(SYMROOT)/$(MODULE_NAME).${ARCH}.linker.dylib: $(MODULE_DEPENDENCIES) ${MODULE_OBJECTS} $(OBJROOT)/$(MODULE_NAME).desc $(OBJROOT)/$(MODULE_NAME).author Makefile
@echo "\t[LD:${ARCH}] (LINKER) $(MODULE_NAME).${ARCH}dylib"
-alias _$(MODULE_START) start \
-dylib -read_only_relocs suppress \
-S -x -Z -dead_strip_dylibs \
-no_uuid \
-no_uuid -no_eh_labels \
-current_version $(MODULE_VERSION) -compatibility_version $(MODULE_COMPAT_VERSION) \
-final_output $(MODULE_NAME) \
$(filter %.${ARCH}o,$^) \
-alias _$(MODULE_START) start \
-dylib -read_only_relocs suppress \
-S -x -Z -dead_strip_dylibs \
-no_uuid \
-no_uuid -no_eh_labels \
-current_version $(MODULE_VERSION) -compatibility_version $(MODULE_COMPAT_VERSION) \
-final_output $(MODULE_NAME) \
$(filter %.${ARCH}o,$^) \
branches/xZenu/src/modules/klibc/Makefile
2424
2525
2626
27
27
28
2829
2930
strcmp strncmp strcpy strncpy strlcpy strstr strncat strcat strdup strncasecmp strchr strlen strtoul strtol \
qsort sha1hash onexit atexit exit \
snprintf vsnprintf sscanf vsscanf sprintf \
fwrite fprintf vfprintf printf
fwrite fprintf vfprintf printf\
fread2 fputc fputs fopen fread
include ../MakeInc.dir
branches/xZenu/src/modules/klibc/fopen.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
* fopen.c
*/
#include <stdio.h>
#include <unistd.h>
//#include <fcntl.h>
/* This depends on O_RDONLY == 0, O_WRONLY == 1, O_RDWR == 2 */
FILE *fopen(const char *file, const char *mode)
{
printf("WARNING: fopen unimplimented.\n");
return NULL;
#if 0
int flags = O_RDONLY;
int plus = 0;
while (*mode) {
switch (*mode++) {
case 'r':
flags = O_RDONLY;
break;
case 'w':
flags = O_WRONLY | O_CREAT | O_TRUNC;
break;
case 'a':
flags = O_WRONLY | O_CREAT | O_APPEND;
break;
case '+':
plus = 1;
break;
}
}
if (plus) {
flags = (flags & ~(O_RDONLY | O_WRONLY)) | O_RDWR;
}
/* Note: __create_file(-1) == NULL, so this is safe */
return __create_file(open(file, flags, 0666));
#endif
}
branches/xZenu/src/modules/klibc/fputc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/*
* fputc.c
*
* gcc "printf decompilation" expects this to exist...
*/
#include <stdio.h>
extern size_t _fwrite(const void *buf, size_t count, FILE *f);
int fputc(int c, FILE *f)
{
unsigned char ch = c;
return _fwrite(&ch, 1, f) == 1 ? ch : EOF;
}
branches/xZenu/src/modules/klibc/fputs.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*
* fputs.c
*
* This isn't quite fputs() in the stdio sense, since we don't
* have stdio, but it takes a file descriptor argument instead
* of the FILE *.
*/
#include <stdio.h>
#include <string.h>
extern size_t _fwrite(const void *buf, size_t count, FILE *f);
int fputs(const char *s, FILE *file)
{
return _fwrite(s, strlen(s), file);
}
branches/xZenu/src/modules/klibc/fwrite.c
1313
1414
1515
16
1617
1718
1819
while (count) {
rv = 1;
// TODO: use FILE*
putchar(*p);
p += rv;
branches/xZenu/src/modules/klibc/fread2.c
1
2
3
4
5
6
7
8
9
10
11
12
13
/*
* fread2.c
*
* The actual fread() function as a non-inline
*/
#define __NO_FREAD_FWRITE_INLINES
#include <stdio.h>
extern size_t _fread(void *buf, size_t count, FILE *f);
size_t fread(void *ptr, size_t size, size_t nmemb, FILE * f)
{
return _fread(ptr, size * nmemb, f) / size;
}
branches/xZenu/src/modules/klibc/fread.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/*
* fread.c
*/
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
size_t _fread(void *buf, size_t count, FILE *f)
{
printf("WARNING: fread not implimented.\n");
return 0;
#if 0
size_t bytes = 0;
ssize_t rv;
char *p = buf;
while (count) {
rv = read(fileno(f), p, count);
if (rv == -1) {
if (errno == EINTR) {
errno = 0;
continue;
} else
break;
} else if (rv == 0) {
break;
}
p += rv;
bytes += rv;
count -= rv;
}
return bytes;
#endif
}
branches/xZenu/src/modules/Cconfig
2727
2828
2929
30
31
32
3033
3134
source "modules/Disk/Cconfig"
source "modules/FileSystem/Cconfig"
source "modules/TinyXML/Cconfig"
source "modules/HelloWorld/Cconfig"
endmenu
branches/xZenu/src/modules/Makefile
99
1010
1111
12
12
1313
1414
1515
include ${ROOT}/Make.rules
# The order of building is important.
SUBDIRS = klibc uClibcxx ModuleSystem Disk FileSystem
SUBDIRS = klibc uClibcxx ModuleSystem Disk FileSystem TinyXML
# ModuleSystem
CFLAGS= -O3 $(MORECPP) -g -static

Archive Download the corresponding diff file

Revision: 1308