summaryrefslogtreecommitdiff
path: root/src/libunixonacid/dd_commit.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libunixonacid/dd_commit.c')
-rw-r--r--src/libunixonacid/dd_commit.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/src/libunixonacid/dd_commit.c b/src/libunixonacid/dd_commit.c
index f4a7b06..b4d1511 100644
--- a/src/libunixonacid/dd_commit.c
+++ b/src/libunixonacid/dd_commit.c
@@ -1,17 +1,18 @@
/* ISC license. */
+#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
-#include <stdio.h> /* for rename() */
-#include <skalibs/bytestr.h>
+#include <stdio.h>
+#include <string.h>
#include <skalibs/stralloc.h>
#include <skalibs/djbunix.h>
#include <skalibs/random.h>
#include <skalibs/unix-transactional.h>
-static char const *mybasename (char const *s, unsigned int len)
+static char const *mybasename (char const *s, size_t len)
{
- register unsigned int i = len ;
+ size_t i = len ;
while (i--) if (s[i] == '/') return s + i + 1 ;
return s ;
}
@@ -19,15 +20,15 @@ static char const *mybasename (char const *s, unsigned int len)
int dd_commit (dirdescriptor_t *dd)
{
dirdescriptor_t zero = DIRDESCRIPTOR_ZERO ;
- unsigned int len = str_len(dd->lnkfn) ;
- unsigned int oldbase = dd->new.len ;
- unsigned int newlnkbase ;
+ size_t len = strlen(dd->lnkfn) ;
+ size_t oldbase = dd->new.len ;
+ size_t newlnkbase ;
char const *lnkbn = mybasename(dd->lnkfn, len) ;
if (!sadirname(&dd->new, dd->lnkfn, len)) return 0 ;
if (!stralloc_catb(&dd->new, "/", 1)) goto fail ;
if (sareadlink(&dd->new, dd->lnkfn) < 0)
{
- unsigned int lnkbnbase = dd->new.len ;
+ size_t lnkbnbase = dd->new.len ;
if (errno != EINVAL) goto fail ;
if (!stralloc_cats(&dd->new, lnkbn)) goto fail ;
if (!random_sauniquename(&dd->new, 8)) goto fail ;
@@ -36,7 +37,7 @@ int dd_commit (dirdescriptor_t *dd)
/* /!\ race condition right here: there's no lnkfn in the fs */
if (symlink(dd->new.s + lnkbnbase, dd->lnkfn) < 0) /* now that's VERY BAD if it fails */
{
- register int e = errno ;
+ int e = errno ;
rename(dd->new.s + oldbase, dd->lnkfn) ; /* attempt to revert to initial situation */
errno = e ;
goto fail ; /* and hope for the best */
@@ -50,7 +51,7 @@ int dd_commit (dirdescriptor_t *dd)
if (symlink(dd->new.s, dd->new.s + newlnkbase) < 0) goto fail ;
if (rename(dd->new.s + newlnkbase, dd->lnkfn) < 0)
{
- register int e = errno ;
+ int e = errno ;
unlink(dd->new.s + newlnkbase) ;
errno = e ;
goto fail ;