|
8 | 8 |
|
9 | 9 | #include "postgres.h"
|
10 | 10 |
|
| 11 | +#include "getopt_long.h" |
11 | 12 | #include "access/xlog_internal.h"
|
12 | 13 | #include "access/xlog.h"
|
13 | 14 | #include "access/xlogdefs.h"
|
@@ -80,26 +81,52 @@ main(int argc, char *argv[])
|
80 | 81 | void
|
81 | 82 | handle_args(int argc, char *argv[])
|
82 | 83 | {
|
83 |
| - if (argc > 1 && strcmp(argv[1], "-h") == 0) |
| 84 | + static struct option long_options[] = { |
| 85 | + {"filename", required_argument, NULL, 'f'}, |
| 86 | + {"ops-per-test", required_argument, NULL, 'o'}, |
| 87 | + {NULL, 0, NULL, 0} |
| 88 | + }; |
| 89 | + int option; /* Command line option */ |
| 90 | + int optindex = 0; /* used by getopt_long */ |
| 91 | + |
| 92 | + if (argc > 1) |
84 | 93 | {
|
85 |
| - fprintf(stderr, "test_fsync [-f filename] [ops-per-test]\n"); |
86 |
| - exit(1); |
| 94 | + if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0 || |
| 95 | + strcmp(argv[1], "-?") == 0) |
| 96 | + { |
| 97 | + fprintf(stderr, "test_fsync [-f filename] [ops-per-test]\n"); |
| 98 | + exit(0); |
| 99 | + } |
| 100 | + if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0) |
| 101 | + { |
| 102 | + fprintf(stderr,"test_fsync " PG_VERSION "\n"); |
| 103 | + exit(0); |
| 104 | + } |
87 | 105 | }
|
88 |
| - |
89 |
| - /* |
90 |
| - * arguments: ops_per_test and filename (optional) |
91 |
| - */ |
92 |
| - if (argc > 2 && strcmp(argv[1], "-f") == 0) |
| 106 | + |
| 107 | + while ((option = getopt_long(argc, argv, "f:o:", |
| 108 | + long_options, &optindex)) != -1) |
93 | 109 | {
|
94 |
| - filename = argv[2]; |
95 |
| - argv += 2; |
96 |
| - argc -= 2; |
| 110 | + switch (option) |
| 111 | + { |
| 112 | + case 'f': |
| 113 | + filename = strdup(optarg); |
| 114 | + break; |
| 115 | + |
| 116 | + case 'o': |
| 117 | + ops_per_test = atoi(optarg); |
| 118 | + break; |
| 119 | + |
| 120 | + default: |
| 121 | + fprintf(stderr, |
| 122 | + "Try \"%s --help\" for more information.\n", |
| 123 | + "test_fsync"); |
| 124 | + exit(1); |
| 125 | + break; |
| 126 | + } |
97 | 127 | }
|
98 | 128 |
|
99 |
| - if (argc > 1) |
100 |
| - ops_per_test = atoi(argv[1]); |
101 |
| - |
102 |
| - printf("Ops-per-test = %d\n\n", ops_per_test); |
| 129 | + printf("%d operations per test\n\n", ops_per_test); |
103 | 130 | }
|
104 | 131 |
|
105 | 132 | void
|
@@ -448,7 +475,7 @@ test_open_syncs(void)
|
448 | 475 | }
|
449 | 476 |
|
450 | 477 | if ((tmpfile = open(filename, O_RDWR | OPEN_SYNC_FLAG | PG_O_DIRECT, 0)) == -1)
|
451 |
| - printf(NA_FORMAT, "n/a**\n"); |
| 478 | + printf(NA_FORMAT, "o_direct", "n/a**\n"); |
452 | 479 | else
|
453 | 480 | {
|
454 | 481 | printf(LABEL_FORMAT, "2 open_sync 8k writes");
|
|
0 commit comments