This library contains code that extends and simplifies different operations
for C language based programs.
Revisión | a824b1efeb950b29ceb31dc32996b4fab32aac38 (tree) |
---|---|
Tiempo | 2022-08-30 00:59:39 |
Autor | Sergey Gusarov <laborer2008@gmai...> |
Commiter | Sergey Gusarov |
test_sys_stat: Fixed crash on windows
@@ -13,6 +13,7 @@ | ||
13 | 13 | |
14 | 14 | #if !defined (CT_NO_OS) |
15 | 15 | |
16 | +# include "ctools/pointer.h" | |
16 | 17 | # include "ctools/trace.h" |
17 | 18 | |
18 | 19 | # ifdef CT_OS_WINDOWS |
@@ -38,16 +39,20 @@ | ||
38 | 39 | # define chmod(name, mode) _chmod(name, mode) |
39 | 40 | # endif |
40 | 41 | |
41 | - const int kChmodResult = chmod(path, mode); | |
42 | + int chmodResult = -1; | |
43 | + | |
44 | + CT_CHECK_PTR_AND_RETURN_RES(path, chmodResult); | |
45 | + | |
46 | + chmodResult = chmod(path, mode); | |
42 | 47 | |
43 | 48 | # ifdef CT_OS_WINDOWS |
44 | 49 | # undef chmod |
45 | 50 | # endif |
46 | 51 | |
47 | - if (kChmodResult != kChModOkResult) | |
48 | - CT_TRACE_ERRORC("chmod() failed (%d) for path \"%s\"", kChmodResult, path); | |
52 | + if (chmodResult != kChModOkResult) | |
53 | + CT_TRACE_ERRORC("chmod() failed (%d) for path \"%s\"", chmodResult, path); | |
49 | 54 | |
50 | - return kChmodResult; | |
55 | + return chmodResult; | |
51 | 56 | } |
52 | 57 | |
53 | 58 | int mkDirWrapper(const char* path, mode_t mode, const bool informAboutError) CT_NOEXCEPT |
@@ -56,7 +61,11 @@ | ||
56 | 61 | # define mkdir(name, mode) _mkdir(name) |
57 | 62 | # endif |
58 | 63 | |
59 | - const int kMkDirResult = mkdir(path, mode); | |
64 | + int mkDirResult = -1; | |
65 | + | |
66 | + CT_CHECK_PTR_AND_RETURN_RES(path, mkDirResult); | |
67 | + | |
68 | + mkDirResult = mkdir(path, mode); | |
60 | 69 | |
61 | 70 | # ifdef CT_OS_WINDOWS |
62 | 71 | CT_UNUSED(mode); |
@@ -64,26 +73,31 @@ | ||
64 | 73 | # endif |
65 | 74 | |
66 | 75 | /* *INDENT-OFF* */ |
67 | - if (kMkDirResult == kMkDirOkResult) | |
76 | + if (mkDirResult == kMkDirOkResult) | |
68 | 77 | CT_TRACE_INFO("Created directory: \"%s\" with mode %u", path, (uint)mode); |
69 | 78 | else |
70 | 79 | { |
71 | 80 | if (informAboutError) |
72 | - CT_TRACE_ERRORC("mkdir() failed (%d) for path \"%s\" and mode %u ", kMkDirResult, path, (uint)mode); | |
81 | + CT_TRACE_ERRORC("mkdir() failed (%d) for path \"%s\" and mode %u ", mkDirResult, path, (uint)mode); | |
73 | 82 | } |
74 | 83 | /* *INDENT-ON* */ |
75 | 84 | |
76 | - return kMkDirResult; | |
85 | + return mkDirResult; | |
77 | 86 | } |
78 | 87 | |
79 | 88 | int statWrapper(const char* CT_RESTRICT path, struct stat* CT_RESTRICT buf) CT_NOEXCEPT |
80 | 89 | { |
81 | - const int kStatResult = stat(path, buf); | |
90 | + int statResult = -1; | |
82 | 91 | |
83 | - if (kStatResult != kStatOkResult) | |
84 | - CT_TRACE_ERRORC("stat() failed (%d) for path \"%s\"", kStatResult, path); | |
92 | + CT_CHECK_PTR_AND_RETURN_RES(path, statResult); | |
93 | + CT_CHECK_PTR_AND_RETURN_RES(buf, statResult); | |
85 | 94 | |
86 | - return kStatResult; | |
95 | + statResult = stat(path, buf); | |
96 | + | |
97 | + if (statResult != kStatOkResult) | |
98 | + CT_TRACE_ERRORC("stat() failed (%d) for path \"%s\"", statResult, path); | |
99 | + | |
100 | + return statResult; | |
87 | 101 | } |
88 | 102 | |
89 | 103 | CT_END_NAMESPACE |