package posixat

  1. Overview
  2. Docs
Bindings to the posix *at functions

Install

dune-project
 Dependency

Authors

Maintainers

Sources

v0.17.0.tar.gz
sha256=6f45df31dccb16b014243b1c155d5dbc59de3184562f4869cd9f6e3d05be03cc

doc/src/posixat/types.ml.html

Source file types.ml

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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
open Base

module Fd = struct
  type t = Unix.file_descr

  type info =
    | Win32_handle of int64
    | Win32_socket of int64
    | Unix_fd of int

  external info : t -> info = "shexp_fd_info"

  let sexp_of_t t =
    match info t with
    | Unix_fd n -> sexp_of_int n
    | Win32_handle h -> List [ Atom "HANDLE"; Atom (Printf.sprintf "0x%Lx" h) ]
    | Win32_socket s -> List [ Atom "SOCKET"; Atom (Printf.sprintf "%Lx" s) ]
  ;;
end

module Open_flag = struct
  type t =
    | O_RDONLY
    | O_WRONLY
    | O_RDWR
    | O_NONBLOCK
    | O_APPEND
    | O_CREAT
    | O_TRUNC
    | O_EXCL
    | O_NOCTTY
    | O_DSYNC
    | O_SYNC
    | O_RSYNC
    | O_SHARE_DELETE
    | O_CLOEXEC
    | O_KEEPEXEC [@if ocaml_version >= (4, 05, 0)]
    | O_NOFOLLOW
    | O_DIRECTORY
    | O_PATH
  [@@deriving sexp_of]

  let of_unix_open_flag (flag : Unix.open_flag) : t =
    match flag with
    | O_RDONLY -> O_RDONLY
    | O_WRONLY -> O_WRONLY
    | O_RDWR -> O_RDWR
    | O_NONBLOCK -> O_NONBLOCK
    | O_APPEND -> O_APPEND
    | O_CREAT -> O_CREAT
    | O_TRUNC -> O_TRUNC
    | O_EXCL -> O_EXCL
    | O_NOCTTY -> O_NOCTTY
    | O_DSYNC -> O_DSYNC
    | O_SYNC -> O_SYNC
    | O_RSYNC -> O_RSYNC
    | O_SHARE_DELETE -> O_SHARE_DELETE
    | O_CLOEXEC -> O_CLOEXEC
    | O_KEEPEXEC -> O_KEEPEXEC
  ;;

  let to_unix_open_flag_exn t : Unix.open_flag =
    match t with
    | O_RDONLY -> O_RDONLY
    | O_WRONLY -> O_WRONLY
    | O_RDWR -> O_RDWR
    | O_NONBLOCK -> O_NONBLOCK
    | O_APPEND -> O_APPEND
    | O_CREAT -> O_CREAT
    | O_TRUNC -> O_TRUNC
    | O_EXCL -> O_EXCL
    | O_NOCTTY -> O_NOCTTY
    | O_DSYNC -> O_DSYNC
    | O_SYNC -> O_SYNC
    | O_RSYNC -> O_RSYNC
    | O_SHARE_DELETE -> O_SHARE_DELETE
    | O_CLOEXEC -> O_CLOEXEC
    | O_KEEPEXEC -> O_KEEPEXEC
    | O_NOFOLLOW -> failwith "[Unix.open_flag] does not support O_NOFOLLOW"
    | O_DIRECTORY -> failwith "[Unix.open_flag] does not support O_DIRECTORY"
    | O_PATH -> failwith "[Unix.open_flag] does not support O_PATH"
  ;;
end

module At_flag = struct
  type t =
    | AT_EACCESS
    | AT_SYMLINK_FOLLOW
    | AT_SYMLINK_NOFOLLOW
    | AT_REMOVEDIR
  [@@deriving sexp_of]
end

module Access_permission = struct
  type t = Unix.access_permission =
    | R_OK
    | W_OK
    | X_OK
    | F_OK
  [@@deriving sexp_of]
end

module File_perm = struct
  type t = Unix.file_perm

  let sexp_of_t t = Sexp.Atom (Printf.sprintf "0o%3o" t)
end

module File_kind = struct
  type t = Unix.file_kind =
    | S_REG
    | S_DIR
    | S_CHR
    | S_BLK
    | S_LNK
    | S_FIFO
    | S_SOCK
  [@@deriving sexp_of]
end

module Stats = struct
  type t = Unix.LargeFile.stats =
    { st_dev : int
    ; st_ino : int
    ; st_kind : File_kind.t
    ; st_perm : File_perm.t
    ; st_nlink : int
    ; st_uid : int
    ; st_gid : int
    ; st_rdev : int
    ; st_size : int64
    ; st_atime : float
    ; st_mtime : float
    ; st_ctime : float
    }
  [@@deriving sexp_of]
end