From 5a28b069c4e37723aebbc80fe1c577a80931cd87 Mon Sep 17 00:00:00 2001 From: CismonX Date: Tue, 29 Apr 2025 14:48:39 +0800 Subject: [PATCH] fs_ops: fix file size opened with O_CREAT|O_TRUNC Also make sure that new regular files always have a size of zero. --- src/backend_firefox.c | 5 ++--- src/fs_ops.c | 6 ++++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/backend_firefox.c b/src/backend_firefox.c index c97b47b..5666d86 100644 --- a/src/backend_firefox.c +++ b/src/backend_firefox.c @@ -398,9 +398,8 @@ bookmark_do_create ( stat_buf->value_len = -1; int64_t place_id = 0; if (!is_dir) { - char const *url = "about:blank"; - stat_buf->value_len = strlen(url); - status = mozplace_addref(ctx, url, stat_buf->value_len, &place_id, + stat_buf->value_len = 0; + status = mozplace_addref(ctx, STR_WITHLEN("about:blank"), &place_id, &stat_buf->atime); if (status < 0) { return status; diff --git a/src/fs_ops.c b/src/fs_ops.c index b88eb13..11791c2 100644 --- a/src/fs_ops.c +++ b/src/fs_ops.c @@ -409,6 +409,12 @@ bm_create ( } } + if (flags & O_TRUNC) { + // See bm_open() for comments on O_RDONLY|O_TRUNC. + if ((flags & O_ACCMODE) != O_RDONLY) { + stat.value_len = 0; + } + } bm_fillstat(&stat, SUBSYS_TYPE_BOOKMARK, false, stat_buf); return 0; }