ref: 51db6fac184fd46a4c79df775e6f2df90641b4fa
parent: 45731235afea3fd7904d9052df8b31cd0b49a512
author: Ori Bernstein <[email protected]>
date: Wed Dec 18 09:44:58 EST 2013
Don't unconditionally create files when calling open()
--- a/bio.myr
+++ b/bio.myr
@@ -85,7 +85,7 @@
/* Opens a file with mode provided. */
const open = {path, mode
- -> create(path, mode, 0o777)
+ -> sysopen(path, mode, sysmode(mode), 0o777)
}
/*
@@ -93,20 +93,24 @@
the requested mode, with the requested permissions
*/
const create = {path, mode, perm
- var openmode
- var fd
+ -> sysopen(path, mode, sysmode(mode) | std.Ocreat, perm)
+}
- /* map from the bio modes to the unix open modes */
- if mode == Rd
- openmode = std.Ordonly
- elif mode == Wr
- openmode = std.Owronly
- elif mode == Rw
- openmode = std.Ordwr
+/* map from the bio modes to the unix open modes */
+const sysmode = {mode
+ match mode
+ | Rd: -> std.Ordonly
+ | Wr: -> std.Owronly
+ | Rw: -> std.Ordwr
+ | _: std.fatal(1, "bio: bad file mode")
;;
- openmode |= std.Ocreat
+ -> 0
+}
- /* open the file, and return it */
+/* open the file, and return it */
+const sysopen = {path, mode, openmode, perm
+ var fd
+
fd = std.open(path, openmode, perm castto(int64))
if fd < 0
-> `std.None