Skip to content

Commit

Permalink
cookie: Pull gen_cookie definition to own source file
Browse files Browse the repository at this point in the history
  • Loading branch information
obiwac committed Dec 24, 2024
1 parent 5e792bb commit 93b96b2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
28 changes: 28 additions & 0 deletions src/cookie.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-License-Identifier: MIT
// Copyright (c) 2024 Aymeric Wibo

#include <common.h>

#include <cookie.h>
#include <str.h>

#include <assert.h>
#include <inttypes.h>
#include <stdio.h>
#include <string.h>

char* gen_cookie(char* path, size_t path_size, char const* ext) {
char* cookie = NULL;
asprintf(&cookie, "%s/bob/%.*s.cookie.%" PRIx64 ".%s", out_path, (int) path_size, path, str_hash(path, path_size), ext);
assert(cookie != NULL);

size_t const prefix_len = strlen(out_path) + strlen("/bob/");

for (size_t i = prefix_len; i < prefix_len + path_size; i++) {
if (cookie[i] == '/') {
cookie[i] = '_';
}
}

return cookie;
}
24 changes: 1 addition & 23 deletions src/cookie.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,6 @@

#pragma once

#include <common.h>

#include <str.h>

#include <assert.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static inline char* gen_cookie(char* path, size_t path_size, char const* ext) {
char* cookie = NULL;
asprintf(&cookie, "%s/bob/%.*s.cookie.%" PRIx64 ".%s", out_path, (int) path_size, path, str_hash(path, path_size), ext);
assert(cookie != NULL);

size_t const prefix_len = strlen(out_path) + strlen("/bob/");

for (size_t i = prefix_len; i < prefix_len + path_size; i++) {
if (cookie[i] == '/') {
cookie[i] = '_';
}
}

return cookie;
}
char* gen_cookie(char* path, size_t path_size, char const* ext);

0 comments on commit 93b96b2

Please sign in to comment.