ref: fd731d3c833d9241fdff618b6c949453fb5c0f31
dir: /unistd.c/
#include <unistd.h> #undef getenv #undef stat char * getenv9(char *s) { static char t[1024]; snprint(t, sizeof(t), "%s", s = getenv(strcmp(s, "HOME") == 0 ? "home" : s)); free(s); return t; } int stat9(char *filename, struct stat9 *buf) { Dir *d; if((d = dirstat(filename)) == nil) return -1; buf->st_size = d->length; buf->st_mode = d->mode; free(d); return 0; } int mkdir(char *path, int perm) { int f; if(access(path, AEXIST) == 0){ werrstr("%s: already exists", path); return -1; } if((f = create(path, OREAD, DMDIR|perm)) < 0){ werrstr("%s: can't create: %r", path); return -1; } close(f); return 0; } int rename(char *old, char *new) { Dir d; nulldir(&d); d.name = new; return dirwstat(old, &d) > 0 ? 0 : -1; } void usleep(unsigned us) { nsleep((uvlong)us*1000ULL); }