Skip to content

Commit

Permalink
Merge pull request #1004 from yamt/user-define-header
Browse files Browse the repository at this point in the history
Add an alternative way to override LFS_MALLOC etc
  • Loading branch information
geky authored Dec 6, 2024
2 parents bd01a4c + 4a845be commit c961e1f
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions lfs_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,36 @@
#ifndef LFS_UTIL_H
#define LFS_UTIL_H

#define LFS_STRINGIZE(x) LFS_STRINGIZE2(x)
#define LFS_STRINGIZE2(x) #x

// Users can override lfs_util.h with their own configuration by defining
// LFS_CONFIG as a header file to include (-DLFS_CONFIG=lfs_config.h).
//
// If LFS_CONFIG is used, none of the default utils will be emitted and must be
// provided by the config file. To start, I would suggest copying lfs_util.h
// and modifying as needed.
#ifdef LFS_CONFIG
#define LFS_STRINGIZE(x) LFS_STRINGIZE2(x)
#define LFS_STRINGIZE2(x) #x
#include LFS_STRINGIZE(LFS_CONFIG)
#else

// Alternatively, users can provide a header file which defines
// macros and other things consumed by littlefs.
//
// For example, provide my_defines.h, which contains
// something like:
//
// #include <stddef.h>
// extern void *my_malloc(size_t sz);
// #define LFS_MALLOC(sz) my_malloc(sz)
//
// And build littlefs with the header by defining LFS_DEFINES.
// (-DLFS_DEFINES=my_defines.h)

#ifdef LFS_DEFINES
#include LFS_STRINGIZE(LFS_DEFINES)
#endif

// System includes
#include <stdint.h>
#include <stdbool.h>
Expand Down

0 comments on commit c961e1f

Please sign in to comment.