aboutsummaryrefslogtreecommitdiff
path: root/libbb
diff options
context:
space:
mode:
Diffstat (limited to 'libbb')
-rw-r--r--libbb/copyfd.c5
-rw-r--r--libbb/xfuncs_printf.c21
2 files changed, 22 insertions, 4 deletions
diff --git a/libbb/copyfd.c b/libbb/copyfd.c
index d41fd10f0..7f9d92ea9 100644
--- a/libbb/copyfd.c
+++ b/libbb/copyfd.c
@@ -75,10 +75,7 @@ static off_t bb_full_fd_action(int src_fd, int dst_fd, off_t size)
75 goto use_small_buf; 75 goto use_small_buf;
76 /* We want page-aligned buffer, just in case kernel is clever 76 /* We want page-aligned buffer, just in case kernel is clever
77 * and can do page-aligned io more efficiently */ 77 * and can do page-aligned io more efficiently */
78 buffer = mmap(NULL, CONFIG_FEATURE_COPYBUF_KB * 1024, 78 buffer = mmap_anon(CONFIG_FEATURE_COPYBUF_KB * 1024);
79 PROT_READ | PROT_WRITE,
80 MAP_PRIVATE | MAP_ANON,
81 /* ignored: */ -1, 0);
82 buffer_size = CONFIG_FEATURE_COPYBUF_KB * 1024; 79 buffer_size = CONFIG_FEATURE_COPYBUF_KB * 1024;
83 if (buffer == MAP_FAILED) { 80 if (buffer == MAP_FAILED) {
84 use_small_buf: 81 use_small_buf:
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
114void* FAST_FUNC mmap_read(int fd, size_t size)
115{
116 return mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
117}
118
119void* 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
127void* 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.
116FILE* FAST_FUNC xfopen(const char *path, const char *mode) 137FILE* FAST_FUNC xfopen(const char *path, const char *mode)