        -:    0:Source:syslog-provider.c
        -:    0:Graph:/__w/c-modernization-kit/c-modernization-kit/test/util/src/libutilTest/trace_providerTest/obj/syslog-provider.gcno
        -:    0:Data:/__w/c-modernization-kit/c-modernization-kit/test/util/src/libutilTest/trace_providerTest/obj/syslog-provider.gcda
        -:    0:Runs:1
        -:    1:#ifndef _WIN32
        -:    2:
        -:    3:#include <syslog.h>
        -:    4:#include <trace-syslog-util.h>
        -:    5:#include <stdlib.h>
        -:    6:#include <string.h>
        -:    7:
        -:    8:/**
        -:    9: *  @brief  syslog プロバイダハンドル構造体 (内部定義)。
        -:   10: */
        -:   11:struct syslog_provider
        -:   12:{
        -:   13:    /** openlog に渡した識別子文字列 (複製を保持)。 */
        -:   14:    char *ident;
        -:   15:};
        -:   16:
        -:   17:syslog_provider_t *TRACE_SYSLOG_UTIL_API
        1:   18:    syslog_provider_init(const char *ident, int facility)
        -:   19:{
        -:   20:    syslog_provider_t *handle;
        -:   21:    size_t len;
        -:   22:
        1:   23:    if (ident == NULL)
        -:   24:    {
    #####:   25:        return NULL;
        -:   26:    }
        -:   27:
        1:   28:    handle = (syslog_provider_t *)malloc(sizeof(syslog_provider_t));
        1:   29:    if (handle == NULL)
        -:   30:    {
    #####:   31:        return NULL;
        -:   32:    }
        -:   33:
        -:   34:    /* ident 文字列を複製して保持 (openlog はポインタを保持するため) */
        1:   35:    len = strlen(ident) + 1;
        1:   36:    handle->ident = (char *)malloc(len);
        1:   37:    if (handle->ident == NULL)
        -:   38:    {
    #####:   39:        free(handle);
    #####:   40:        return NULL;
        -:   41:    }
        1:   42:    memcpy(handle->ident, ident, len);
        -:   43:
        1:   44:    openlog(handle->ident, LOG_NDELAY | LOG_PID, facility);
        -:   45:
        1:   46:    return handle;
        -:   47:}
        -:   48:
        -:   49:int TRACE_SYSLOG_UTIL_API
    #####:   50:    syslog_provider_write(syslog_provider_t *handle, int level, const char *message)
        -:   51:{
    #####:   52:    if (handle == NULL || message == NULL)
        -:   53:    {
    #####:   54:        return 0;
        -:   55:    }
        -:   56:
    #####:   57:    syslog(level, "%s", message);
        -:   58:
    #####:   59:    return 0;
        -:   60:}
        -:   61:
        -:   62:void TRACE_SYSLOG_UTIL_API
        1:   63:    syslog_provider_dispose(syslog_provider_t *handle)
        -:   64:{
        1:   65:    if (handle == NULL)
        -:   66:    {
    #####:   67:        return;
        -:   68:    }
        -:   69:
        1:   70:    closelog();
        1:   71:    free(handle->ident);
        1:   72:    free(handle);
        -:   73:}
        -:   74:
        -:   75:int TRACE_SYSLOG_UTIL_API
    #####:   76:    syslog_provider_rename(syslog_provider_t *handle, const char *new_ident)
        -:   77:{
        -:   78:    char *dup;
        -:   79:    size_t len;
        -:   80:
    #####:   81:    if (handle == NULL || new_ident == NULL)
        -:   82:    {
    #####:   83:        return -1;
        -:   84:    }
        -:   85:
    #####:   86:    len = strlen(new_ident) + 1;
    #####:   87:    dup = (char *)malloc(len);
    #####:   88:    if (dup == NULL)
        -:   89:    {
    #####:   90:        return -1;
        -:   91:    }
    #####:   92:    memcpy(dup, new_ident, len);
        -:   93:
    #####:   94:    closelog();
    #####:   95:    free(handle->ident);
    #####:   96:    handle->ident = dup;
    #####:   97:    openlog(handle->ident, LOG_NDELAY | LOG_PID, LOG_USER);
        -:   98:
    #####:   99:    return 0;
        -:  100:}
        -:  101:
        -:  102:#else /* _WIN32 */
        -:  103:    #pragma warning(disable : 4206)
        -:  104:#endif /* _WIN32 */
