• R/O
  • SSH

libctools: Commit

This library contains code that extends and simplifies different operations
for C language based programs.


Commit MetaInfo

Revisióna824b1efeb950b29ceb31dc32996b4fab32aac38 (tree)
Tiempo2022-08-30 00:59:39
AutorSergey Gusarov <laborer2008@gmai...>
CommiterSergey Gusarov

Log Message

test_sys_stat: Fixed crash on windows

Cambiar Resumen

Diferencia incremental

diff -r 2a389cb2b486 -r a824b1efeb95 src/std/sys/stat.c
--- a/src/std/sys/stat.c Mon Aug 29 18:52:45 2022 +0300
+++ b/src/std/sys/stat.c Mon Aug 29 18:59:39 2022 +0300
@@ -13,6 +13,7 @@
1313
1414 #if !defined (CT_NO_OS)
1515
16+# include "ctools/pointer.h"
1617 # include "ctools/trace.h"
1718
1819 # ifdef CT_OS_WINDOWS
@@ -38,16 +39,20 @@
3839 # define chmod(name, mode) _chmod(name, mode)
3940 # endif
4041
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);
4247
4348 # ifdef CT_OS_WINDOWS
4449 # undef chmod
4550 # endif
4651
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);
4954
50- return kChmodResult;
55+ return chmodResult;
5156 }
5257
5358 int mkDirWrapper(const char* path, mode_t mode, const bool informAboutError) CT_NOEXCEPT
@@ -56,7 +61,11 @@
5661 # define mkdir(name, mode) _mkdir(name)
5762 # endif
5863
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);
6069
6170 # ifdef CT_OS_WINDOWS
6271 CT_UNUSED(mode);
@@ -64,26 +73,31 @@
6473 # endif
6574
6675 /* *INDENT-OFF* */
67- if (kMkDirResult == kMkDirOkResult)
76+ if (mkDirResult == kMkDirOkResult)
6877 CT_TRACE_INFO("Created directory: \"%s\" with mode %u", path, (uint)mode);
6978 else
7079 {
7180 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);
7382 }
7483 /* *INDENT-ON* */
7584
76- return kMkDirResult;
85+ return mkDirResult;
7786 }
7887
7988 int statWrapper(const char* CT_RESTRICT path, struct stat* CT_RESTRICT buf) CT_NOEXCEPT
8089 {
81- const int kStatResult = stat(path, buf);
90+ int statResult = -1;
8291
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);
8594
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;
87101 }
88102
89103 CT_END_NAMESPACE
Show on old repository browser