caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Unix.stat sometimes fails on Win32 port
@ 2003-08-06 10:02 Richard Jones
  2003-08-06 14:39 ` David Brown
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Jones @ 2003-08-06 10:02 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-08-06 17:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-08-06 10:02 [Caml-list] Unix.stat sometimes fails on Win32 port Richard Jones
2003-08-06 14:39 ` David Brown
2003-08-06 14:49   ` Richard Jones
2003-08-06 16:21     ` David Brown
2003-08-06 17:01       ` John Carr

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).