mwrap (Perl version) user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
* [PATCH] mymalloc: use ftruncate(2) when creating a sparse file
@ 2023-01-03  7:25 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2023-01-03  7:25 UTC (permalink / raw)
  To: mwrap-perl

Unlike pwrite(2), it won't dirty the last page, and it's fewer
arguments so argument passing is simpler.
---
 mymalloc.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/mymalloc.h b/mymalloc.h
index e781b43..eda669f 100644
--- a/mymalloc.h
+++ b/mymalloc.h
@@ -69,9 +69,9 @@ static void *my_mmap(size_t size)
 	if (fd < 0) {
 		flags |= MAP_ANONYMOUS;
 	} else {
-		ssize_t w = pwrite(fd, "", 1, size - 1); /* sparse file */
+		int t = ftruncate(fd, size); /* sparse file */
 
-		if (w <= 0) { /* 0 may be ENOSPC */
+		if (t < 0) {
 			flags |= MAP_ANONYMOUS;
 			close(fd);
 			fd = -1;

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-01-03  7:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-03  7:25 [PATCH] mymalloc: use ftruncate(2) when creating a sparse file Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mwrap-perl.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).