Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Unix.stat sometimes fails on Win32 port
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Richard Jones <rich@a...>
Subject: [Caml-list] Unix.stat sometimes fails on Win32 port
Demonstration program below. Basically if you compile this and run

	winfiletest d c:\
	winfiletest d c:\temp
	winfiletest d c:\temp\      <-- this one fails
	winfiletest d c:\temp\.

This is specifically a problem with lablgtk2 which returns directory
names with a trailing slash from the file selection dialog. Works OK
on the Unix port, but fails under Windows.

Rich.

----------------------------------------------------------------------

open Unix

let perror f default =
  try f ()
  with
    Unix_error (errno, syscall, operand) ->
      Printf.eprintf "%s: %s: %s\n" syscall operand (error_message errno);
      Pervasives.flush Pervasives.stderr;
      default

(* Filename concatenation. *)
let (//) = Filename.concat

(* Check if path is a directory. *)
let is_dir path =
  perror (fun () -> (stat path).st_kind = S_DIR) false

(* Check if path is a file. *)
let is_file path =
  perror (fun () -> (stat path).st_kind = S_REG) false

let () =
  if Array.length Sys.argv < 3 then
    failwith "usage: winfiletest f|d name";
  if Sys.argv.(1) = "f" then
    if is_file Sys.argv.(2) then
      Printf.printf "is_file true\n"
    else
      Printf.printf "is_file false\n"
  else
    if is_dir Sys.argv.(2) then
      Printf.printf "is_dir true\n"
    else
      Printf.printf "is_dir false\n";

-- 
Richard Jones. http://www.annexia.org/ http://freshmeat.net/users/rwmj
Merjis Ltd. http://www.merjis.com/ - all your business data are belong to you.
"My karma ran over your dogma"

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners