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

Add support for -r (read-only) open before locking

And only supports a single file per invocation now.
parent 3b794a8c
No related branches found
No related tags found
No related merge requests found
Pipeline #7116 passed
#include <stdlib.h>
#include <string.h>
#include "filewrap.h" #include "filewrap.h"
void show_locks(const char* path) int main(int argc, char** argv)
{ {
int file = open(path, O_RDWR); int access = O_RDWR;
int argn = 1;
if(strcmp(argv[argn], "-r") == 0) {
access = O_RDONLY;
++argn;
}
const char* path = argv[argn++];
int file = open(path, access);
if(file == -1) { if(file == -1) {
perror(path); perror(path);
return; return EXIT_FAILURE;
} }
off_t len = filelength(file); off_t len = filelength(file);
...@@ -17,11 +27,5 @@ void show_locks(const char* path) ...@@ -17,11 +27,5 @@ void show_locks(const char* path)
unlock(file, o, 1); unlock(file, o, 1);
} }
close(file); close(file);
} return EXIT_SUCCESS;
int main(int argc, char** argv)
{
for(int i = 1; i < argc; ++i)
show_locks(argv[i]);
return 0;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment