Skip to content
Snippets Groups Projects
Commit 6cc93d8c authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Add a -l (loop) option to retry until failure

Pretty remedial option parsing here, the order is significant
parent 2e47ac98
Branches eugeneso/lord2_errorhandling
No related tags found
No related merge requests found
......@@ -7,11 +7,13 @@ int main(int argc, char** argv)
int access = O_RDWR;
char* share = "NWA";
bool try_all = true;
bool loop = false;
if(argc < 2) {
printf("usage: sopenfile [-r] <path/filename> [share-mode]\n");
printf("usage: sopenfile [-r] [-l] <path/filename> [share-mode]\n");
printf("\n");
printf("-r open file read-only instead of read/write\n");
printf("-l loop until failure\n");
printf("\n");
printf("share-mode: N (deny-none)\n");
printf(" W (deny-write)\n");
......@@ -23,12 +25,17 @@ int main(int argc, char** argv)
access = O_RDONLY;
++argn;
}
if(strcmp(argv[argn], "-l") == 0) {
loop = true;
++argn;
}
const char* path = argv[argn++];
if(argc > argn) {
share = argv[argn++];
try_all = false;
}
do {
for(int i = 0; share[i] != '\0'; ++i) {
int share_mode = 0;
char share_flag = share[i];
......@@ -59,6 +66,7 @@ int main(int argc, char** argv)
close(file);
}
}
return EXIT_SUCCESS;
} while(loop && errno == 0);
return errno == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment