Skip to content
Snippets Groups Projects
Commit 4af1f221 authored by Eric Vidal's avatar Eric Vidal :speech_balloon:
Browse files

add env_get_destination()

parent 1bd57b66
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,7 @@ extern int env_make_symlink(resolve_service_t *res) ;
extern int env_compute(stralloc *result, resolve_service_t *res) ;
extern int env_clean_with_comment(stralloc *sa) ;
extern int env_prepare_for_write(stralloc *dst, stralloc *contents, resolve_service_t *res) ;
extern int env_get_destination(stralloc *sa, resolve_service_t *res) ;
/** version function */
extern int env_find_current_version(stralloc *sa,char const *svconf) ;
......
......@@ -3,6 +3,7 @@ env_check_version.o
env_clean_with_comment.o
env_compute.o
env_find_current_version.o
env_get_destination.o
env_import_version_file.o
env_make_symlink.o
env_prepare_for_write.o
......
/*
* env_resolve_conf.c
*
* Copyright (c) 2018-2022 Eric Vidal <eric@obarun.org>
*
* All rights reserved.
*
* This file is part of Obarun. It is subject to the license terms in
* the LICENSE file found in the top-level directory of this
* distribution.
* This file may not be copied, modified, propagated, or distributed
* except according to the terms contained in the LICENSE file./
*/
#include <string.h>
#include <oblibs/log.h>
#include <oblibs/string.h>
#include <skalibs/stralloc.h>
#include <skalibs/djbunix.h>
#include <66/environ.h>
#include <66/constants.h>
#include <66/service.h>
int env_get_destination(stralloc *sa, resolve_service_t *res)
{
log_flow() ;
char *conf = res->sa.s + res->environ.envdir ;
size_t conflen = strlen(conf) ;
char sym[conflen + SS_SYM_VERSION_LEN + 1] ;
auto_strings(sym, conf, SS_SYM_VERSION) ;
if (sareadlink(sa, sym) == -1)
log_warnusys_return(LOG_EXIT_ZERO, "read link of: ", sym) ;
if (!stralloc_0(sa))
log_warnusys_return(LOG_EXIT_ZERO, "stralloc") ;
return 1 ;
}
......@@ -30,20 +30,11 @@ int env_prepare_for_write(stralloc *dst, stralloc *contents, resolve_service_t *
{
log_flow() ;
char *conf = res->sa.s + res->environ.envdir ;
size_t conflen = strlen(conf) ;
char sym[conflen + SS_SYM_VERSION_LEN + 1] ;
auto_strings(sym, conf, SS_SYM_VERSION) ;
if (!env_compute(contents, res))
log_warnu_return(LOG_EXIT_ZERO, "compute environment") ;
if (sareadlink(dst, sym) == -1)
log_warnusys_return(LOG_EXIT_ZERO, "read link of: ", sym) ;
if (!stralloc_0(dst))
log_warnusys_return(LOG_EXIT_ZERO, "stralloc") ;
if (!env_get_destination(dst, res))
log_warnu_return(LOG_EXIT_ZERO, "get directory destination for environment") ;
return 1 ;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment