-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuutil.cpp
More file actions
39 lines (34 loc) · 699 Bytes
/
Copy pathuutil.cpp
File metadata and controls
39 lines (34 loc) · 699 Bytes
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
#include <time.h>
#include <QUuid>
#include <QDebug>
#include <QDateTime>
#include <QHostInfo>
#include "uutil.h"
#ifdef Q_OS_WIN
#include <Winsock2.h>
#else
#include <unistd.h>
#endif
QString uUtil::hostname()
{
// hostnames cannot be longer than 255 characters + NL
char buf[256] = {"\0"};
if (0 == gethostname(buf, 256))
{
return buf;
}
return QHostInfo::localHostName();
}
QString uUtil::uuid()
{
QString uuid = QUuid::createUuid().toString();
return uuid.mid(1, uuid.size() - 2); // remove curly brackets
}
uint uUtil::timeUTC()
{
time_t rawtime;
struct tm *ptm;
time(&rawtime);
ptm = gmtime(&rawtime);
return mktime(ptm);
}