コード例 #1
0
ファイル: H5Omtime.c プロジェクト: aovi/UnrealEngine4
/*-------------------------------------------------------------------------
 * Function:	H5O_mtime_debug
 *
 * Purpose:	Prints debugging info for the message.
 *
 * Return:	Non-negative on success/Negative on failure
 *
 * Programmer:	Robb Matzke
 *		[email protected]
 *		Jul 24 1998
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
static herr_t
H5O_mtime_debug(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, const void *_mesg, FILE *stream,
		int indent, int fwidth)
{
    const time_t	*mesg = (const time_t *)_mesg;
    struct tm		*tm;
    char		buf[128];

    FUNC_ENTER_NOAPI_NOINIT_NOERR

    /* check args */
    assert(f);
    assert(mesg);
    assert(stream);
    assert(indent >= 0);
    assert(fwidth >= 0);

    /* debug */
    tm = HDlocaltime(mesg);

    HDstrftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %Z", tm);
    fprintf(stream, "%*s%-*s %s\n", indent, "", fwidth,
	    "Time:", buf);

    FUNC_LEAVE_NOAPI(SUCCEED)
}
コード例 #2
0
ファイル: mtime.c プロジェクト: chaako/sceptic3D
/*-------------------------------------------------------------------------
 * Function:	main
 *
 * Purpose:	H5O_mtime_decode() test.
 *
 * Return:	Success:
 *
 *		Failure:
 *
 * Programmer:	Robb Matzke
 *              Thursday, July 30, 1998
 *
 * Modifications:
 *              Added checks for old and new modification time messages
 *              in pre-created datafiles (generated with gen_old_mtime.c and
 *              gen_new_mtime.c).
 *              Quincey Koziol
 *              Friday, January  3, 2003
 *
 *-------------------------------------------------------------------------
 */
int
main(void)
{
    hid_t	fapl, file, space, dset;
    hsize_t	size[1] = {2};
    time_t	now;
    struct tm	*tm;
    H5O_info_t	oi1, oi2;
    signed char	buf1[32], buf2[32];
    char	filename[1024];

    h5_reset();
    fapl = h5_fileaccess();

    TESTING("modification time messages");

    /* Create the file, create a dataset, then close the file */
    h5_fixname(FILENAME[0], fapl, filename, sizeof filename);
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR;
    if((space = H5Screate_simple(1, size, NULL)) < 0) TEST_ERROR;
    if((dset = H5Dcreate2(file, "dset", H5T_NATIVE_SCHAR, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
        TEST_ERROR;
    now = HDtime(NULL);
    if(H5Dclose(dset) < 0) TEST_ERROR;
    if(H5Sclose(space) < 0) TEST_ERROR;
    if(H5Fclose(file) < 0) TEST_ERROR;

    /*
     * Open the file and get the modification time. We'll test the
     * H5Oget_info() arguments too: being able to stat something without
     * knowing its name.
     */
    h5_fixname(FILENAME[0], fapl, filename, sizeof filename);
    if((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0) TEST_ERROR;
    if(H5Oget_info_by_name(file, "dset", &oi1, H5P_DEFAULT) < 0) TEST_ERROR;
    if((dset = H5Dopen2(file, "dset", H5P_DEFAULT)) < 0) TEST_ERROR;
    if(H5Oget_info(dset, &oi2) < 0) TEST_ERROR;
    if(H5Dclose(dset) < 0) TEST_ERROR;
    if(H5Fclose(file) < 0) TEST_ERROR;

    /* Compare addresses & times from the two ways of calling H5Oget_info() */
    if(oi1.addr != oi2.addr || oi1.mtime != oi2.mtime) {
        H5_FAILED();
        puts("    Calling H5Oget_info() with the dataset ID returned");
        puts("    different values than calling it with a file and dataset");
        puts("    name.");
        goto error;
    }

    /* Compare times -- they must be within 60 seconds of one another */
    if(0 == oi1.mtime) {
        SKIPPED();
        puts("    The modification time could not be decoded on this OS.");
        puts("    Modification times will be mantained in the file but");
        puts("    cannot be queried on this system.  See H5O_mtime_decode().");
        return 0;
    } else if(HDfabs(HDdifftime(now, oi1.mtime)) > 60.0) {
        H5_FAILED();
        tm = HDlocaltime(&(oi1.mtime));
        HDstrftime((char*)buf1, sizeof buf1, "%Y-%m-%d %H:%M:%S", tm);
        tm = HDlocaltime(&now);
        HDstrftime((char*)buf2, sizeof buf2, "%Y-%m-%d %H:%M:%S", tm);
        printf("    got: %s\n    ans: %s\n", buf1, buf2);
        goto error;
    }
    PASSED();


    /* Check opening existing file with old-style modification time information
     * and make certain that the time is correct
     */
    TESTING("accessing old modification time messages");

    {
        char testfile[512]="";
        char *srcdir = HDgetenv("srcdir");

        if(srcdir && ((HDstrlen(srcdir) + strlen(TESTFILE1) + 1) < sizeof(testfile))){
            HDstrcpy(testfile, srcdir);
            HDstrcat(testfile, "/");
        }
        HDstrcat(testfile, TESTFILE1);
        file = H5Fopen(testfile, H5F_ACC_RDONLY, H5P_DEFAULT);
        if(file >= 0){
            if(H5Oget_info_by_name(file, "/Dataset1", &oi1, H5P_DEFAULT) < 0)
                TEST_ERROR;
            if(oi1.mtime != MTIME1) {
                H5_FAILED();
                   /* If this fails, examine H5Omtime.c.  Modification time is very
                    * system dependant (e.g., on Windows DST must be hardcoded). */
                puts("    Old modification time incorrect");
                goto error;
            }
            if(H5Fclose(file) < 0) TEST_ERROR;
        }
        else {
            H5_FAILED();
            printf("***cannot open the pre-created old modification test file (%s)\n",
                testfile);
            goto error;
        } /* end else */
    }
    PASSED();

    /* Check opening existing file with new-style modification time information
     * and make certain that the time is correct
     */
    TESTING("accessing new modification time messages");

    {
        char testfile[512]="";
        char *srcdir = HDgetenv("srcdir");

        if(srcdir && ((HDstrlen(srcdir) + strlen(TESTFILE2) + 1) < sizeof(testfile))){
            HDstrcpy(testfile, srcdir);
            HDstrcat(testfile, "/");
        }
        HDstrcat(testfile, TESTFILE2);
        file = H5Fopen(testfile, H5F_ACC_RDONLY, H5P_DEFAULT);
        if(file >= 0){
            if(H5Oget_info_by_name(file, "/Dataset1", &oi2, H5P_DEFAULT) < 0)
                TEST_ERROR;
            if(oi2.mtime != MTIME2) {
               H5_FAILED();
               puts("    Modification time incorrect.");
               goto error;
            }
            if(H5Fclose(file) < 0) TEST_ERROR;
        }
        else {
            H5_FAILED();
            printf("***cannot open the pre-created old modification test file (%s)\n",
                testfile);
            goto error;
        } /* end else */
    }
    PASSED();

    /* All looks good */
    puts("All modification time tests passed.");
    h5_cleanup(FILENAME, fapl);
    return 0;

    /* Something broke */
error:
    return 1;
}
コード例 #3
0
ファイル: H5make_libsettings.c プロジェクト: GATB/gatb-core
/*-------------------------------------------------------------------------
 * Function:  print_header
 *
 * Purpose:   Prints the header for the generated file.
 *
 * Return:    void
 *-------------------------------------------------------------------------
 */
static void
print_header(void)
{
    time_t        now = HDtime(NULL);
    struct tm        *tm = HDlocaltime(&now);
    char        real_name[30];
    char        host_name[256];
    int            i;
    const char        *s;
#ifdef H5_HAVE_GETPWUID
    struct passwd    *pwd = NULL;
#else
    int            pwd = 1;
#endif
    static const char    *month_name[] =
    {
    "Jan", "Feb", "Mar", "Apr", "May", "Jun",
    "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
    static const char    *purpose = "\
This machine-generated source code contains\n\
information about the library build configuration\n";

    /*
     * The real name is the first item from the passwd gecos field.
     */
#ifdef H5_HAVE_GETPWUID
    {
        size_t n;
        char *comma;

        if((pwd = HDgetpwuid(HDgetuid()))) {
            if((comma = HDstrchr(pwd->pw_gecos, ','))) {
                n = MIN(sizeof(real_name) - 1, (unsigned)(comma - pwd->pw_gecos));
                HDstrncpy(real_name, pwd->pw_gecos, n);
                real_name[n] = '\0';
            } /* end if */
            else {
                HDstrncpy(real_name, pwd->pw_gecos, sizeof(real_name));
                real_name[sizeof(real_name) - 1] = '\0';
            } /* end else */
        } /* end if */
        else
            real_name[0] = '\0';
    }
#else
    real_name[0] = '\0';
#endif

    /*
     * The FQDM of this host or the empty string.
     */
#ifdef H5_HAVE_GETHOSTNAME
    if(HDgethostname(host_name, sizeof(host_name)) < 0)
        host_name[0] = '\0';
#else
    host_name[0] = '\0';
#endif

    /*
     * The file header: warning, copyright notice, build information.
     */
    fprintf(rawoutstream, "/* Generated automatically by H5make_libsettings -- do not edit */\n\n\n");
    HDfputs(FileHeader, rawoutstream);        /*the copyright notice--see top of this file */

    fprintf(rawoutstream, " *\n * Created:\t\t%s %2d, %4d\n",
    month_name[tm->tm_mon], tm->tm_mday, 1900 + tm->tm_year);
    if(pwd || real_name[0] || host_name[0]) {
        fprintf(rawoutstream, " *\t\t\t");
        if(real_name[0])
            fprintf(rawoutstream, "%s <", real_name);
#ifdef H5_HAVE_GETPWUID
        if(pwd)
            HDfputs(pwd->pw_name, rawoutstream);
#endif
        if(host_name[0])
            fprintf(rawoutstream, "@%s", host_name);
        if(real_name[0])
            fprintf(rawoutstream, ">");
        HDfputc('\n', rawoutstream);
    } /* end if */
    fprintf(rawoutstream, " *\n * Purpose:\t\t");
    for(s = purpose; *s; s++) {
        HDfputc(*s, rawoutstream);
        if('\n' == *s && s[1])
            fprintf(rawoutstream, " *\t\t\t");
    } /* end for */

    fprintf(rawoutstream, " *\n * Modifications:\n *\n");
    fprintf(rawoutstream, " *\tDO NOT MAKE MODIFICATIONS TO THIS FILE!\n");
    fprintf(rawoutstream, " *\tIt was generated by code in `H5make_libsettings.c'.\n");

    fprintf(rawoutstream, " *\n *");
    for(i = 0; i < 73; i++)
        HDfputc('-', rawoutstream);
    fprintf(rawoutstream, "\n */\n\n");
}