Пример #1
0
int gmx_fio_get_output_file_positions(gmx_file_position_t **p_outputfiles,
                                      int                  *p_nfiles)
{
    int                   i, nfiles, rc, nalloc;
    int                   pos_hi, pos_lo;
    long                  pos;
    gmx_file_position_t * outputfiles;
    char                  buf[STRLEN];
    t_fileio             *cur;

    nfiles = 0;

    /* pre-allocate 100 files */
    nalloc = 100;
    snew(outputfiles, nalloc);

    cur = gmx_fio_get_first();
    while (cur)
    {
        /* Skip the checkpoint files themselves, since they could be open when
           we call this routine... */
        /* also skip debug files (shoud be the only iFTP==efNR) */
        if (cur->bOpen &&
            !cur->bRead &&
            !cur->bStdio &&
            cur->iFTP != efCPT &&
            cur->iFTP != efNR)
        {
            int ret;
            /* This is an output file currently open for writing, add it */
            if (nfiles == nalloc)
            {
                nalloc += 100;
                srenew(outputfiles, nalloc);
            }

            strncpy(outputfiles[nfiles].filename, cur->fn, STRLEN - 1);

            /* Get the file position */
            gmx_fio_int_get_file_position(cur, &outputfiles[nfiles].offset);
#ifndef GMX_FAHCORE
            outputfiles[nfiles].chksum_size
                = gmx_fio_int_get_file_md5(cur,
                                           outputfiles[nfiles].offset,
                                           outputfiles[nfiles].chksum);
#endif
            nfiles++;
        }

        cur = gmx_fio_get_next(cur);
    }
    *p_nfiles      = nfiles;
    *p_outputfiles = outputfiles;

    return 0;
}
Пример #2
0
int gmx_fio_fclose(FILE *fp)
{
    t_fileio *cur;
    t_fileio *found = NULL;
    int       rc    = -1;

    cur = gmx_fio_get_first();
    while (cur)
    {
        if (cur->fp == fp)
        {
            rc = gmx_fio_close_locked(cur);
            gmx_fio_remove(cur);
            gmx_fio_stop_getting_next(cur);
            break;
        }
        cur = gmx_fio_get_next(cur);
    }

    return rc;
}
Пример #3
0
t_fileio *gmx_fio_all_output_fsync(void)
{
    t_fileio *ret = NULL;
    t_fileio *cur;

    cur = gmx_fio_get_first();
    while (cur)
    {
        /* skip debug files (shoud be the only iFTP==efNR) */
        if (cur->bOpen &&
            !cur->bRead &&
            !cur->bStdio &&
            cur->iFTP != efNR)
        {
            /* if any of them fails, return failure code */
            int rc = gmx_fio_int_fsync(cur);
            if (rc != 0 && !ret)
            {
                ret = cur;
            }
        }
        cur = gmx_fio_get_next(cur);
    }

    /* in addition, we force these to be written out too, if they're being
       redirected. We don't check for errors because errors most likely mean
       that they're not redirected. */
    fflush(stdout);
    fflush(stderr);
#if (defined(HAVE_FSYNC))
    /* again, fahcore defines HAVE_FSYNC and fsync() */
    fsync(STDOUT_FILENO);
    fsync(STDERR_FILENO);
#endif

    return ret;
}