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

Some helpful test programs for testing file record locking.

parent 043feff8
No related branches found
No related tags found
No related merge requests found
Pipeline #7115 passed
#include <stdlib.h>
#include "filewrap.h"
int main(int argc, char** argv)
{
int access = O_RDWR;
const char* path = argv[1];
if(argc < 4) {
fprintf(stderr, "usage: lockfile path offset length\n");
return 0;
}
int file = open(path, access);
if(file < 0) {
puts("Open failure");
perror(path);
return -1;
}
int result = lock(file, atoi(argv[2]), atoi(argv[3]));
if(result != 0) {
puts("Lock failure");
perror(path);
return -1;
}
printf("Hit enter\n");
getchar();
close(file);
return 0;
}
#include "filewrap.h"
void show_locks(const char* path)
{
int file = open(path, O_RDWR);
if(file == -1) {
perror(path);
return;
}
off_t len = filelength(file);
for(off_t o = 0; o < len; ++o) {
if(lock(file, o, 1) != 0)
printf("Byte 0x%" PRIx64 " is locked\n", o);
else
unlock(file, o, 1);
}
close(file);
}
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.
Finish editing this message first!
Please register or to comment