stat.c 549 B

1234567891011121314151617181920212223242526272829
  1. #include <stdint.h>
  2. #include <errno.h>
  3. #include <syscall.h>
  4. #include <sys/stat.h>
  5. int stat(const char* pathname, struct stat* statbuf)
  6. {
  7. int ret = syscall2(SYS_stat, (uint32_t)pathname, (uint32_t)statbuf);
  8. if (ret < 0) {
  9. errno = -ret;
  10. return -1;
  11. }
  12. return ret;
  13. }
  14. int fstat(int fd, struct stat* statbuf)
  15. {
  16. int ret = syscall2(SYS_fstat, fd, (uint32_t)statbuf);
  17. if (ret < 0) {
  18. errno = -ret;
  19. return -1;
  20. }
  21. return ret;
  22. }
  23. mode_t umask(mode_t mask)
  24. {
  25. return syscall1(SYS_umask, mask);
  26. }