This makes the following do the expected thing:
barebox@barebox sandbox:/ ls -l lala
-rwxrwxrwx 4 lala
barebox@barebox sandbox:/ mw -d lala 72 0
Without this patch mw dies with
lseek: Invalid argument
memset, memcpy and probably others benefit in the same way.
Signed-off-by: Uwe Kleine-König <[email protected]>
---
lib/libfile.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
diff --git a/lib/libfile.c b/lib/libfile.c
index 83c6399a5b39..01c59cdb80fe 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -510,6 +510,24 @@ int open_and_lseek(const char *filename, int mode, loff_t
pos)
if (!pos)
return fd;
+ if (mode & (O_WRONLY | O_RDWR)) {
+ struct stat s;
+
+ ret = fstat(fd, &s);
+ if (ret) {
+ perror("ftruncate");
+ return ret;
+ }
+
+ if (s.st_size < pos) {
+ ret = ftruncate(fd, pos);
+ if (ret) {
+ perror("ftruncate");
+ return ret;
+ }
+ }
+ }
+
ret = lseek(fd, pos, SEEK_SET);
if (ret == -1) {
perror("lseek");
--
2.18.0
_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox