diff options
-rw-r--r-- | NEWS | 6 | ||||
-rw-r--r-- | doc/index.html | 2 | ||||
-rw-r--r-- | doc/license.html | 2 | ||||
-rw-r--r-- | doc/upgrade.html | 6 | ||||
-rw-r--r-- | package/deps.mak | 1 | ||||
-rw-r--r-- | package/info | 2 | ||||
-rw-r--r-- | src/include/skalibs/unix-transactional.h | 1 | ||||
-rw-r--r-- | src/libunixonacid/atomic_symlink.c | 41 |
8 files changed, 58 insertions, 3 deletions
@@ -1,5 +1,11 @@ Changelog for skalibs. +In 2.6.3.0 +---------- + + - New function: atomic_symlink(). + + In 2.6.2.0 ---------- diff --git a/doc/index.html b/doc/index.html index 24fe81c..da77c9b 100644 --- a/doc/index.html +++ b/doc/index.html @@ -60,7 +60,7 @@ with a standard C development environment </li> <h3> Download </h3> <ul> - <li> The current released version of skalibs is <a href="skalibs-2.6.2.0.tar.gz">2.6.2.0</a>. </li> + <li> The current released version of skalibs is <a href="skalibs-2.6.3.0.tar.gz">2.6.3.0</a>. </li> <li> Alternatively, you can checkout a copy of the <a href="//git.skarnet.org/cgi-bin/cgit.cgi/skalibs/">skalibs git repository</a>: diff --git a/doc/license.html b/doc/license.html index 3cd815b..9eb93a0 100644 --- a/doc/license.html +++ b/doc/license.html @@ -74,7 +74,7 @@ color, or different text font. </li> <p> <em>I am aware that the previous restrictions sound completely ridiculous while the official skalibs documentation is incomplete. -As of 2.6.2.0, I'm not going to enforce those restrictions, but if you're +As of 2.6.3.0, I'm not going to enforce those restrictions, but if you're going to provide documentation for skalibs, don't keep it to yourself, please send it to me instead. :-) </em> </p> diff --git a/doc/upgrade.html b/doc/upgrade.html index 536e079..a45131d 100644 --- a/doc/upgrade.html +++ b/doc/upgrade.html @@ -16,6 +16,12 @@ <a href="//skarnet.org/">skarnet.org</a> </p> +<h2> in 2.6.3.0 </h2> + +<ul> + <li> New function: atomic_symlink(). </li> +</ul> + <h2> in 2.6.2.0 </h2> <ul> diff --git a/package/deps.mak b/package/deps.mak index f5aa076..63dec9f 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -690,6 +690,7 @@ src/libstddjb/xpathexec_run.o src/libstddjb/xpathexec_run.lo: src/libstddjb/xpat src/libunixonacid/access_at.o src/libunixonacid/access_at.lo: src/libunixonacid/access_at.c src/include/skalibs/djbunix.h src/include/skalibs/nonposix.h src/include/skalibs/sysdeps.h src/include/skalibs/unix-transactional.h src/libunixonacid/atomic_rm_rf.o src/libunixonacid/atomic_rm_rf.lo: src/libunixonacid/atomic_rm_rf.c src/include/skalibs/skamisc.h src/include/skalibs/unix-transactional.h src/libunixonacid/atomic_rm_rf_tmp.o src/libunixonacid/atomic_rm_rf_tmp.lo: src/libunixonacid/atomic_rm_rf_tmp.c src/include/skalibs/djbunix.h src/include/skalibs/random.h src/include/skalibs/stralloc.h src/include/skalibs/unix-transactional.h +src/libunixonacid/atomic_symlink.o src/libunixonacid/atomic_symlink.lo: src/libunixonacid/atomic_symlink.c src/include/skalibs/random.h src/include/skalibs/unix-transactional.h src/libunixonacid/bufalloc_timed_flush.o src/libunixonacid/bufalloc_timed_flush.lo: src/libunixonacid/bufalloc_timed_flush.c src/include/skalibs/bufalloc.h src/include/skalibs/functypes.h src/include/skalibs/unix-timed.h src/libunixonacid/buffer_timed_fill.o src/libunixonacid/buffer_timed_fill.lo: src/libunixonacid/buffer_timed_fill.c src/include/skalibs/allreadwrite.h src/include/skalibs/buffer.h src/include/skalibs/functypes.h src/include/skalibs/unix-timed.h src/libunixonacid/buffer_timed_flush.o src/libunixonacid/buffer_timed_flush.lo: src/libunixonacid/buffer_timed_flush.c src/include/skalibs/buffer.h src/include/skalibs/functypes.h src/include/skalibs/unix-timed.h diff --git a/package/info b/package/info index f19446c..404e5b2 100644 --- a/package/info +++ b/package/info @@ -1,4 +1,4 @@ package=skalibs -version=2.6.2.0 +version=2.6.3.0 category=prog package_macro_name=SKALIBS diff --git a/src/include/skalibs/unix-transactional.h b/src/include/skalibs/unix-transactional.h index d548f78..1037e92 100644 --- a/src/include/skalibs/unix-transactional.h +++ b/src/include/skalibs/unix-transactional.h @@ -39,6 +39,7 @@ extern size_t openwritevnclose_at (int, char const *, struct iovec const *, unsi extern int mkdir_unique (stralloc *, char const *, unsigned int) ; extern int atomic_rm_rf (char const *) ; extern int atomic_rm_rf_tmp (char const *, stralloc *) ; +extern int atomic_symlink (char const *, char const *, char const *) ; typedef struct dirdescriptor_s dirdescriptor_t, *dirdescriptor_t_ref ; diff --git a/src/libunixonacid/atomic_symlink.c b/src/libunixonacid/atomic_symlink.c new file mode 100644 index 0000000..660e4d3 --- /dev/null +++ b/src/libunixonacid/atomic_symlink.c @@ -0,0 +1,41 @@ +/* ISC license. */ + +#include <string.h> +#include <unistd.h> +#include <errno.h> +#include <stdio.h> +#include <skalibs/random.h> +#include <skalibs/unix-transactional.h> + +int atomic_symlink (char const *target, char const *name, char const *suffix) +{ + { + int e = errno ; + if (symlink(target, name) == 0) return 1 ; + if (errno != EEXIST) return 0 ; + errno = e ; + } + { + size_t namelen = strlen(name) ; + size_t suffixlen = suffix ? strlen(suffix) : 8 ; + char tmp[namelen + suffixlen + 2] ; + memcpy(tmp, name, namelen) ; + tmp[namelen] = ':' ; + if (suffix) + memcpy(tmp + namelen + 1, suffix, suffixlen + 1) ; + else + { + random_name(tmp + namelen + 1, 8) ; + tmp[namelen + 9] = 0 ; + } + if (symlink(target, tmp) < 0) return 0 ; + if (rename(tmp, name) < 0) + { + int e = errno ; + unlink(tmp) ; + errno = e ; + return 0 ; + } + } + return 1 ; +} |