dir_gccgo_c.c 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /* Copyright 2020 The Go Authors. All rights reserved.
  2. Use of this source code is governed by a BSD-style
  3. license that can be found in the LICENSE file. */
  4. #include <dirent.h>
  5. #include "runtime.h"
  6. unsigned char direntType (struct dirent *)
  7. __asm__ (GOSYM_PREFIX "os.direntType");
  8. unsigned char
  9. direntType (struct dirent *p __attribute__((unused)))
  10. {
  11. #ifndef HAVE_STRUCT_DIRENT_D_TYPE
  12. return 'U';
  13. #else
  14. switch (p->d_type)
  15. {
  16. #ifdef DT_BLK
  17. case DT_BLK:
  18. return 'B';
  19. #endif
  20. #ifdef DT_CHR
  21. case DT_CHR:
  22. return 'C';
  23. #endif
  24. #ifdef DT_DBF
  25. case DT_DBF:
  26. // Database record file.
  27. // Treat as regular file.
  28. return 'R';
  29. #endif
  30. #ifdef DT_DIR
  31. case DT_DIR:
  32. return 'D';
  33. #endif
  34. #ifdef DT_FIFO
  35. case DT_FIFO:
  36. return 'F';
  37. #endif
  38. #ifdef DT_LNK
  39. case DT_LNK:
  40. return 'L';
  41. #endif
  42. #ifdef DT_REG
  43. case DT_REG:
  44. return 'R';
  45. #endif
  46. #ifdef DT_SOCK
  47. case DT_SOCK:
  48. return 'S';
  49. #endif
  50. default:
  51. return 'U';
  52. }
  53. #endif /* HAVE_DIRENT_D_TYPE */
  54. }