From f23996b445422bdc79b4a16da63c740ae6bddda9 Mon Sep 17 00:00:00 2001
From: Laurent Bercot
Date: Sun, 3 Aug 2025 23:14:12 +0000
Subject: Add mkntemp, atomic_symlink4
Signed-off-by: Laurent Bercot
---
doc/libunixonacid/unix-transactional.html | 17 ++++++++++++
package/deps.mak | 6 +++--
src/include/skalibs/posixplz.h | 1 +
src/include/skalibs/unix-transactional.h | 4 ++-
src/libposixplz/mkntemp.c | 19 ++++++++++++++
src/libunixonacid/atomic_symlink.c | 34 ++----------------------
src/libunixonacid/atomic_symlink4.c | 43 +++++++++++++++++++++++++++++++
7 files changed, 89 insertions(+), 35 deletions(-)
create mode 100644 src/libposixplz/mkntemp.c
create mode 100644 src/libunixonacid/atomic_symlink4.c
diff --git a/doc/libunixonacid/unix-transactional.html b/doc/libunixonacid/unix-transactional.html
index 9a36173..b429001 100644
--- a/doc/libunixonacid/unix-transactional.html
+++ b/doc/libunixonacid/unix-transactional.html
@@ -128,5 +128,22 @@ The difference between these two functions is the same as that between
rm_rf and rm_rf_tmp in djbunix.
+ Atomic symbolic link creation
+
+
+ int atomic_symlink4 (char const *target, char const *name, char *buf, size_t len)
+Atomically makes a symlink named name pointing to target. If
+name designated an existing file, it is unlinked. Does not work if
+name is an existing directory (but will work if it is a
+symlink to a directory!) Returns 1 on success, and 0 (and sets errno) on
+error.
+In addition, if buf is not NULL, and points
+to a buffer of nonzero length len, then if name exists prior to the
+call, it must be a symbolic link, and its target be shorter than len bytes.
+If these conditions are fulfilled, the operation succeeds, and buf then
+contains the previous target of name, with a terminating NULL. If they are not,
+the function fails with 0 (errno is ENAMETOOLONG if the buffer is too small).
+
+