Skip to content

Commit 09362ee

Browse files
committed
Applied formatting according to clangd, fixed cmakelists
1 parent 8ce19a3 commit 09362ee

File tree

16 files changed

+1147
-950
lines changed

16 files changed

+1147
-950
lines changed

.clang-format

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
IndentWidth: 4
2+
BreakBeforeBraces: Custom
3+
BraceWrapping:
4+
AfterFunction: true
5+
AlignConsecutiveMacros:
6+
Enabled: true
7+
AcrossEmptyLines: true
8+
AcrossComments: true
9+
AlignConsecutiveAssignments:
10+
Enabled: true
11+
AcrossEmptyLines: true
12+
AcrossComments: true

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ set(LICENSE "BSD2 license")
2020
add_executable(llb ${SOURCES} include/llb_internal.h)
2121

2222
if (APPLE)
23-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I/usr/local/opt/openssl/include")
24-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/usr/local/opt/openssl/include")
25-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/usr/local/opt/openssl/lib")
23+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -I/opt/homebrew/opt/openssl@3/include")
24+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I/opt/homebrew/opt/openssl@3/include")
25+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L/opt/homebrew/opt/openssl@3/lib")
2626
endif (APPLE)
2727

2828
if (DEBUG)

include/llb_internal.h

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@
2828
#ifndef LLB_INTERNAL
2929
#define LLB_INTERNAL
3030

31+
#include <assert.h>
3132
#include <stdio.h>
3233
#include <stdlib.h>
3334
#include <unistd.h>
34-
#include <assert.h>
3535

36-
#define RANDOM(A,B) A + rand()/(RAND_MAX/(B - A))
36+
#define RANDOM(A, B) A + rand() / (RAND_MAX / (B - A))
3737

3838
/* Load-balancing mode */
39-
#define LLB_TCP_MODE 0
40-
#define LLB_HTTP_MODE 1
39+
#define LLB_TCP_MODE 0
40+
#define LLB_HTTP_MODE 1
4141

42-
#define LLB_SUCCESS 0
43-
#define LLB_FAILURE -1
42+
#define LLB_SUCCESS 0
43+
#define LLB_FAILURE -1
4444

4545
/* Load-balancing algorithms */
4646
#define ROUND_ROBIN 0
@@ -50,46 +50,48 @@
5050
#define LEASTTRAFFIC 4
5151
#define WEIGHTED_ROUND_ROBIN 5
5252

53-
static inline void *llb_malloc(size_t size) {
53+
static inline void *llb_malloc(size_t size)
54+
{
5455
void *ptr = malloc(size);
5556
if (!ptr && size != 0) {
56-
fprintf(stderr, "[%s:%ul] Out of memory (%lu bytes)\n",
57-
__FILE__, __LINE__, size);
57+
fprintf(stderr, "[%s:%ul] Out of memory (%lu bytes)\n", __FILE__,
58+
__LINE__, size);
5859
exit(EXIT_FAILURE);
5960
}
6061
return ptr;
6162
}
6263

63-
static inline void *llb_calloc(size_t n, size_t size) {
64+
static inline void *llb_calloc(size_t n, size_t size)
65+
{
6466
void *ptr = calloc(n, size);
6567
if (!ptr && size != 0 && n != 0) {
66-
fprintf(stderr, "[%s:%ul] Out of memory (%lu bytes)\n",
67-
__FILE__, __LINE__, size);
68+
fprintf(stderr, "[%s:%ul] Out of memory (%lu bytes)\n", __FILE__,
69+
__LINE__, size);
6870
exit(EXIT_FAILURE);
6971
}
7072
return ptr;
7173
}
7274

73-
static inline void *llb_realloc(void *ptr, size_t size) {
75+
static inline void *llb_realloc(void *ptr, size_t size)
76+
{
7477
assert(ptr && size > 0);
7578
void *new_ptr = realloc(ptr, size);
7679
if (!new_ptr && size != 0) {
77-
fprintf(stderr, "[%s:%ul] Out of memory (%lu bytes)\n",
78-
__FILE__, __LINE__, size);
80+
fprintf(stderr, "[%s:%ul] Out of memory (%lu bytes)\n", __FILE__,
81+
__LINE__, size);
7982
exit(EXIT_FAILURE);
8083
}
8184
return new_ptr;
8285
}
8386

84-
static inline void llb_free(void *ptr) {
85-
free(ptr);
86-
}
87+
static inline void llb_free(void *ptr) { free(ptr); }
8788

8889
/* D. J. Bernstein hash function */
89-
static inline size_t djb_hash(const char *str) {
90+
static inline size_t djb_hash(const char *str)
91+
{
9092
size_t hash = 5381;
9193
while (*str)
92-
hash = 33 * hash ^ (unsigned char) *str++;
94+
hash = 33 * hash ^ (unsigned char)*str++;
9395
return hash;
9496
}
9597

0 commit comments

Comments
 (0)