Sigrid Solveig Haflínudóttiradd path-make-dir to create directories98d914e2 months agoHistory
190 lines · 2.5 KB · C
RawDownload
#include <fcntl.h>#include <sys/time.h>#include <time.h>#include <OSUtils.h>#include "inc/priv.h"#include "inc/time.h" u64intsec_realtime(void){	struct timeval now; 	if(gettimeofday(&now, nil) != 0)		return 0;	return (u64int)now.tv_sec*1000000000ULL + (u64int)now.tv_usec*1000ULL;} u64intnanosec_monotonic(void){	static u64int t0;	if(t0 == 0)		t0 = sec_realtime();	return sec_realtime() - t0;} voidtimestr(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);} u64intparsetime(const char *s){	USED(s);	return 0;} voidsleep_ms(int ms){	USED(ms);} intftruncate(int f, soffset sz){	USED(f); USED(sz);	return -1;} char *sys_getcwd(void){	return nil;} intsys_chdir(int fd, const char *path){	USED(fd);	USED(path);	return -1;} intsys_mkdir(const char *path, usize mode){	USED(path);	USED(mode);	return -1;} intaccess(const char *path, int amode){	USED(path); USED(amode);	return -1;} voidsys_seed(void *p, int sz){	u64int r = sec_realtime();	u8int *o = p; 	for(; sz > 0; r >>= 8, sz--)		*o++ = r & 0xff;} intsys_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;} intsys_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;} intsys_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);} voidsys_fd_setup(int fd){	USED(fd);} intsys_rename(const char *old, const char *new){	return rename(old, new);} soffsetsys_seek(int fd, soffset offset, int whence){	return lseek(fd, offset, whence);} intsys_close(int fd){	return close(fd);} voidsys_init(void){} char os_version[12]; static const u8int boot[] = {#include "sl.boot.h"}; intmain(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);}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t