summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/skaembutils/s6-grep.c20
-rw-r--r--src/skaembutils/s6-ln.c3
-rw-r--r--src/skaembutils/s6-update-symlinks.c14
3 files changed, 14 insertions, 23 deletions
diff --git a/src/skaembutils/s6-grep.c b/src/skaembutils/s6-grep.c
index bd48cea..2839758 100644
--- a/src/skaembutils/s6-grep.c
+++ b/src/skaembutils/s6-grep.c
@@ -13,6 +13,7 @@
#include <skalibs/skamisc.h>
#define USAGE "s6-grep [ -E | -F ] [ -i ] [ -c ] [ -n ] [ -q ] [ -v ] pattern"
+#define dieusage() strerr_dieusage(100, USAGE)
typedef struct flags_s flags_t, *flags_t_ref ;
struct flags_s
@@ -27,6 +28,12 @@ struct flags_s
} ;
#define FLAGS_ZERO { .extended = 0, .ignorecase = 0, .fixed = 0, .count = 0, .num = 0, .quiet = 0, .not = 0 }
+static void xout (char const *s, size_t len)
+{
+ if (buffer_put(buffer_1, s, len) < 0)
+ strerr_diefu1sys(111, "write to stdout") ;
+}
+
int main (int argc, char const *const *argv)
{
unsigned int count = 0 ;
@@ -47,12 +54,12 @@ int main (int argc, char const *const *argv)
case 'n': flags.num = 1 ; break ;
case 'q': flags.quiet = 1 ; break ;
case 'v': flags.not = 1 ; break ;
- default : strerr_dieusage(100, USAGE) ;
+ default : dieusage() ;
}
}
argc -= l.ind ; argv += l.ind ;
}
- if (!argc) strerr_dieusage(100, USAGE) ;
+ if (!argc) dieusage() ;
{
stralloc line = STRALLOC_ZERO ;
regex_t re ;
@@ -109,11 +116,9 @@ int main (int argc, char const *const *argv)
char fmt[UINT_FMT] ;
size_t n = uint_fmt(fmt, num) ;
fmt[n++] = ':' ;
- if (buffer_put(buffer_1, fmt, n) < (ssize_t)n)
- strerr_diefu1sys(111, "write to stdout") ;
+ xout(fmt, n) ;
}
- if (buffer_put(buffer_1, line.s, line.len) < (ssize_t)line.len)
- strerr_diefu1sys(111, "write to stdout") ;
+ xout(line.s, line.len) ;
}
}
}
@@ -126,8 +131,7 @@ int main (int argc, char const *const *argv)
char fmt[UINT_FMT] ;
size_t n = uint_fmt(fmt, count) ;
fmt[n++] = '\n' ;
- if (buffer_put(buffer_1, fmt, n) < (ssize_t)n)
- strerr_diefu1sys(111, "write to stdout") ;
+ xout(fmt, n) ;
}
return !count ;
}
diff --git a/src/skaembutils/s6-ln.c b/src/skaembutils/s6-ln.c
index 65a650f..d600aab 100644
--- a/src/skaembutils/s6-ln.c
+++ b/src/skaembutils/s6-ln.c
@@ -12,6 +12,7 @@
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
+#include <skalibs/posixplz.h>
#include <skalibs/sgetopt.h>
#include <skalibs/strerr2.h>
#include <skalibs/stralloc.h>
@@ -61,7 +62,7 @@ static void force (char const *old, char const *new, linkfunc_t_ref doit)
strerr_diefu3sys(111, "make a link", " to ", old) ;
if (rename(satmp.s + base, new) == -1)
{
- unlink(satmp.s + base) ;
+ unlink_void(satmp.s + base) ;
strerr_diefu2sys(111, "atomically replace ", new) ;
}
satmp.len = base ;
diff --git a/src/skaembutils/s6-update-symlinks.c b/src/skaembutils/s6-update-symlinks.c
index 7ef3eb5..6acb77c 100644
--- a/src/skaembutils/s6-update-symlinks.c
+++ b/src/skaembutils/s6-update-symlinks.c
@@ -97,10 +97,8 @@ static int addlink (stralloc3 *blah, unsigned int dstpos, unsigned int srcpos)
r = sareadlink(&blah->src, blah->dst.s + dstpos) ;
if ((r == -1) && (errno != EINVAL))
{
- int e = errno ;
blah->dst.len = dstbase ;
dir_close(dir) ;
- errno = e ;
return ERROR ;
}
if (r < 0)
@@ -117,11 +115,9 @@ static int addlink (stralloc3 *blah, unsigned int dstpos, unsigned int srcpos)
}
if (errno)
{
- int e = errno ;
blah->src.len = srcbase ;
blah->dst.len = dstbase ;
dir_close(dir) ;
- errno = e ;
return ERROR ;
}
}
@@ -129,11 +125,9 @@ static int addlink (stralloc3 *blah, unsigned int dstpos, unsigned int srcpos)
|| (mkdir(blah->dst.s + dstpos, 0777) == -1)
|| !stralloc_catb(&blah->src, "/", 1))
{
- int e = errno ;
blah->src.len = srcbase ;
blah->dst.len = dstbase ;
dir_close(dir) ;
- errno = e ;
return ERROR ;
}
else /* expand */
@@ -154,21 +148,17 @@ static int addlink (stralloc3 *blah, unsigned int dstpos, unsigned int srcpos)
|| !stralloc_cats(&blah->src, d->d_name) || !stralloc_0(&blah->src)
|| (symlink(blah->src.s + srcbase, blah->dst.s + dstbase) == -1))
{
- int e = errno ;
blah->src.len = srcbase ;
blah->dst.len = dstbase ;
dir_close(dir) ;
- errno = e ;
return ERROR ;
}
}
if (errno)
{
- int e = errno ;
blah->src.len = srcbase ;
blah->dst.len = dstbase ;
dir_close(dir) ;
- errno = e ;
return ERROR ;
}
}
@@ -214,23 +204,19 @@ static int addlink (stralloc3 *blah, unsigned int dstpos, unsigned int srcpos)
continue ;
if (!stralloc_cats(&blah->tmp, d->d_name) || !stralloc_0(&blah->tmp))
{
- int e = errno ;
blah->tmp.len = tmpbase ;
blah->src.len = srcbase ;
blah->dst.len = dstbase ;
dir_close(dir) ;
- errno = e ;
return ERROR ;
}
}
if (errno)
{
- int e = errno ;
blah->tmp.len = tmpbase ;
blah->src.len = srcbase ;
blah->dst.len = dstbase ;
dir_close(dir) ;
- errno = e ;
return ERROR ;
}
dir_close(dir) ;