shithub: mc

Download patch

ref: 54da79816fab4a03e8f6022d6c9764d9099abd60
parent: 5e7fe6940f78e778df65655c0fd181c28f1c6400
author: Ori Bernstein <[email protected]>
date: Fri Jan 3 06:11:00 EST 2014

Add 'tryslurp' function.

    Returns an empty slice if the file fails to be read.

--- a/libstd/slurp.myr
+++ b/libstd/slurp.myr
@@ -8,9 +8,17 @@
 
 pkg std =
 	const slurp : (path : byte[:] -> error(byte[:], byte[:]))
+	const tryslurp	: (path : byte[:] -> byte[:])
 ;;
 
 const Bufinc = 4096
+
+const tryslurp = {path
+	match slurp(path)
+	| `Some data:	-> data
+	| `None:	-> [][:]
+	;;
+}
 
 const slurp = {path
 	var fd