| 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 |
|
| 5 |
#include <dirent.h> |
| 6 |
|
| 7 |
#include "runtime.h" |
| 8 |
|
| 9 |
unsigned char direntType (struct dirent *) |
| 10 |
__asm__ (GOSYM_PREFIX "os.direntType"); |
| 11 |
|
| 12 |
unsigned char |
| 13 |
direntType (struct dirent *p __attribute__((unused))) |
| 14 |
{ |
| 15 |
#ifndef HAVE_STRUCT_DIRENT_D_TYPE |
| 16 |
return 'U'; |
| 17 |
#else |
| 18 |
switch (p->d_type) |
| 19 |
{ |
| 20 |
#ifdef DT_BLK |
| 21 |
case DT_BLK: |
| 22 |
return 'B'; |
| 23 |
#endif |
| 24 |
#ifdef DT_CHR |
| 25 |
case DT_CHR: |
| 26 |
return 'C'; |
| 27 |
#endif |
| 28 |
#ifdef DT_DBF |
| 29 |
case DT_DBF: |
| 30 |
// Database record file. |
| 31 |
// Treat as regular file. |
| 32 |
return 'R'; |
| 33 |
#endif |
| 34 |
#ifdef DT_DIR |
| 35 |
case DT_DIR: |
| 36 |
return 'D'; |
| 37 |
#endif |
| 38 |
#ifdef DT_FIFO |
| 39 |
case DT_FIFO: |
| 40 |
return 'F'; |
| 41 |
#endif |
| 42 |
#ifdef DT_LNK |
| 43 |
case DT_LNK: |
| 44 |
return 'L'; |
| 45 |
#endif |
| 46 |
#ifdef DT_REG |
| 47 |
case DT_REG: |
| 48 |
return 'R'; |
| 49 |
#endif |
| 50 |
#ifdef DT_SOCK |
| 51 |
case DT_SOCK: |
| 52 |
return 'S'; |
| 53 |
#endif |
| 54 |
default: |
| 55 |
return 'U'; |
| 56 |
} |
| 57 |
#endif /* HAVE_DIRENT_D_TYPE */ |
| 58 |
} |