Skip to content

Commit e1636d0

Browse files
yamtgeky
authored andcommitted
Add an alternative way to override LFS_MALLOC etc
With the existing method, (-DLFS_MALLOC=my_malloc) users often had to use compiler options like -include, which was not so portable. This change introduces another way to provide partial overrides of lfs_util.h using a user-provided header.
1 parent b78afe2 commit e1636d0

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

lfs_util.h

+20-2
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,36 @@
88
#ifndef LFS_UTIL_H
99
#define LFS_UTIL_H
1010

11+
#define LFS_STRINGIZE(x) LFS_STRINGIZE2(x)
12+
#define LFS_STRINGIZE2(x) #x
13+
1114
// Users can override lfs_util.h with their own configuration by defining
1215
// LFS_CONFIG as a header file to include (-DLFS_CONFIG=lfs_config.h).
1316
//
1417
// If LFS_CONFIG is used, none of the default utils will be emitted and must be
1518
// provided by the config file. To start, I would suggest copying lfs_util.h
1619
// and modifying as needed.
1720
#ifdef LFS_CONFIG
18-
#define LFS_STRINGIZE(x) LFS_STRINGIZE2(x)
19-
#define LFS_STRINGIZE2(x) #x
2021
#include LFS_STRINGIZE(LFS_CONFIG)
2122
#else
2223

24+
// Alternatively, users can provide a header file which defines
25+
// macros and other things consumed by littlefs.
26+
//
27+
// For example, provide my_defines.h, which contains
28+
// something like:
29+
//
30+
// #include <stddef.h>
31+
// extern void *my_malloc(size_t sz);
32+
// #define LFS_MALLOC(sz) my_malloc(sz)
33+
//
34+
// And build littlefs with the header by defining LFS_USER_DEFINES.
35+
// (-DLFS_USER_DEFINES=my_defines.h)
36+
37+
#ifdef LFS_USER_DEFINES
38+
#include LFS_STRINGIZE(LFS_USER_DEFINES)
39+
#endif
40+
2341
// System includes
2442
#include <stdint.h>
2543
#include <stdbool.h>

0 commit comments

Comments
 (0)