Merge pull request #8971 from nojb/filename_nul

Add Filename.null
master
Nicolás Ojeda Bär 2019-10-03 18:05:52 +02:00 committed by GitHub
commit 46ca15365a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 20 additions and 7 deletions

View File

@ -198,6 +198,9 @@ Working version
(Guillaume Munch-Maccagnoni, review by David Allsopp, Damien Doligez and
Gabriel Scherer)
- #8971: Add `Filename.null`, the conventional name of the "null" device.
(Nicolás Ojeda Bär, review by Xavier Leroy and Alain Frisch)
### Other libraries:
- #1939, #2023: Implement Unix.truncate and Unix.ftruncate on Windows.

View File

@ -70,6 +70,7 @@ let generic_dirname is_dir_sep current_dir_name name =
else trailing_sep (String.length name - 1)
module type SYSDEPS = sig
val null : string
val current_dir_name : string
val parent_dir_name : string
val dir_sep : string
@ -88,6 +89,7 @@ module type SYSDEPS = sig
end
module Unix : SYSDEPS = struct
let null = "/dev/null"
let current_dir_name = "."
let parent_dir_name = ".."
let dir_sep = "/"
@ -128,6 +130,7 @@ module Unix : SYSDEPS = struct
end
module Win32 : SYSDEPS = struct
let null = "NUL"
let current_dir_name = "."
let parent_dir_name = ".."
let dir_sep = "\\"
@ -261,6 +264,7 @@ Quoting commands for execution by cmd.exe is difficult.
end
module Cygwin : SYSDEPS = struct
let null = "/dev/null"
let current_dir_name = "."
let parent_dir_name = ".."
let dir_sep = "/"

View File

@ -118,6 +118,10 @@ val dirname : string -> string
This function conforms to the specification of POSIX.1-2008 for the
[dirname] utility. *)
val null : string
(** [null] is ["/dev/null"] on POSIX and ["NUL"] on Windows. It represents a
file on the OS that discards all writes and returns end of file on reads. *)
val temp_file : ?temp_dir: string -> string -> string -> string
(** [temp_file prefix suffix] returns the name of a
fresh temporary file in the temporary directory.

View File

@ -0,0 +1,8 @@
(* TEST
*)
let () =
let ic = open_in Filename.null in
match input_char ic with
| exception End_of_file -> close_in ic
| _ -> assert false

View File

@ -5,17 +5,11 @@ include unix
** native
*)
let null =
if Sys.win32 then
"NUL"
else
"/dev/null"
let () =
let ic, _ as process =
(* Redirect to null to avoid
"The process tried to write to a nonexistent pipe." on Windows *)
Printf.ksprintf Unix.open_process "echo toto > %s" null
Printf.ksprintf Unix.open_process "echo toto > %s" Filename.null
in
assert
(Unix.process_pid process = Unix.process_pid process);