[openfirmware] r1574 - ofw/core
svn at openfirmware.info
svn at openfirmware.info
Fri Dec 11 07:19:28 CET 2009
Author: wmb
Date: 2009-12-11 07:19:28 +0100 (Fri, 11 Dec 2009)
New Revision: 1574
Modified:
ofw/core/filecmds.fth
Log:
OFW core - added $read-file word.
Modified: ofw/core/filecmds.fth
===================================================================
--- ofw/core/filecmds.fth 2009-12-11 06:18:41 UTC (rev 1573)
+++ ofw/core/filecmds.fth 2009-12-11 06:19:28 UTC (rev 1574)
@@ -669,6 +669,20 @@
r> close-dev ( len )
load-base swap list
;
+
+\ Read entire file into allocated memory
+: $read-file ( filename$ -- true | data$ false )
+ open-dev ?dup 0= if true exit then >r ( r: ih )
+ " size" r@ $call-method drop ( len r: ih )
+ dup alloc-mem swap ( adr len r: ih )
+ 2dup " read" r@ $call-method ( adr len actual r: ih )
+ r> close-dev ( adr len actual )
+ over <> if ( adr len )
+ free-mem true exit
+ then ( adr len )
+ false
+;
+
\ LICENSE_BEGIN
\ Copyright (c) 2006 FirmWorks
\
More information about the openfirmware
mailing list