Skip to content
Snippets Groups Projects
instance_create.c 1.1 KiB
Newer Older
Eric Vidal's avatar
Eric Vidal committed
 * instance_create.c
Eric Vidal's avatar
Eric Vidal committed
 * Copyright (c) 2018-2024 Eric Vidal <eric@obarun.org>
Eric Vidal's avatar
Eric Vidal committed
 * All rights reserved.
Eric Vidal's avatar
Eric Vidal committed
 * 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./
 */

Eric Vidal's avatar
Eric Vidal committed
#include <stddef.h>
#include <oblibs/log.h>
Eric Vidal's avatar
Eric Vidal committed
#include <oblibs/string.h>
#include <oblibs/sastr.h>
Eric Vidal's avatar
Eric Vidal committed

#include <skalibs/stralloc.h>
int instance_create(stralloc *sasv,char const *svname, char const *regex, int len)
Eric Vidal's avatar
Eric Vidal committed
    log_flow() ;

Eric Vidal's avatar
Eric Vidal committed
    int e = 0 ;
    char const *copy ;
    size_t tlen = len + 1 ;

    stralloc tmp = STRALLOC_ZERO ;

    if (!auto_stra(&tmp,sasv->s)) goto err ;

    copy = svname + tlen ;

    if (!sastr_replace_all(&tmp,regex,copy)){
        log_warnu("replace instance character for service: ",svname) ;
        goto err ;
    }

Eric Vidal's avatar
Eric Vidal committed
    stralloc_0(&tmp) ;

    sasv->len = 0 ;

    if (!auto_stra(sasv, tmp.s))
        goto err ;

    e = 1 ;
    err:
        stralloc_free(&tmp) ;
Eric Vidal's avatar
Eric Vidal committed
        return e ;