| 139 | } |
| 140 | |
| 141 | static void |
| 142 | handle_args(int argc, char *argv[]) |
| 143 | { |
| 144 | static struct option long_options[] = { |
| 145 | {"filename", required_argument, NULL, 'f'}, |
| 146 | {"secs-per-test", required_argument, NULL, 's'}, |
| 147 | {NULL, 0, NULL, 0} |
| 148 | }; |
| 149 | |
| 150 | int option; /* Command line option */ |
| 151 | int optindex = 0; /* used by getopt_long */ |
| 152 | unsigned long optval; /* used for option parsing */ |
| 153 | char *endptr; |
| 154 | |
| 155 | if (argc > 1) |
| 156 | { |
| 157 | if (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-?") == 0) |
| 158 | { |
| 159 | printf(_("Usage: %s [-f FILENAME] [-s SECS-PER-TEST]\n"), progname); |
| 160 | exit(0); |
| 161 | } |
| 162 | if (strcmp(argv[1], "--version") == 0 || strcmp(argv[1], "-V") == 0) |
| 163 | { |
| 164 | puts("pg_test_fsync (Apache Cloudberry) " PG_VERSION); |
| 165 | exit(0); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | while ((option = getopt_long(argc, argv, "f:s:", |
| 170 | long_options, &optindex)) != -1) |
| 171 | { |
| 172 | switch (option) |
| 173 | { |
| 174 | case 'f': |
| 175 | filename = pg_strdup(optarg); |
| 176 | break; |
| 177 | |
| 178 | case 's': |
| 179 | errno = 0; |
| 180 | optval = strtoul(optarg, &endptr, 10); |
| 181 | |
| 182 | if (endptr == optarg || *endptr != '\0' || |
| 183 | errno != 0 || optval != (unsigned int) optval) |
| 184 | { |
| 185 | pg_log_error("invalid argument for option %s", "--secs-per-test"); |
| 186 | fprintf(stderr, _("Try \"%s --help\" for more information.\n"), progname); |
| 187 | exit(1); |
| 188 | } |
| 189 | |
| 190 | secs_per_test = (unsigned int) optval; |
| 191 | if (secs_per_test == 0) |
| 192 | { |
| 193 | pg_log_error("%s must be in range %u..%u", |
| 194 | "--secs-per-test", 1, UINT_MAX); |
| 195 | exit(1); |
| 196 | } |
| 197 | break; |
| 198 |
no test coverage detected