-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutils.hpp
More file actions
32 lines (26 loc) · 757 Bytes
/
utils.hpp
File metadata and controls
32 lines (26 loc) · 757 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
#pragma once
#include <stdio.h>
#ifdef __IDP__
#include <pro.h>
#include <loader.hpp>
inline qstring get_idb_path() { return get_path(PATH_TYPE_IDB); }
#endif
/*
* Hash function (djb2) by Dan Bernstein.
* Source: Originally described in comp.lang.c
* This implementation is based on the description of the algorithm.
*/
inline unsigned long djb2(const char* str) {
unsigned long hash = 5381;
int c;
while ((c = *str++))
hash = ((hash << 5) + hash) + c; /* hash * 33 + c */
return hash;
}
inline void make_semaphore_name(const char* string, char* out, size_t out_size) {
#ifdef __IDP__
qsnprintf(out, out_size, "ejectidb_%08lx", djb2(string));
#else
snprintf(out, out_size, "ejectidb_%08lx", djb2(string));
#endif
}