Skip to content

Commit 1476181

Browse files
committed
Added LFS_CONFIG for user provided configuration of the utils
Suggested by sn00pster, LFS_CONFIG is an opt-in user provided configuration file that will override the util implementation in lfs_util.h. This is useful for allowing system-specific overrides without needing to rely on git merges or other forms of patching for updates.
1 parent b2124a5 commit 1476181

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lfs_util.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
*/
1818
#include "lfs_util.h"
1919

20+
// Only compile if user does not provide custom config
21+
#ifndef LFS_CONFIG
2022

23+
24+
// Software CRC implementation with small lookup table
2125
void lfs_crc(uint32_t *restrict crc, const void *buffer, size_t size) {
2226
static const uint32_t rtable[16] = {
2327
0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac,
@@ -34,3 +38,5 @@ void lfs_crc(uint32_t *restrict crc, const void *buffer, size_t size) {
3438
}
3539
}
3640

41+
42+
#endif

lfs_util.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@
1818
#ifndef LFS_UTIL_H
1919
#define LFS_UTIL_H
2020

21+
// Users can override lfs_util.h with their own configuration by defining
22+
// LFS_CONFIG as a header file to include (-DLFS_CONFIG=lfs_config.h).
23+
//
24+
// If LFS_CONFIG is used, none of the default utils will be emitted and must be
25+
// provided by the config file. To start I would suggest copying lfs_util.h and
26+
// modifying as needed.
27+
#ifdef LFS_CONFIG
28+
#define LFS_STRINGIZE(x) LFS_STRINGIZE2(x)
29+
#define LFS_STRINGIZE2(x) #x
30+
#include LFS_STRINGIZE(LFS_CONFIG)
31+
#else
32+
33+
// System includes
2134
#include <stdint.h>
2235
#include <stdbool.h>
2336
#include <string.h>
@@ -169,3 +182,4 @@ static inline void lfs_free(void *p) {
169182

170183

171184
#endif
185+
#endif

0 commit comments

Comments
 (0)