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

Add -c and -R options

Really need to make the option order (arity) neutral
parent a2d23c40
No related branches found
No related tags found
No related merge requests found
...@@ -8,11 +8,14 @@ int main(int argc, char** argv) ...@@ -8,11 +8,14 @@ int main(int argc, char** argv)
char* share = "NWA"; char* share = "NWA";
bool try_all = true; bool try_all = true;
bool loop = false; bool loop = false;
bool rm = false;
if(argc < 2) { if(argc < 2) {
printf("usage: sopenfile [-r] [-l] <path/filename> [share-mode]\n"); printf("usage: sopenfile [-r] [-l] <path/filename> [share-mode]\n");
printf("\n"); printf("\n");
printf("-r open file read-only instead of read/write\n"); printf("-r open file read-only instead of read/write\n");
printf("-c open file with create permissions\n");
printf("-R remove file after open\n");
printf("-l loop until failure\n"); printf("-l loop until failure\n");
printf("\n"); printf("\n");
printf("share-mode: N (deny-none)\n"); printf("share-mode: N (deny-none)\n");
...@@ -25,6 +28,14 @@ int main(int argc, char** argv) ...@@ -25,6 +28,14 @@ int main(int argc, char** argv)
access = O_RDONLY; access = O_RDONLY;
++argn; ++argn;
} }
if(strcmp(argv[argn], "-c") == 0) {
access |= O_CREAT;
++argv;
}
if(strcmp(argv[argn], "-R") == 0) {
rm = true;
++argn;
}
if(strcmp(argv[argn], "-l") == 0) { if(strcmp(argv[argn], "-l") == 0) {
loop = true; loop = true;
++argn; ++argn;
...@@ -54,11 +65,13 @@ int main(int argc, char** argv) ...@@ -54,11 +65,13 @@ int main(int argc, char** argv)
return EXIT_FAILURE; return EXIT_FAILURE;
} }
fprintf(stderr, "%s Deny-%c (share mode %x): ", path, toupper(share_flag), share_mode); fprintf(stderr, "%s Deny-%c (share mode %x): ", path, toupper(share_flag), share_mode);
int file = sopen(path, access, share_mode); int file = sopen(path, access, share_mode, DEFFILEMODE);
if(file < 0) if(file < 0)
fprintf(stderr, "Error %d (%s)\n", errno, strerror(errno)); fprintf(stderr, "Error %d (%s)\n", errno, strerror(errno));
else { else {
printf("Success\n"); printf("Success\n");
if(rm)
printf("remove(%s) = %d\n", path, unlink(path));
if(!try_all) { if(!try_all) {
fprintf(stderr, "Hit enter\n"); fprintf(stderr, "Hit enter\n");
getchar(); getchar();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment