12#include <sys/resource.h>
13#include <sys/unistd.h>
31 for (i = 0; i < len; ++i)
32 putch(((
const char*) src)[i]);
125 struct _reent *
ptr = _REENT;
129 ptr->_errno = ENOMEM;
130 return (caddr_t) - 1;
146void *
dlsym(
void * p,
const char * s) {
160FILE *
popen(
const char * s1,
const char * s2){
170int execve(
const char *path,
char *
const argv[],
char *
const envp[]) {
171 struct _reent *r = _REENT;
176int execv(
const char *path,
char *
const argv[]) {
180int execvp(
const char *file,
char *
const argv[]) {
187 struct _reent *r = _REENT;
194 struct _reent *
ptr = _REENT;
195 ptr->_errno = ENOSYS;
205int mkfifo(
const char *pathname, mode_t mode) {
218 struct stat information;
219 int ok =
stat(path, &information);
223 if (((information.st_mode & S_IRUSR) == S_IRUSR) ||
224 ((information.st_mode & S_IRGRP) == S_IRGRP) ||
225 ((information.st_mode & S_IROTH) == S_IROTH)){
243 struct _reent *
ptr = _REENT;
244 ptr->_errno = ENOSYS;
249 struct _reent *
ptr = _REENT;
254 ptr->_errno = ENOSYS;
264 struct _reent *
ptr = _REENT;
265 ptr->_errno = ENOSYS;
270 strncpy(name,
"xenon",len);
344#define MAX_HANDLES 1024
349void __release_handle(
int fd) {
355 if (
NULL != handle) {
368 if (handles[i] ==
NULL)
break;
372 handles[i] = malloc(
size);
373 if (
NULL != handles[i]) ret = i + 3;
384 return handles[fd - 3];
392static int defaultDevice = -1;
399 if (device > 2 && device <=
STD_MAX)
400 defaultDevice = device;
445 int i = 0, namelen, dev = -1;
447 if (strchr(name,
':') ==
NULL)
return defaultDevice;
453 if (name[namelen] ==
':' || (
isdigit((
int)name[namelen]) && name[namelen + 1] ==
':')) {
487 for (devnum = 3; devnum <
STD_MAX; devnum++) {
509 if (dev >= 0 && dev <
STD_MAX) {
522int open(
const char *file,
int flags,
int mode) {
523 struct _reent *r = _REENT;
543 __release_handle(fd);
559int read(
int fileDesc,
void *
ptr,
size_t len) {
560 struct _reent *r = _REENT;
562 unsigned int dev = 0;
563 unsigned int fd = -1;
567 if (fileDesc != -1) {
573 if (
NULL == handle)
return ret;
584int write(
int fileDesc,
const void *
ptr,
size_t len) {
585 struct _reent *r = _REENT;
587 unsigned int dev = 0;
588 unsigned int fd = -1;
593 if (fileDesc != -1) {
600 if (
NULL == handle)
return ret;
616 struct _reent *r = _REENT;
618 unsigned int dev = 0;
619 unsigned int fd = -1;
623 if (fileDesc != -1) {
629 if (
NULL == handle)
return ret;
645 struct _reent *r = _REENT;
660 struct _reent *r = _REENT;
680 unsigned int dev = 0;
681 unsigned int fd = -1;
690 if (
NULL == handle) {
707 unsigned int dev = 0;
708 unsigned int fd = -1;
717 if (
NULL == handle) {
732int link(
const char *existing,
const char *
new) {
733 struct _reent *r = _REENT;
740 if (sourceDev == destDev) {
758 struct _reent *r = _REENT;
761 unsigned int dev = 0;
762 unsigned int fd = -1;
766 if (fileDesc != -1) {
773 if (
NULL == handle)
return ret;
787int rename(
const char *existing,
const char *newName) {
788 struct _reent *r = _REENT;
796 if (sourceDev == destDev) {
813 struct _reent *r = _REENT;
831 struct _reent *
ptr = _REENT;
833 unsigned int dev = 0;
834 unsigned int fd = -1;
836 if (fileDesc != -1) {
840 if (handle !=
NULL) {
847 __release_handle(fileDesc);
857static char _current_working_directory [PATH_MAX] =
"/";
859#define DIRECTORY_SEPARATOR_CHAR '/'
867 const char *extraEnd;
870 pathLength = strnlen(path, maxLength);
873 if (pathLength >= maxLength) {
874 r->_errno = ENAMETOOLONG;
877 pathEnd = path + pathLength;
898 if (extraEnd ==
NULL) {
899 extraEnd = strrchr(extra,
'\0');
904 extraSize = (extraEnd - extra);
905 if (extraSize == 0) {
922 if (pathEnd ==
NULL) {
927 pathLength = pathEnd - path;
930 pathLength += extraSize;
931 if (pathLength >= maxLength) {
932 r->_errno = ENAMETOOLONG;
936 strncpy(pathEnd, extra, extraSize);
937 pathEnd += extraSize;
941 }
while (extraSize != 0);
953 struct _reent *r = _REENT;
956 const char *pathPosition;
957 char temp_cwd [PATH_MAX];
960 if (strnlen(path, PATH_MAX + 1) >= PATH_MAX) {
961 r->_errno = ENAMETOOLONG;
965 if (strchr(path,
':') !=
NULL) {
966 strncpy(temp_cwd, path, PATH_MAX);
968 path = strchr(path,
':') + 1;
970 strncpy(temp_cwd, _current_working_directory, PATH_MAX);
973 pathPosition = strchr(temp_cwd,
':') + 1;
1001 strncpy(_current_working_directory, temp_cwd, PATH_MAX);
1008 struct _reent *r = _REENT;
1015 if (
size < (strnlen(_current_working_directory, PATH_MAX) + 1)) {
1020 strncpy(buf, _current_working_directory,
size);
1025int chmod(
const char *path, mode_t mode) {
1027 struct _reent *r = _REENT;
1044 struct _reent *r = _REENT;
1050 if (handle !=
NULL) {
1063static DIR_ITER * __diropen(
const char *path) {
1064 struct _reent *r = _REENT;
1075 if (
NULL != handle) {
1096static int __dirreset(
DIR_ITER *dirState) {
1097 struct _reent *r = _REENT;
1101 if (dirState !=
NULL) {
1113static int __dirnext(
DIR_ITER *dirState,
char *filename,
struct stat *filestat) {
1114 struct _reent *r = _REENT;
1118 if (dirState !=
NULL) {
1130static int __dirclose(
DIR_ITER *dirState) {
1131 struct _reent *r = _REENT;
1135 if (dirState !=
NULL) {
1150 DIR* dirp = malloc(
sizeof (
DIR));
1156 dirp->
dirData = __diropen(dirname);
1177 res = __dirclose(dirp->
dirData);
1184 char filename[PATH_MAX];
1186 int olderrno = errno;
1193 res = __dirnext(dirp->
dirData, filename, &st);
1196 if (errno == ENOENT) {
1207 if (strnlen(filename, PATH_MAX) >=
sizeof (dirp->
fileData.
d_name)) {
1231 char filename[PATH_MAX];
1233 if (!dirp || loc < 0) {
1246 (__dirnext(dirp->
dirData, filename,
NULL) >= 0)) {
1263int mkdir(
const char *path, mode_t mode) {
1264 struct _reent *r = _REENT;
void lock(unsigned int *lock)
#define __lock_release_recursive(NAME)
#define __lock_acquire_recursive(NAME)
unsigned int __mf_uintptr_t __attribute__((__mode__(__pointer__)))
int chdir(const char *path)
int mkfifo(const char *pathname, mode_t mode)
pid_t waitpid(pid_t pid, int *stat_loc, int options)
const devoptab_t * devoptab_list[STD_MAX]
void(* stdlog_hook)(const char *text, int len)=0
int kill(int pid, int sig)
int unlink(const char *name)
#define DIRECTORY_SEPARATOR_CHAR
const char DIRECTORY_SEPARATOR[]
void * getpwnam(const char *name)
void(* stdout_hook)(const char *text, int len)=0
FILE * popen(const char *s1, const char *s2)
void * dlsym(void *p, const char *s)
int fchmod(int fd, mode_t mode)
long int telldir(DIR *dirp)
int fcntl(int filedes, int cmd,...)
int __alloc_handle(int size)
int mkdir(const char *path, mode_t mode)
void * getpwuid(uid_t uid)
int __libc_lock_acquire(int *lock)
int stat(const char *file, struct stat *st)
int ftruncate(int fileDesc, off_t len)
int __libc_lock_release(int *lock)
int execve(const char *path, char *const argv[], char *const envp[])
const char DIRECTORY_PARENT[]
void * dlopen(const char *c, int i)
const devoptab_t console_optab
int gettimeofday(struct timeval *ptimeval, void *ptimezone)
int fstat(int fileDesc, struct stat *st)
int _concatenate_path(struct _reent *r, char *path, const char *extra, int maxLength)
void setDefaultDevice(int device)
struct dirent * readdir(DIR *dirp)
int RemoveDevice(const char *name)
int read(int fileDesc, void *ptr, size_t len)
int AddDevice(const devoptab_t *device)
int gethostname(char *name, size_t len)
int execvp(const char *file, char *const argv[])
void * getgrnam(const char *name)
int write(int fileDesc, const void *ptr, size_t len)
int __libc_lock_close(int *lock)
void * getgrgid(gid_t gid)
int link(const char *existing, const char *new)
int FindDevice(const char *name)
ssize_t vfs_console_write(struct _reent *r, int fd, const char *src, size_t len)
void seekdir(DIR *dirp, long int loc)
int chmod(const char *path, mode_t mode)
int lstat(const char *path, struct stat *buf)
const char DIRECTORY_THIS[]
char * getcwd(char *buf, size_t size)
_off_t lseek(int fileDesc, _off_t pos, int dir)
int open(const char *file, int flags, int mode)
void rewinddir(DIR *dirp)
const devoptab_t dotab_stdnull
int getrusage(int who, struct rusage *usage)
void * sbrk(ptrdiff_t incr)
const devoptab_t * GetDeviceOpTab(const char *name)
void __malloc_unlock(struct _reent *ptr)
int rename(const char *existing, const char *newName)
__handle * __get_handle(int fd)
int execv(const char *path, char *const argv[])
DIR * opendir(const char *dirname)
void __malloc_lock(struct _reent *ptr)
int bdev_enum(int handle, const char **name)
int __libc_lock_init(int *lock, int recursive)
int access(const char *path, int mode)
int(* gettod_r)(struct _reent *ptr, struct timeval *tp, struct timezone *tz)
void *(* sbrk_r)(struct _reent *ptr, ptrdiff_t incr)
int(* lock_release)(int *lock)
void(* malloc_lock)(struct _reent *ptr)
int(* lock_close)(int *lock)
void(* malloc_unlock)(struct _reent *ptr)
int(* lock_acquire)(int *lock)
int(* lock_init)(int *lock, int recursive)
int(* dirclose_r)(struct _reent *r, DIR_ITER *dirState)
int(* rename_r)(struct _reent *r, const char *oldName, const char *newName)
int(* unlink_r)(struct _reent *r, const char *name)
DIR_ITER *(* diropen_r)(struct _reent *r, DIR_ITER *dirState, const char *path)
int(* statvfs_r)(struct _reent *r, const char *path, struct statvfs *buf)
int(* dirreset_r)(struct _reent *r, DIR_ITER *dirState)
int(* fsync_r)(struct _reent *r, int fd)
int(* fstat_r)(struct _reent *r, int fd, struct stat *st)
int(* fchmod_r)(struct _reent *r, int fd, mode_t mode)
int(* close_r)(struct _reent *r, int fd)
int(* dirnext_r)(struct _reent *r, DIR_ITER *dirState, char *filename, struct stat *filestat)
off_t(* seek_r)(struct _reent *r, int fd, off_t pos, int dir)
int(* chmod_r)(struct _reent *r, const char *path, mode_t mode)
int(* link_r)(struct _reent *r, const char *existing, const char *newLink)
ssize_t(* write_r)(struct _reent *r, int fd, const char *ptr, size_t len)
int(* ftruncate_r)(struct _reent *r, int fd, off_t len)
int(* mkdir_r)(struct _reent *r, const char *path, int mode)
int(* open_r)(struct _reent *r, void *fileStruct, const char *path, int flags, int mode)
int(* stat_r)(struct _reent *r, const char *file, struct stat *st)
ssize_t(* read_r)(struct _reent *r, int fd, char *ptr, size_t len)
void putch(unsigned char c)