PostgreSQL Source Code: src/port/pgcheckdir.c Source File (original) (raw)

Go to the documentation of this file.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16#include "c.h"

17

19

20

21

22

23

24

25

26

27

28

29

30

31

32int

34{

35 int result = 1;

36 DIR *chkdir;

38 bool dot_found = false;

39 bool mount_found = false;

40 int readdir_errno;

41

43 if (chkdir == NULL)

44 return (errno == ENOENT) ? 0 : -1;

45

46 while (errno = 0, (file = readdir(chkdir)) != NULL)

47 {

48 if (strcmp(".", file->d_name) == 0 ||

49 strcmp("..", file->d_name) == 0)

50 {

51

52 continue;

53 }

54#ifndef WIN32

55

56 else if (file->d_name[0] == '.')

57 {

58 dot_found = true;

59 }

60

61 else if (strcmp("lost+found", file->d_name) == 0)

62 {

63 mount_found = true;

64 }

65#endif

66 else

67 {

68 result = 4;

69 break;

70 }

71 }

72

73 if (errno)

74 result = -1;

75

76

77 readdir_errno = errno;

79 result = -1;

80 else

81 errno = readdir_errno;

82

83

84 if (result == 1 && mount_found)

85 result = 3;

86

87

88 if (result == 1 && dot_found)

89 result = 2;

90

91 return result;

92}

struct dirent * readdir(DIR *)

DIR * opendir(const char *)

int pg_check_dir(const char *dir)