Skip to content

Commit

Permalink
- coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
aschnell committed Aug 10, 2023
1 parent 487bb0e commit 58dca8e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion client/mksubvolume.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/


#include <string.h>
#include <cstring>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
Expand Down
10 changes: 7 additions & 3 deletions snapper/FileUtils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -405,23 +405,27 @@ namespace snapper
static const char letters[] = "abcdefghijklmnopqrstuvwxyz" "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"0123456789";

const size_t num_letters = strlen(letters);

static uint64_t value;

struct timeval tv;
gettimeofday(&tv, NULL);
value += ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec;

unsigned int attempts = 62 * 62 * 62;
unsigned int attempts = num_letters * num_letters * num_letters;

string::size_type length = name.size();

assert(length >= 6);

for (unsigned int count = 0; count < attempts; value += 7777, ++count)
{
uint64_t v = value;
for (string::size_type i = length - 6; i < length; ++i)
{
name[i] = letters[v % 62];
v /= 62;
name[i] = letters[v % num_letters];
v /= num_letters;
}

int fd = open(name, O_RDWR | O_CREAT | O_EXCL | O_CLOEXEC, S_IRUSR | S_IWUSR);
Expand Down

0 comments on commit 58dca8e

Please sign in to comment.