Example #1
0
int
main(int argc, char **argv) {
    char          position1[255];
    char          position2[255];
    zt_log_ty   * logger;
    zt_log_ty   * lsyslog;

    /* set the progname before calling syslog */
    zt_progname(argv[0], STRIP_DIR);

    lsyslog = zt_log_syslog();

    logger = zt_log_logger(lsyslog);
    zt_log_set_level(lsyslog, zt_log_debug);

    zt_log_printf( zt_log_emerg, "*emergency* message" );
    zt_log_printf( zt_log_alert, "*alert* message" );
    zt_log_printf( zt_log_crit, "*critical* message" );
    zt_log_printf( zt_log_err, "*error* message" );
    zt_log_printf( zt_log_warning, "*warning* message" );
    zt_log_printf( zt_log_notice, "*notice* message" );
    zt_log_printf( zt_log_info, "*info* message" );
    zt_log_printf( zt_log_debug, "*debug* message" );

    zt_log_set_opts(lsyslog, (ZT_LOG_RAW));

    /* these need to be on the same line for the test to work */
    sprintf(position1, "(%s:%d)", __FILE__, __LINE__); ZT_LOG_XDEBUG( "LOG_DEBUG" );
    sprintf(position2, "(%s:%d)", __FILE__, __LINE__); ZT_LOG_DEBUG_INFO(), zt_log_lprintf(lsyslog, zt_log_debug, "lprintf with debugging");

    zt_log_close(lsyslog);
    zt_log_logger(logger);

    return 0;
} /* basic_tests */
Example #2
0
int
zt_table_set(zt_table *h, const void *key, const void *datum)
{
    unsigned long       nkey = h->func(key, h->cdata);
    unsigned long       skey = nkey;
    struct table_node * node;
    struct table_node * nn;

    ZT_HASH_SUB32_MASK(nkey, h->nbits);
    ZT_LOG_XDEBUG("for key %d hash key is: %d", (int)key, nkey);

    nn = h->buckets[nkey];

    if (!(h->flags & ZT_TABLE_ALLOW_DUP_KEYS)) {
        while (nn) {
            if (nn->hash_key == skey) {
                if (h->cmp((void *)nn->key, key, h->cdata)) {
                    return 1;
                }
            }
            nn = nn->next;
        }
    }

    node = (struct table_node *)zt_mem_pool_alloc(h->node_pool);

    node->next = h->buckets[nkey];
    node->hash_key = skey;
    h->buckets[nkey] = node;
    node->key = (void *)key;
    node->datum = (void *)datum;

    return 0;
}