1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
#include <stdio.h>
#include <sys/file.h>
#define CAML_NAME_SPACE
#include <caml/mlvalues.h>
#include <caml/alloc.h>
#include <caml/memory.h>
#include <caml/custom.h>
#include <caml/fail.h>
CAMLprim value coq_flock(value fd, value operation)
{
CAMLparam2 (fd, operation);
int fd_i = Int_val(fd);
int operation_i = Int_val(operation);
// printf("stub_fd: %d ; op_id: %d", fd_i, operation_i);
int operation_f = 0;
switch (operation_i) {
case 0:
operation_f = LOCK_SH;
break;
case 1:
operation_f = LOCK_EX;
break;
case 2:
operation_f = LOCK_UN;
break;
default:
caml_invalid_argument("Incorrect flock operation");
break;
};
int res = flock(fd_i, operation_f);
if (res != 0) { perror("flock: "); };
CAMLreturn ( Val_int(res) );
}
|