[go: up one dir, main page]

File: util.mli

package info (click to toggle)
approx 4.5-1%2Bsqueeze1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 428 kB
  • ctags: 683
  • sloc: ml: 1,957; sh: 45; makefile: 36
file content (213 lines) | stat: -rw-r--r-- 5,999 bytes parent folder | download
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
(* approx: proxy server for Debian archive files
   Copyright (C) 2010  Eric C. Cooper <ecc@cmu.edu>
   Released under the GNU General Public License *)

(* Check if the first string is a prefix of the second *)

val is_prefix : string -> string -> bool

(* Extract substring s.[from] .. s.[until-1] *)

val substring : ?from:int -> ?until:int -> string -> string

(* Split a string at each occurrence of a separator *)

val split : char -> string -> string list

(* Join a list of strings with a separator (inverse of split) *)

val join : char -> string list -> string

(* Split a string into lines *)

val split_lines : string -> string list

(* Split a pathname into a list of components.
   Initial and final "/" map to empty strings;
   "/" by itself maps to [""; ""] *)

val explode_path : string -> string list

(* Inverse of explode_path *)

val implode_path : string list -> string

(* Infix operator to concatenate two pathname components *)

val (^/) : string -> string -> string

(* Create a directory, including any intermediate directories
   along the specified path (like "mkdir --parents") *)

val make_directory : string -> unit

(* Return a quoted string *)

val quoted_string : string -> string

(* Return the relative portion of a pathname *)

val relative_path : string -> string

(* Return the relative portion of a URL *)

val relative_url : string -> string

(* Split a filename into the leading portion without an extension
   and the extension, if any, beginning with '.' *)

val split_extension : string -> string * string

(* Return a filename with its extension, if any, removed *)

val without_extension : string -> string

(* Return the extension of a filename, including the initial '.' *)

val extension : string -> string

(* Return the underlying value of an option, otherwise raise Not_found *)

val the : 'a option -> 'a

(* Call a function making sure that a cleanup procedure is called
   before returning the result of the function or raising an exception *)

val unwind_protect : (unit -> 'a) -> (unit -> unit) -> 'a

(* Apply a function to a resource that is acquired and released by
   the given functions *)

val with_resource : ('t -> unit) -> ('a -> 't) -> 'a -> ('t -> 'b) -> 'b

(* Open an input channel and apply a function to the channel,
   using unwind_protect to ensure that the channel gets closed *)

val with_in_channel : ('a -> in_channel) -> 'a -> (in_channel -> 'b) -> 'b

(* Open an output channel and apply a function to the channel,
   using unwind_protect to ensure that the channel gets closed *)

val with_out_channel : ('a -> out_channel) -> 'a -> (out_channel -> 'b) -> 'b

(* Spawn a shell command and apply a function to its output,
   using unwind_protect to ensure that the channel gets closed *)

val with_process : ?error:string -> string -> (in_channel -> 'a) -> 'a

(* Generate a unique string, suitable for use as a filename *)

val gensym : string -> string

(* Return the name of the temporary file directory *)

val tmp_dir : unit -> string

(* Attempt to remove a file but ignore any errors *)

val rm : string -> unit

(* Check if a file is compressed by examining its extension *)

val is_compressed : string -> bool

(* Decompress a file to a temporary location and return
   the temporary file name, which must be removed by the caller *)

val decompress : string -> string

(* Decompress a file and apply a function to the temporary file name,
   using unwind_protect to ensure that the temporary file gets removed *)

val with_decompressed : string -> (string -> 'a) -> 'a

(* Apply a function to a file or to a temporary decompressed version of it *)

val decompress_and_apply : (string -> 'a) -> string -> 'a

(* Return a list of possible compressed versions of the given file *)

val compressed_versions : string -> string list

(* Return the newest possibly-compressed version of the given file *)

val newest_version : string -> string

(* Open a file for input, decompressing it if necessary *)

val open_file : string -> in_channel

(* Open a file for exclusive output *)

val open_out_excl : string -> out_channel

(* Copy an input channel to an output channel *)

val copy_channel : in_channel -> out_channel -> unit

(* Open a temporary file for output in the same directory as the given one
   (so that it can be renamed back to the original), apply the given function,
   and return the file name *)

val with_temp_file : string -> (out_channel -> unit) -> string

(* Update the ctime of the given file, if it exists,
   without changing its access or modification times *)

val update_ctime : string -> unit

(* Check if a filename exists and is a directory *)

val directory_exists : string -> bool

(* Check if a filename is a symbolic link *)

val is_symlink : string -> bool

(* Create a generic iterator function from a fold function *)

val iter_of_fold : ((unit -> 'a) -> unit -> 'b) -> 'a -> 'b

(* Fold a function over each directory below a given path *)

val fold_dirs : ('a -> string -> 'a) -> 'a -> string -> 'a

val iter_dirs : (string -> unit) -> string -> unit

(* Fold a function over each non-directory below a given path *)

val fold_non_dirs : ('a -> string -> 'a) -> 'a -> string -> 'a

val iter_non_dirs : (string -> unit) -> string -> unit

(* Return the modification time of a file *)

val file_modtime : string -> float

(* Return the size of a file *)

val file_size : string -> int64

(* Return the MD5 digest of a file *)

val file_md5sum : string -> string

(* Return the SHA1 digest of a file *)

val file_sha1sum : string -> string

(* Return the SHA256 digest of a file *)

val file_sha256sum : string -> string

(* Drop privileges to those of the given user and group *)

val drop_privileges : user:string -> group:string -> unit

(* Check that the program is executing as the given user and group *)

val check_id : user:string -> group:string -> unit

(* Convert a socket address to a string *)

val string_of_sockaddr : Unix.sockaddr -> with_port:bool -> string