forked from derat/xsettingsd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.cc
More file actions
38 lines (29 loc) · 916 Bytes
/
common.cc
File metadata and controls
38 lines (29 loc) · 916 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
// Copyright 2009 Daniel Erat <dan@erat.org>
// All rights reserved.
#include "common.h"
#include <cstdarg>
#include <cstdio>
using std::string;
namespace xsettingsd {
std::string StringPrintf(const char* format, ...) {
char buffer[1024];
va_list argp;
va_start(argp, format);
vsnprintf(buffer, sizeof(buffer), format, argp);
va_end(argp);
return std::string(buffer);
}
bool IsLittleEndian() {
int i = 1;
return reinterpret_cast<char*>(&i)[0];
}
int GetPadding(int length, int increment) {
return (increment - (length % increment)) % increment;
// From xsettings-common.h in Owen Taylor's reference implementation --
// "n" is length and "m" is increment, I think. This produces results
// that don't seem like padding, though: when "n" is 2 and "m" is 4, it
// produces 4.
//return ((n + m - 1) & (~(m - 1)));
}
const char* kProgName = "xsettingsd";
} // namespace xsettingsd