forked from HDFGroup/vol-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
h5delete.c
73 lines (62 loc) · 2.16 KB
/
h5delete.c
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
71
72
73
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* 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://support.hdfgroup.org/ftp/HDF5/releases. *
* If you do not have access to either file, you may request a copy from *
* [email protected]. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* h5delete tool
*
* Deletes storage via H5Fdelete() using the VOL connector specified in the
* environment variable.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <hdf5.h>
static void usage(void);
static void
usage(void)
{
fprintf(stderr, "Usage: h5delete [-f] <filename>\n");
}
int
main(int argc, const char *argv[])
{
bool quiet = false;
const char *name = NULL;
int ret = 0;
switch (argc) {
case 3:
if (strcmp(argv[1], "-f")) {
usage();
return EXIT_FAILURE;
}
quiet = true;
name = argv[2];
break;
case 2:
name = argv[1];
break;
default:
usage();
return EXIT_FAILURE;
}
H5E_BEGIN_TRY {
/* Only uses the environment variable at this time */
ret = (int)H5Fdelete(name, H5P_DEFAULT);
} H5E_END_TRY;
/* The native VOL connector does not implement the H5Fdelete() call
* at this time, so try to remove the file via the POSIX remove(3)
* call on failures.
*/
if (ret < 0)
ret = remove(name);
if (ret < 0 && !quiet)
fprintf(stderr, "Unable to delete storage at: %s\n", name);
return ret < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}