src/siri/db/series.c
/*
 * Returns 0 if successful or -1 in case of an error.
 * (a SIGNAL might be raised but -1 should be considered critical in any case)
 */
Returns 0 if successful or -1 in case of an error.
(a SIGNAL might be raised but -1 should be considered critical in any case)
Returns 0 if successful or - 1 in case of an error . ( a SIGNAL might be raised but - 1 should be considered critical in any case )
static int SERIES_read_dropped(siridb_t * siridb, imap_t * dropped)
{
    char * buffer;
    char * pt;
    long int size;
    int rc = 0;
    FILE * fp;
    log_debug("Loading dropped series");
    SIRIDB_GET_FN(fn, siridb->dbpath, SIRIDB_DROPPED_FN)
    if ((fp = fopen(fn, "r")) == NULL)
    {
        return 0;
    }
    if (fseeko(fp, 0, SEEK_END) ||
        (size = ftello(fp)) < 0 ||
        fseeko(fp, 0, SEEK_SET))
    {
        fclose(fp);
        log_critical("Cannot read size of file '%s'", fn);
        rc = -1;
    }
    else if (size)
    {
        buffer = (char *) malloc(size);
        if (buffer == NULL)
        {
            log_critical("Cannot allocate buffer for reading dropped series");
            rc = -1;
        }
        else if (fread(buffer, size, 1, fp) == 1)
        {
            char * end = buffer + size;
            for (   pt = buffer;
                    pt < end;
                    pt += sizeof(uint32_t))
            {
                if (imap_set(
                        dropped,
                        (uint32_t) *((uint32_t *) pt),
                        (int *) DROPPED_DUMMY) == -1)
                {
                    log_critical("Cannot add id to dropped map");
                    rc = -1;
                }
            }
        }
        else
        {
            log_critical("Cannot read %ld bytes from file '%s'", size, fn);
            rc = -1;
        }
        free(buffer);
    }
    fclose(fp);
    return rc;
}
static int SERIES_read_dropped ( siridb_t * siridb , imap_t * dropped ) { char * buffer ; char * pt ; long int size ; int rc = 0 ; FILE * fp ; log_debug ( " " ) ; SIRIDB_GET_FN ( fn , siridb -> dbpath , SIRIDB_DROPPED_FN ) if ( ( fp = fopen ( fn , " " ) ) == NULL ) { return 0 ; } if ( fseeko ( fp , 0 , SEEK_END ) || ( size = ftello ( fp ) ) < 0 || fseeko ( fp , 0 , SEEK_SET ) ) { fclose ( fp ) ; log_critical ( " " , fn ) ; rc = -1 ; } else if ( size ) { buffer = ( char * ) malloc ( size ) ; if ( buffer == NULL ) { log_critical ( " " ) ; rc = -1 ; } else if ( fread ( buffer , size , 1 , fp ) == 1 ) { char * end = buffer + size ; for ( pt = buffer ; pt < end ; pt += sizeof ( uint32_t ) ) { if ( imap_set ( dropped , ( uint32_t ) * ( ( uint32_t * ) pt ) , ( int * ) DROPPED_DUMMY ) == -1 ) { log_critical ( " " ) ; rc = -1 ; } } } else { log_critical ( " " , size , fn ) ; rc = -1 ; } free ( buffer ) ; } fclose ( fp ) ; return rc ; }
Returns 0 if successful or -1 in case of an error.
Returns 0 if successful or - 1 in case of an error .
/* no drop file, we have nothing to do */ /* get file size */