Beispiel #1
0
static int DefaultSaveFunction(const void *element,void *arg, FILE *Outfile)
{
    const CHAR_TYPE *str = (const CHAR_TYPE *)element;
    size_t len = STRLEN(str);

    if (encode_ule128(Outfile, len) <= 0)
        return EOF;
    len++;
    return len == fwrite(str,1,len,Outfile);
}
Beispiel #2
0
static int Save(const HashTable *HT,FILE *stream, SaveFunction saveFn,void *arg)
{
    HashIndex  hix;
    HashIndex *hi;
    int rv;
    int retval=1;
    size_t elemsiz;

    if (HT == NULL || stream == NULL) {
        return NullPtrError("Save");
    }
    if (saveFn == NULL) {
        saveFn = DefaultSaveFunction;
        elemsiz = HT->ElementSize;
        arg = &elemsiz;
    }
    if (fwrite(&HashTableGuid,sizeof(guid),1,stream) == 0)
        return EOF;
    if (fwrite(HT,1,sizeof(HashTable),stream) == 0)
        return EOF;

    hix.ht    = (HashTable *)HT;
    hix.index = 0;
    hix.This  = NULL;
    hix.next  = NULL;

    hi = next(&hix);
    if (hi) {
        /* Scan the entire table */
        do {
            rv = encode_ule128(stream, hi->This->klen);
            if (rv > 0)
                rv = (int)fwrite(hi->This->key,1,hi->This->klen,stream);
            if (rv > 0)
                rv = (int)saveFn(hi->This->val,arg,stream);
        } while (rv > 0 && (hi = next(hi)));

        if (rv <= 0) {
            retval = (int)rv;
        }
    }
    return retval;
}