File: flock.c

package info (click to toggle)
coq 8.16.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 40,596 kB
  • sloc: ml: 219,376; sh: 3,545; python: 3,231; ansic: 2,529; makefile: 767; lisp: 279; javascript: 63; xml: 24; sed: 2
file content (41 lines) | stat: -rw-r--r-- 792 bytes parent folder | download | duplicates (2)
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) );
}