diff --git a/src/lib66/utils/read_svfile.c b/src/lib66/utils/read_svfile.c index af74412fb19d6dda9fd77f29e97bacd79c9f895f..5846659048490f8c820c13a45b9e89dc0a458d61 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 92b4c41f491e0ae25441d24ca0f62f2bdec0b7c5..a4a22200bc6e0b7da11e2be7aedd93e7424189c7 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 91980962056c5485a19743280d6b402bf1a1254d..5ab2e2e54f3bfdf7ebd3d32249913f9ec8909d60 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 fab2429f234301ff7e49e905f5887bfb90954aa1..9da938bae5083a9df0acffad415a31df4aaa2aaf 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 1efb0f641bf152b2c263d33f1e7b776b7dd16370..9d948cfd7164ff2b482e63d52813178e8b3d6634 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 d29b87bcea2c04df86423a3cab52363d641e56fb..ceb0eb6c98e30264d60bf7dbeb63128b486a2db3 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 ; }