diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2020-12-14 18:25:28 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-12-14 18:25:28 +0100 |
commit | fd3c512f88d43e6633bd3c3110cfa0bb321adaa8 (patch) | |
tree | 97211484388a0db0a85957f2e3f3724cb1c9159f /libbb/xfuncs_printf.c | |
parent | db793480cb8ec3e5f878d1ec18b6ed5010c85e85 (diff) | |
download | busybox-w32-fd3c512f88d43e6633bd3c3110cfa0bb321adaa8.tar.gz busybox-w32-fd3c512f88d43e6633bd3c3110cfa0bb321adaa8.tar.bz2 busybox-w32-fd3c512f88d43e6633bd3c3110cfa0bb321adaa8.zip |
libbb: create and use mmap() helpers
function old new delta
mmap_anon - 22 +22
mmap_read - 21 +21
xmmap_anon - 16 +16
rpm_gettags 465 447 -18
bb_full_fd_action 498 480 -18
uevent_main 337 310 -27
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 0/3 up/down: 59/-63) Total: -4 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/xfuncs_printf.c')
-rw-r--r-- | libbb/xfuncs_printf.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/libbb/xfuncs_printf.c b/libbb/xfuncs_printf.c index fcc798662..db40e996b 100644 --- a/libbb/xfuncs_printf.c +++ b/libbb/xfuncs_printf.c | |||
@@ -111,6 +111,27 @@ void* FAST_FUNC xmemdup(const void *s, int n) | |||
111 | return memcpy(xmalloc(n), s, n); | 111 | return memcpy(xmalloc(n), s, n); |
112 | } | 112 | } |
113 | 113 | ||
114 | void* FAST_FUNC mmap_read(int fd, size_t size) | ||
115 | { | ||
116 | return mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); | ||
117 | } | ||
118 | |||
119 | void* FAST_FUNC mmap_anon(size_t size) | ||
120 | { | ||
121 | return mmap(NULL, size, | ||
122 | PROT_READ | PROT_WRITE, | ||
123 | MAP_PRIVATE | MAP_ANONYMOUS, | ||
124 | /* ignored: */ -1, 0); | ||
125 | } | ||
126 | |||
127 | void* FAST_FUNC xmmap_anon(size_t size) | ||
128 | { | ||
129 | void *p = mmap_anon(size); | ||
130 | if (p == MAP_FAILED) | ||
131 | bb_die_memory_exhausted(); | ||
132 | return p; | ||
133 | } | ||
134 | |||
114 | // Die if we can't open a file and return a FILE* to it. | 135 | // Die if we can't open a file and return a FILE* to it. |
115 | // Notice we haven't got xfread(), This is for use with fscanf() and friends. | 136 | // Notice we haven't got xfread(), This is for use with fscanf() and friends. |
116 | FILE* FAST_FUNC xfopen(const char *path, const char *mode) | 137 | FILE* FAST_FUNC xfopen(const char *path, const char *mode) |