stat.c 594 B

123456789101112131415161718192021222324252627282930
  1. #include <errno.h>
  2. #include <syscall.h>
  3. #include <sys/stat.h>
  4. #include <string.h>
  5. #ifndef syscall_lstat
  6. DECL_SYSCALL2(lstat, char *, void *);
  7. #endif
  8. int stat(const char *file, struct stat *st){
  9. int ret = syscall_stat((char *)file, (void *)st);
  10. if (ret >= 0) {
  11. return ret;
  12. } else {
  13. errno = ENOENT; /* meh */
  14. memset(st, 0x00, sizeof(struct stat));
  15. return ret;;
  16. }
  17. }
  18. int lstat(const char *path, struct stat *st) {
  19. int ret = syscall_lstat((char *)path, (void *)st);
  20. if (ret >= 0) {
  21. return ret;
  22. } else {
  23. errno = -ret;
  24. memset(st, 0x00, sizeof(struct stat));
  25. return ret;
  26. }
  27. }