shithub: mc

Download patch

ref: 93c80509bd8997bef851dacbd6399f3fa6554518
parent: 0185c4dbac1a09bfc22e230954c7dfbe7d0cd5a1
author: Ori Bernstein <[email protected]>
date: Mon Aug 18 13:49:49 EDT 2014

Add fput/fputv calls.

    This allows us to put to a specific fd.

--- a/libstd/fmt.myr
+++ b/libstd/fmt.myr
@@ -24,7 +24,9 @@
 
 pkg std =
 	const put	: (fmt : byte[:], args : ... -> size)
+	const fput	: (fd : fd, fmt : byte[:], args : ... -> size)
 	const putv	: (fmt : byte[:], ap : valist -> size)
+	const fputv	: (fd : fd, fmt : byte[:], ap : valist -> size)
 	const fatal	: (status : int, fmt : byte[:], args : ... -> void)
 	const fatalv	: (status : int, fmt : byte[:], ap : valist -> void)
 	const fmt	: (fmt : byte[:], args : ... -> byte[:])
@@ -35,17 +37,25 @@
 
 /* Writes a string of text up to 2 kb in size to stdout */
 const put = {fmt, args
-	-> putv(fmt, vastart(&args))
+	-> fputv(1, fmt, vastart(&args))
 }
 
+const fput = {fd, fmt, args
+	-> fputv(fd, fmt, vastart(&args))
+}
+
+const putv = {fmt, ap
+	-> fputv(1, fmt, ap)
+}
+
 /* Writes a string of text up to 2kb long to stdout, using a valist
    as the source of the arguments */
-const putv = {fmt, ap
+const fputv = {fd, fmt, ap
 	var buf : byte[2048]
 	var n
 	
 	n = bfmtv(buf[:], fmt, ap)
-	write(1, buf[:n])
+	write(fd, buf[:n])
 	-> n
 }