scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

setstat-posix.c (408B)


      1 #include <sys/stat.h>
      2 #include <unistd.h>
      3 #include <utime.h>
      4 
      5 #include <time.h>
      6 
      7 #include <scc/scc.h>
      8 
      9 int
     10 setstat(char *fname, struct fprop *prop)
     11 {
     12 	struct utimbuf ut = {prop->time, prop->time};
     13 
     14 	if (chown(fname, prop->uid, prop->gid) < 0) {
     15 		if (chown(fname, getuid(), getgid()) < 0)
     16 			return -1;
     17 	}
     18 	if (chmod(fname, prop->mode) < 0)
     19 		return -1;
     20 	if (utime(fname, &ut) < 0)
     21 		return -1;
     22 	return 0;
     23 }