From 6f062aee15b6a75559b3e82b14721038031aaeb7 Mon Sep 17 00:00:00 2001
From: obarun <eric@obarun.org>
Date: Mon, 26 Sep 2022 20:24:50 +1100
Subject: [PATCH] pass to auto_stra

---
 src/lib66/utils/read_svfile.c     | 11 +++++------
 src/lib66/utils/set_livedir.c     | 26 ++++++++++++--------------
 src/lib66/utils/set_livescan.c    |  8 ++++----
 src/lib66/utils/set_livestate.c   |  9 ++++-----
 src/lib66/utils/set_ownerhome.c   |  8 ++++----
 src/lib66/utils/set_ownersysdir.c | 21 ++++++++++-----------
 6 files changed, 39 insertions(+), 44 deletions(-)

diff --git a/src/lib66/utils/read_svfile.c b/src/lib66/utils/read_svfile.c
index af74412f..58466590 100644
--- a/src/lib66/utils/read_svfile.c
+++ b/src/lib66/utils/read_svfile.c
@@ -28,13 +28,11 @@ int read_svfile(stralloc *sasv,char const *name,char const *src)
     log_flow() ;
 
     int r ;
+
     size_t srclen = strlen(src) ;
     size_t namelen = strlen(name) ;
-
     char svtmp[srclen + namelen + 1] ;
-    memcpy(svtmp,src,srclen) ;
-    memcpy(svtmp + srclen, name, namelen) ;
-    svtmp[srclen + namelen] = 0 ;
+    auto_strings(svtmp, src, name) ;
 
     size_t filesize=file_get_size(svtmp) ;
     if (!filesize)
@@ -44,9 +42,10 @@ int read_svfile(stralloc *sasv,char const *name,char const *src)
     if(!r)
         log_warnusys_return(LOG_EXIT_ZERO,"open ", svtmp) ;
 
+
     /** ensure that we have an empty line at the end of the string*/
-    if (!stralloc_cats(sasv,"\n")) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
-    if (!stralloc_0(sasv)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
+    if (!auto_stra(sasv, "\n"))
+        log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
 
     return 1 ;
 }
diff --git a/src/lib66/utils/set_livedir.c b/src/lib66/utils/set_livedir.c
index 92b4c41f..a4a22200 100644
--- a/src/lib66/utils/set_livedir.c
+++ b/src/lib66/utils/set_livedir.c
@@ -13,6 +13,7 @@
  */
 
 #include <oblibs/log.h>
+#include <oblibs/string.h>
 
 #include <skalibs/stralloc.h>
 
@@ -23,21 +24,18 @@ int set_livedir(stralloc *live)
 {
     log_flow() ;
 
-    if (live->len)
-    {
-        if (live->s[0] != '/') return -1 ;
-        if (live->s[live->len - 2] != '/')
-        {
+    if (live->len) {
+
+        if (live->s[0] != '/')
+            return -1 ;
+
+        if (live->s[live->len - 2] != '/') {
             live->len-- ;
-            if (!stralloc_cats(live,"/")) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
-            if (!stralloc_0(live)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
+            if (!auto_stra(live,"/")) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
         }
-    }
-    else
-    {
-        if (!stralloc_cats(live,SS_LIVE)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
-        if (!stralloc_0(live)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
-    }
-    live->len--;
+
+    } else if (!auto_stra(live,SS_LIVE))
+        log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
+
     return 1 ;
 }
diff --git a/src/lib66/utils/set_livescan.c b/src/lib66/utils/set_livescan.c
index 91980962..5ab2e2e5 100644
--- a/src/lib66/utils/set_livescan.c
+++ b/src/lib66/utils/set_livescan.c
@@ -15,6 +15,7 @@
 #include <sys/types.h>
 
 #include <oblibs/log.h>
+#include <oblibs/string.h>
 
 #include <skalibs/stralloc.h>
 #include <skalibs/types.h>
@@ -36,9 +37,8 @@ int set_livescan(stralloc *scandir,uid_t owner)
     size_t ownerlen = uid_fmt(ownerpack,owner) ;
     ownerpack[ownerlen] = 0 ;
 
-    if (!stralloc_cats(scandir,SS_SCANDIR "/")) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
-    if (!stralloc_cats(scandir,ownerpack)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
-    if (!stralloc_0(scandir)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
-    scandir->len--;
+    if (!auto_stra(scandir,SS_SCANDIR "/", ownerpack))
+        log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
+
     return 1 ;
 }
diff --git a/src/lib66/utils/set_livestate.c b/src/lib66/utils/set_livestate.c
index fab2429f..9da938ba 100644
--- a/src/lib66/utils/set_livestate.c
+++ b/src/lib66/utils/set_livestate.c
@@ -15,6 +15,7 @@
 #include <sys/types.h>
 
 #include <oblibs/log.h>
+#include <oblibs/string.h>
 
 #include <skalibs/types.h>
 #include <skalibs/stralloc.h>
@@ -36,10 +37,8 @@ int set_livestate(stralloc *livestate,uid_t owner)
     size_t ownerlen = uid_fmt(ownerpack,owner) ;
     ownerpack[ownerlen] = 0 ;
 
-    if (!stralloc_cats(livestate,SS_STATE + 1)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
-    if (!stralloc_cats(livestate,"/")) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
-    if (!stralloc_cats(livestate,ownerpack)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
-    if (!stralloc_0(livestate)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
-    livestate->len--;
+    if (!auto_stra(livestate,SS_STATE + 1, "/", ownerpack))
+        log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
+
     return 1 ;
 }
diff --git a/src/lib66/utils/set_ownerhome.c b/src/lib66/utils/set_ownerhome.c
index 1efb0f64..9d948cfd 100644
--- a/src/lib66/utils/set_ownerhome.c
+++ b/src/lib66/utils/set_ownerhome.c
@@ -17,6 +17,7 @@
 #include <pwd.h>
 
 #include <oblibs/log.h>
+#include <oblibs/string.h>
 
 #include <skalibs/stralloc.h>
 
@@ -39,9 +40,8 @@ int set_ownerhome(stralloc *base,uid_t owner)
     errno = e ;
     if (!user_home) return 0 ;
 
-    if (!stralloc_cats(base,user_home)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
-    if (!stralloc_cats(base,"/")) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
-    if (!stralloc_0(base)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
-    base->len--;
+    if (!auto_stra(base,user_home, "/"))
+        log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
+
     return 1 ;
 }
diff --git a/src/lib66/utils/set_ownersysdir.c b/src/lib66/utils/set_ownersysdir.c
index d29b87bc..ceb0eb6c 100644
--- a/src/lib66/utils/set_ownersysdir.c
+++ b/src/lib66/utils/set_ownersysdir.c
@@ -16,6 +16,7 @@
 #include <errno.h>
 
 #include <oblibs/log.h>
+#include <oblibs/string.h>
 
 #include <skalibs/stralloc.h>
 
@@ -39,17 +40,15 @@ int set_ownersysdir(stralloc *base, uid_t owner)
     errno = e ;
     if (user_home == NULL) return 0 ;
 
-    if(owner > 0){
-        if (!stralloc_cats(base,user_home)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
-        if (!stralloc_cats(base,"/")) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
-        if (!stralloc_cats(base,SS_USER_DIR)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
-        if (!stralloc_0(base)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
-    }
-    else
-    {
-        if (!stralloc_cats(base,SS_SYSTEM_DIR)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
-        if (!stralloc_0(base)) log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
+    if(owner > 0) {
+        if (!auto_stra(base,user_home, "/", SS_USER_DIR))
+            log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
+
+    } else {
+
+        if (!auto_stra(base,SS_SYSTEM_DIR))
+            log_warnsys_return(LOG_EXIT_ZERO,"stralloc") ;
     }
-    base->len--;
+
     return 1 ;
 }
-- 
GitLab