Home
posix.c - scc - simple c99 compiler HTML git clone git://git.simple-cc.org/scc DIR Log DIR Files DIR Refs DIR Submodules DIR README DIR LICENSE --- posix.c (947B) --- 1 #include <sys/types.h> 2 #include <sys/time.h> 3 #include <sys/stat.h> 4 #include <string.h> 5 #include <unistd.h> 6 #include <utime.h> 7 8 #include <limits.h> 9 10 #include "sys.h" 11 12 const char invalidchars[] = " "; 13 14 time_t 15 totime(long long t) 16 { 17 return t; 18 } 19 20 char * 21 canonical(char *path) 22 { 23 char *name = strrchr(path, '/'); 24 return (name && name[1]) ? name+1 : path; 25 } 26 27 int 28 getstat(char *fname, struct fprop *prop) 29 { 30 struct stat st; 31 32 if (stat(fname, &st) < 0) 33 return -1; 34 if (st.st_size > LONG_MAX) 35 return -1; 36 prop->uid = st.st_uid; 37 prop->gid = st.st_gid; 38 prop->mode = st.st_mode; 39 prop->time = st.st_mtime; 40 prop->size = st.st_size; 41 42 return 0; 43 } 44 45 int 46 setstat(char *fname, struct fprop *prop) 47 { 48 struct utimbuf ut = {prop->time, prop->time}; 49 50 if (chown(fname, prop->uid, prop->gid) < 0) { 51 if (chown(fname, getuid(), getgid()) < 0) 52 return -1; 53 } 54 if (chmod(fname, prop->mode) < 0) 55 return -1; 56 if (utime(fname, &ut) < 0) 57 return -1; 58 return 0; 59 }