utime.c 469 B

123456789101112131415161718192021222324252627282930
  1. #include "lib.h"
  2. #include <sys/types.h>
  3. #include <time.h>
  4. #include <utime.h>
  5. #include <errno.h>
  6. #include <stdlib.h>
  7. #include "sys9.h"
  8. #include "dir.h"
  9. int
  10. utime(const char *path, const struct utimbuf *times)
  11. {
  12. int n;
  13. Dir nd;
  14. time_t curt;
  15. _nulldir(&nd);
  16. if(times == 0) {
  17. curt = time(0);
  18. nd.atime = curt;
  19. nd.mtime = curt;
  20. } else {
  21. nd.atime = times->actime;
  22. nd.mtime = times->modtime;
  23. }
  24. n = _dirwstat(path, &nd);
  25. if(n < 0)
  26. _syserrno();
  27. return n;
  28. }