-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsyscalls.c
79 lines (65 loc) · 1.61 KB
/
syscalls.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* syscalls.c
*
* Created on: 7.1.2017
* Based on work of: freddiechopin.info
* Author: korgeaux
*/
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#define SYSCALLS_HAVE_SBRK_R 1
#define SYSCALLS_HAVE_CLOSE_R 0
#define SYSCALLS_HAVE_FSTAT_R 0
#define SYSCALLS_HAVE_ISATTY_R 0
#define SYSCALLS_HAVE_LSEEK_R 0
#define SYSCALLS_HAVE_READ_R 0
#define SYSCALLS_HAVE_WRITE_R 0
#undef errno
extern int errno;
#if SYSCALLS_HAVE_SBRK_R == 1
caddr_t _sbrk_r(struct _reent *r, int size) {
extern char __heap_start;
extern char __heap_end;
static char *current_heap_end = &__heap_start;
char *previous_heap_end;
previous_heap_end = current_heap_end;
if (current_heap_end + size > &__heap_end) {
errno = ENOMEM;
return (caddr_t) -1;
}
current_heap_end += size;
return (caddr_t) previous_heap_end;
}
#endif
#if SYSCALLS_HAVE_CLOSE_R == 1
int _close_r(struct _reent *r, int file) {
return -1;
}
#endif
#if SYSCALLS_HAVE_FSTAT_R == 1
int _fstat_r(struct _reent *r, int file, struct stat *st) {
st->st_mode = S_IFCHR;
return 0;
}
#endif
#if SYSCALLS_HAVE_ISATTY_R == 1
int _isatty_r(struct _reent *r, int file) {
return 1;
}
#endif
#if SYSCALLS_HAVE_LSEEK_R == 1
off_t _lseek_r(struct _reent *r, int file, off_t offset, int whence) {
return 0;
}
#endif
#if SYSCALLS_HAVE_READ_R == 1
ssize_t _read_r(struct _reent *r, int file, void *buf, size_t nbyte) {
return 0;
}
#endif
#if SYSCALLS_HAVE_WRITE_R == 1
ssize_t _write_r(struct _reent *r, int file, const void *buf, size_t nbyte) {
return 0;
}
#endif