[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH for-2.2 1/3] block/raw-posix: Fix preallocating writ
From: |
Max Reitz |
Subject: |
[Qemu-devel] [PATCH for-2.2 1/3] block/raw-posix: Fix preallocating write() loop |
Date: |
Tue, 18 Nov 2014 11:23:04 +0100 |
write() may write less bytes than requested; in this case, the number of
bytes written is returned. This is the byte count we should be
subtracting from the number of bytes still to be written, and not the
byte count we requested to write.
Reported-by: László Érsek <address@hidden>
Signed-off-by: Max Reitz <address@hidden>
---
An interesting anecdote: My German man page for write(2) says the
following about its return value:
> Bei Erfolg wird Null zurückgegeben.
Which translates to:
> On success, zero is returned.
Whereas write(2) for LANG=C says the following (which is correct):
> On success, the number of bytes written is returned (zero indicates
> nothing was written).
I think I know why I somehow prefer the English versions...
---
block/raw-posix.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/block/raw-posix.c b/block/raw-posix.c
index e100ae2..4e6552f 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1457,7 +1457,7 @@ static int raw_create(const char *filename, QemuOpts
*opts, Error **errp)
"Could not write to the new file");
break;
}
- left -= num;
+ left -= result;
}
fsync(fd);
g_free(buf);
--
1.9.3