_exit
. , , (, ).
close
. :
int close(int file) {
return -1;
}
environ
. :
char *__env[1] = { 0 };
char **environ = __env;
execve
. ( ):
#include <errno.h>
#undef errno
extern int errno;
int execve(char *name, char **argv, char **env) {
errno = ENOMEM;
return -1;
}
fork
. ( ):
#include <errno.h>
#undef errno
extern int errno;
int fork(void) {
errno = EAGAIN;
return -1;
}
fstat
. . sys/stat.h include C.
#include <sys/stat.h>
int fstat(int file, struct stat *st) {
st->st_mode = S_IFCHR;
return 0;
}
getpid
; , . :
int getpid(void) {
return 1;
}
isatty
, . , stdout, :
int isatty(int file) {
return 1;
}
kill
. :
#include <errno.h>
#undef errno
extern int errno;
int kill(int pid, int sig) {
errno = EINVAL;
return -1;
}
link
. :
#include <errno.h>
#undef errno
extern int errno;
int link(char *old, char *new) {
errno = EMLINK;
return -1;
}
lseek
. :
int lseek(int file, int ptr, int dir) {
return 0;
}
open
. :
int open(const char *name, int flags, int mode) {
return -1;
}
read
. :
int read(int file, char *ptr, int len) {
return 0;
}
sbrk
. malloc , . ; _end GNU.
caddr_t sbrk(int incr) {
extern char _end;
static char *heap_end;
char *prev_heap_end;
if (heap_end == 0) {
heap_end = &_end;
}
prev_heap_end = heap_end;
if (heap_end + incr > stack_ptr) {
write (1, "Heap and stack collision\n", 25);
abort ();
}
heap_end += incr;
return (caddr_t) prev_heap_end;
}
stat
( ). :
int stat(char *file, struct stat *st) {
st->st_mode = S_IFCHR;
return 0;
}
times
. :
int times(struct tms *buf) {
return -1;
}
unlink
. :
#include <errno.h>
#undef errno
extern int errno;
int unlink(char *name) {
errno = ENOENT;
return -1;
}
wait
. :
#include <errno.h>
#undef errno
extern int errno;
int wait(int *status) {
errno = ECHILD;
return -1;
}
write
. libc , stdout, , , , , . ; ( , , , ) .
int write(int file, char *ptr, int len) {
int todo;
for (todo = 0; todo < len; todo++) {
outbyte (*ptr++);
}
return len;
}