aboutsummaryrefslogtreecommitdiffstats
path: root/util/system/sysstat.cpp
blob: db3338b02e4c509ad2b1dce14333ca807f7b39da (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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