From 2154de1cf36c0ac741f258f72de6895e8782ec79 Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Wed, 14 Apr 2021 15:23:52 +0200 Subject: bareboximd: Use mmap when possibly It's hard to believe but there are systems out there that are so sparse with memory that they can't afford 1MiB of RAM to read a file into. Use mmap when possible and fall back to reading into an allocated buffer otherwise. Signed-off-by: Sascha Hauer --- common/imd.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'common/imd.c') diff --git a/common/imd.c b/common/imd.c index aff3b00b6b..e1d5733c6b 100644 --- a/common/imd.c +++ b/common/imd.c @@ -17,6 +17,10 @@ int imd_command_setenv(const char *variable_name, const char *value) return -ENOSYS; } #endif +static inline void read_file_2_free(void *buf) +{ + free(buf); +} #endif /* @@ -542,6 +546,6 @@ int imd_command(int argc, char *argv[]) ret = 0; out: - free(buf); + read_file_2_free(buf); return ret; } -- cgit v1.2.3