aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-12-29 00:08:09 -0500
committerBruce Hill <bruce@bruce-hill.com>2025-12-29 00:08:09 -0500
commit1f13fa92a87bec65d1760266b108a5485bc14c7a (patch)
tree083ae8dfab39209cf5238200518b04cc002ae352 /src
parentfedc4b0ead8f7874120c6e86aaa971a790faea1f (diff)
parent0f9af5f44bd2735f34a48ceb177837a5a6ef25b0 (diff)
Merge branch 'dev' into static-dependencies
Diffstat (limited to 'src')
-rw-r--r--src/stdlib/paths.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/stdlib/paths.c b/src/stdlib/paths.c
index 0e9a14b9..0ef452d2 100644
--- a/src/stdlib/paths.c
+++ b/src/stdlib/paths.c
@@ -337,17 +337,19 @@ typedef struct {
static Result_t _write_bytes_to_fd(List_t bytes, bool close_file, void *userdata) {
writer_data_t *data = userdata;
if (bytes.length > 0) {
- int fd = open(data->path_str, data->mode, data->permissions);
- if (fd == -1) {
- if (errno == EMFILE || errno == ENFILE) {
- // If we hit file handle limits, run GC collection to try to clean up any lingering file handles that
- // will be closed by GC finalizers.
- GC_gcollect();
- fd = open(data->path_str, data->mode, data->permissions);
+ if (data->fd == -1) {
+ data->fd = open(data->path_str, data->mode, data->permissions);
+ if (data->fd == -1) {
+ if (errno == EMFILE || errno == ENFILE) {
+ // If we hit file handle limits, run GC collection to try to clean up any lingering file handles
+ // that will be closed by GC finalizers.
+ GC_gcollect();
+ data->fd = open(data->path_str, data->mode, data->permissions);
+ }
+ if (data->fd == -1)
+ return FailureResult("Could not write to file: ", data->path_str, " (", strerror(errno), ")");
}
- if (fd == -1) return FailureResult("Could not write to file: ", data->path_str, " (", strerror(errno), ")");
}
- data->fd = fd;
if (bytes.stride != 1) List$compact(&bytes, 1);
ssize_t written = write(data->fd, bytes.data, (size_t)bytes.length);