summaryrefslogtreecommitdiffstats
path: root/tools/test/misc/clear_open_chk.c
blob: b57eb4a9e6254166d5fb6b09fab1482b34630e3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by The HDF Group.                                               *
 * All rights reserved.                                                      *
 *                                                                           *
 * This file is part of HDF5.  The full HDF5 copyright notice, including     *
 * terms governing use, modification, and redistribution, is contained in    *
 * the COPYING file, which can be found at the root of the source code       *
 * distribution tree, or in https://www.hdfgroup.org/licenses.               *
 * If you do not have access to either file, you may request a copy from     *
 * help@hdfgroup.org.                                                        *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "hdf5.h"
#include "H5private.h"
#include "h5tools.h"

static void usage(void);

static void
usage(void)
{
    fprintf(stdout, "\n");
    fprintf(stdout, "Usage error!\n");
    fprintf(stdout, "Usage: clear_open_chk filename\n");
} /* usage() */

/*-------------------------------------------------------------------------
 * Function:    main
 *
 * Purpose:    To open the file which has zero or nonzero status_flags in
 *        the superblock.
 *
 * Return:    0 on success
 *        1 on failure
 *
 * Programmer:    Vailin Choi; July 2013
 *
 *-------------------------------------------------------------------------
 */
int
main(int argc, char *argv[])
{
    char *fname; /* The HDF5 file name */
    hid_t fid;   /* File ID */

    /* Check the # of arguments */
    if (argc != 2) {
        usage();
        HDexit(EXIT_FAILURE);
    }

    /* Get the file name */
    fname = HDstrdup(argv[1]);

    /* Try opening the file */
    if ((fid = h5tools_fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT, FALSE, NULL, (size_t)0)) < 0) {
        fprintf(stderr, "clear_open_chk: unable to open the file\n");
        free(fname);
        HDexit(EXIT_FAILURE);
    }
    free(fname);

    /* Close the file */
    if (H5Fclose(fid) < 0) {
        fprintf(stderr, "clear_open_chk: cannot close the file\n");
        HDexit(EXIT_FAILURE);
    }

    /* Return success */
    HDexit(EXIT_SUCCESS);
} /* main() */