BackupPC-XS

 view release on metacpan or  search on metacpan

bpc_lib.c  view on Meta::CPAN

/*
 * Library routines
 *
 * Copyright (C) 2013 Craig Barratt.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, visit the http://fsf.org website.
 */

#include "backuppc.h"

char BPC_TopDir[BPC_MAXPATHLEN];
char BPC_PoolDir[BPC_MAXPATHLEN];
char BPC_CPoolDir[BPC_MAXPATHLEN];
char BPC_PoolDir3[BPC_MAXPATHLEN];
char BPC_CPoolDir3[BPC_MAXPATHLEN];

int BPC_HardLinkMax   = 32000;
int BPC_PoolV3Enabled = 0;
int BPC_TmpFileUnique = -1;
int BPC_LogLevel      = 0;

static char *hexDigits = "0123456789abcdef";

void bpc_lib_conf_init(char *topDir, int hardLinkMax, int poolV3Enabled, int logLevel)
{
    if ( logLevel >= 8 ) bpc_logMsgf("bpc_lib_conf_init: topDir = %s, logLevel = %d\n", topDir, logLevel);

    snprintf(BPC_TopDir,    sizeof(BPC_TopDir),    "%s",    topDir);
    snprintf(BPC_CPoolDir,  sizeof(BPC_CPoolDir),  "%s/%s", BPC_TopDir, "cpool");
    snprintf(BPC_CPoolDir3, sizeof(BPC_CPoolDir3), "%s/%s", BPC_TopDir, "cpool");
    snprintf(BPC_PoolDir,   sizeof(BPC_PoolDir),   "%s/%s", BPC_TopDir, "pool");
    snprintf(BPC_PoolDir3,  sizeof(BPC_PoolDir3),  "%s/%s", BPC_TopDir, "pool");

    BPC_HardLinkMax   = hardLinkMax;
    BPC_PoolV3Enabled = poolV3Enabled;
    BPC_LogLevel      = logLevel;
}

void bpc_lib_setTmpFileUnique(int val)
{
    BPC_TmpFileUnique = val;
}

int bpc_lib_setLogLevel(int logLevel)
{
    if ( logLevel >= 0 ) {
        BPC_LogLevel = logLevel;
    }
    return BPC_LogLevel;
}

/*
 * Converts a byte to two ascii hex digits at outStr[0] and outStr[1].
 * Nothing is written at outStr[2]; ie: no NULL termination
 */
void bpc_byte2hex(char *outStr, int byte)
{
    outStr[0] = hexDigits[(byte >> 4) & 0xf];
    outStr[1] = hexDigits[(byte >> 0) & 0xf];
}

static uchar bpc_hexChar2nibble(char c)
{
    if ( '0' <= c && c <= '9' ) return c - '0';
    if ( 'A' <= c && c <= 'F' ) return 0xa + (c - 'A');
    if ( 'a' <= c && c <= 'f' ) return 0xa + (c - 'a');
    return 0;
}



( run in 0.930 second using v1.01-cache-2.11-cpan-39bf76dae61 )