diff options
author | Devtools Arcadia <[email protected]> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <[email protected]> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /util/system/sysstat.cpp |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'util/system/sysstat.cpp')
-rw-r--r-- | util/system/sysstat.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/util/system/sysstat.cpp b/util/system/sysstat.cpp new file mode 100644 index 00000000000..db3338b02e4 --- /dev/null +++ b/util/system/sysstat.cpp @@ -0,0 +1,47 @@ +#include "sysstat.h" + +#ifdef _win_ + + #include "winint.h" + #include <errno.h> + +int Chmod(const char* fname, int mode) { + if (!fname) { + errno = EINVAL; + return -1; + } + ui32 fAttr = ::GetFileAttributesA(fname); + if (fAttr == 0xffffffff) + return -1; + if (mode & _S_IWRITE) { + fAttr &= ~FILE_ATTRIBUTE_READONLY; + } else { + fAttr |= FILE_ATTRIBUTE_READONLY; + } + if (!::SetFileAttributesA(fname, fAttr)) { + return -1; + } + return 0; +} + +int Mkdir(const char* path, int /*mode*/) { + errno = 0; + if (!path) { + errno = EINVAL; + return -1; + } + if (!CreateDirectoryA(path, (LPSECURITY_ATTRIBUTES) nullptr)) { + ui32 errCode = GetLastError(); + if (errCode == ERROR_ALREADY_EXISTS) { + errno = EEXIST; + } else if (errCode == ERROR_PATH_NOT_FOUND) { + errno = ENOENT; + } else { + errno = EINVAL; + } + return -1; + } + return 0; +} + +#endif |