src/components/io/linux-io.c
// Code to just count events in file, fills in a context.
// This may be a dummy from init_component.
Code to just count events in file, fills in a context.
This may be a dummy from init_component.
Code to just count events in file fills in a context . This may be a dummy from init_component .
static int io_count_events(_io_context_t *myCtx)
{
    myCtx->EventCount = 0;
    myCtx->pFile = fopen (IO_FILENAME,"r");
    if (myCtx->pFile == NULL) {
        snprintf(_io_vector.cmp_info.disabled_reason, PAPI_MAX_STR_LEN-1,
        "Failed to open target file '%s'.", IO_FILENAME);
        return PAPI_ENOSUPP;
    }
    while (1) {
        char *res;
        res = fgets(myCtx->line, FILE_LINE_SIZE, myCtx->pFile);
        if (res  == NULL) break;
        if (strlen(myCtx->line) == (FILE_LINE_SIZE-1)) {
            fclose(myCtx->pFile);
            snprintf(_io_vector.cmp_info.disabled_reason, PAPI_MAX_STR_LEN-1,
            "File '%s' line %i too long.", IO_FILENAME, myCtx->EventCount+1);
            return PAPI_ENOSUPP;
        }
        char dummy[FILE_LINE_SIZE] = {0};
        long long tmplong = 0LL;
        int nf = sscanf( myCtx->line, "%s %lld\n", dummy, &tmplong);
        if (nf != 2 || strlen(dummy)<2 || dummy[strlen(dummy)-1] != ':') {
            fclose(myCtx->pFile);
            snprintf(_io_vector.cmp_info.disabled_reason, PAPI_MAX_STR_LEN-1,
            "File '%s' line %i bad format.", IO_FILENAME, myCtx->EventCount+1);
            return PAPI_ENOSUPP;
        }
        myCtx->EventCount++; 
    } 
    return PAPI_OK;
}
static int io_count_events ( _io_context_t * myCtx ) { myCtx -> EventCount = 0 ; myCtx -> pFile = fopen ( IO_FILENAME , " " ) ; if ( myCtx -> pFile == NULL ) { snprintf ( _io_vector . cmp_info . disabled_reason , PAPI_MAX_STR_LEN - 1 , " " , IO_FILENAME ) ; return PAPI_ENOSUPP ; } while ( 1 ) { char * res ; res = fgets ( myCtx -> line , FILE_LINE_SIZE , myCtx -> pFile ) ; if ( res == NULL ) break ; if ( strlen ( myCtx -> line ) == ( FILE_LINE_SIZE - 1 ) ) { fclose ( myCtx -> pFile ) ; snprintf ( _io_vector . cmp_info . disabled_reason , PAPI_MAX_STR_LEN - 1 , " " , IO_FILENAME , myCtx -> EventCount + 1 ) ; return PAPI_ENOSUPP ; } char dummy [ FILE_LINE_SIZE ] = { 0 } ; long long tmplong = 0LL ; int nf = sscanf ( myCtx -> line , " \n " , dummy , & tmplong ) ; if ( nf != 2 || strlen ( dummy ) < 2 || dummy [ strlen ( dummy ) - 1 ] != ' ' ) { fclose ( myCtx -> pFile ) ; snprintf ( _io_vector . cmp_info . disabled_reason , PAPI_MAX_STR_LEN - 1 , " " , IO_FILENAME , myCtx -> EventCount + 1 ) ; return PAPI_ENOSUPP ; } myCtx -> EventCount ++ ; } return PAPI_OK ; }
Code to just count events in file, fills in a context.
Code to just count events in file fills in a context .
// Just count the lines, basic vetting for ability to parse. // fgets guarantees z-terminator, reads at most FILE_LINE_SIZE-1 bytes. // If the read filled the whole buffer, line is too long. // END READING. // NOTE: We intentionally leave file open; up to caller to close // or rewind and continue.