#include #include #include #include #include "inc/priv.h" #include "inc/time.h" u64int sec_realtime(void) { struct timeval now; if(gettimeofday(&now, nil) != 0) return 0; return (u64int)now.tv_sec*1000000000ULL + (u64int)now.tv_usec*1000ULL; } u64int nanosec_monotonic(void) { static u64int t0; if(t0 == 0) t0 = sec_realtime(); return sec_realtime() - t0; } void timestr(u64int ns, char *buf, int sz) { time_t tme = ns/Nsec; struct tm tm; *buf = 0; if(localtime_r(&tme, &tm) != nil) strftime(buf, sz, "%a %b %e %H:%M:%S %Y", &tm); } u64int parsetime(const char *s) { USED(s); return 0; } void sleep_ms(int ms) { USED(ms); } int ftruncate(int f, soffset sz) { USED(f); USED(sz); return -1; } char * sys_getcwd(void) { return nil; } int sys_chdir(int fd, const char *path) { USED(fd); USED(path); return -1; } int sys_mkdir(const char *path, usize mode) { USED(path); USED(mode); return -1; } int access(const char *path, int amode) { USED(path); USED(amode); return -1; } void sys_seed(void *p, int sz) { u64int r = sec_realtime(); u8int *o = p; for(; sz > 0; r >>= 8, sz--) *o++ = r & 0xff; } int sys_read(int fd, u8int *buf, usize n, usize *nread) { ssize r; while(1){ r = read(fd, buf, n); if(r > -1){ *nread = (usize)r; break; } return r; } return 0; } int sys_write(int fd, const void *buf, usize n, usize *nwritten) { ssize r = write(fd, buf, n); if(r < 0) return -1; *nwritten = (usize)r; return 0; } int sys_open(const char *fname, ios_flags flags, usize mode) { int of = (flags & IOS_WRITE) ? ((flags & IOS_READ) ? O_RDWR : O_WRONLY) : O_RDONLY; if(flags & IOS_TRUNC) of |= O_TRUNC; if(flags & IOS_CREATE) of |= O_CREAT; if(flags & IOS_APPEND) of |= O_APPEND; if(flags & IOS_EXCL) of |= O_EXCL; return open(fname, of, mode); } void sys_fd_setup(int fd) { USED(fd); } int sys_rename(const char *old, const char *new) { return rename(old, new); } soffset sys_seek(int fd, soffset offset, int whence) { return lseek(fd, offset, whence); } int sys_close(int fd) { return close(fd); } void sys_init(void) { } char os_version[12]; static const u8int boot[] = { #include "sl.boot.h" }; int main(int argc, char **argv) { static SysEnvRec r; memset(&r, 0, sizeof(r)); SysEnvirons(2, &r); snprintf( os_version, sizeof(boot), "%d.%d.%d", r.systemVersion>>8, (r.systemVersion>>4)&0xf, (r.systemVersion>>0)&0xf ); slmain(boot, sizeof(boot), argc, argv); }