aboutsummaryrefslogtreecommitdiffstats
path: root/util/system/compat.cpp
blob: 5b9b17f53f96b103ad92f86cac2d542f21a891bc (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
#include "compat.h"
#include "progname.h"

#include <util/generic/string.h>

#ifdef _win_
    #include "winint.h"
    #include <io.h>
#endif

#ifndef HAVE_NATIVE_GETPROGNAME
const char* getprogname() {
    return GetProgramName().data();
}
#endif

#ifdef _win_

void sleep(i64 len) {
    Sleep((unsigned long)len * 1000);
}

void usleep(i64 len) {
    Sleep((unsigned long)len / 1000);
}

    #include <fcntl.h>
int ftruncate(int fd, i64 length) {
    return _chsize_s(fd, length);
}
int truncate(const char* name, i64 length) {
    int fd = ::_open(name, _O_WRONLY);
    int ret = ftruncate(fd, length);
    ::close(fd);
    return ret;
}
#endif