changeset 79:80d8c9248f85

Began work on File
author Mike Pavone <pavone@retrodev.com>
date Sat, 10 Jul 2010 18:02:04 -0400
parents 4d5ea487f810
children d78613686a38
files file.rhope kernel.rhope
diffstat 2 files changed, 131 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/file.rhope	Sat Jul 10 18:02:04 2010 -0400
@@ -0,0 +1,128 @@
+
+
+Blueprint Stat
+{
+	
+}
+
+Blueprint File
+{
+	Name
+}
+
+Blueprint File Read
+{
+	Name
+	Descriptor(Int32,Naked)
+	Info
+	Buffer
+}
+
+Blueprint File Write
+{
+	Name
+	Descriptor(Int32,Naked)
+	Info
+	Buffer
+}
+
+Blueprint File ReadWrite
+{
+	Name
+	Read Offset(Int64,Naked)
+	Descriptor(Int32,Naked)
+	Info
+	Buffer
+}
+
+File[name:out]
+{
+	out <- [Build[File()]]Name <<[name]
+}
+
+
+Open@File[file,mode:out,error]
+{
+	If[[mode]=["r"]]
+	{ 
+		imode <- 
+		type <- File Read()
+		out <- Val[ofile]
+	}{
+		If[[mode]=["w"]]
+		{ 
+			imode <- 
+			type <- File Write()
+			out <- Val[ofile]
+		}{
+			,error <- If[[mode]=["rw"]]
+			{ 
+				imode <- 
+				type <- File ReadWrite()
+				out <- [ofile]Read Offset <<[0i64]
+			}
+		}
+	}
+	fd <- open[[file]Name >>]
+	error <- If[[fd]=[-1i32]] {}
+	{
+		ofile <- [[[[Build[type]	
+			]Name <<[ [file]Name >> ]
+			]Descriptor <<[fd]
+			]Info <<[Stat[fd]]
+			]Buffer <<[Array[]]
+	}
+}
+
+Read@File[file,bytes:data,outfile,error]
+{
+	,error <- [file]Open["r"]
+	{
+		data,outfile,error <- [~]Read[bytes]
+	}
+}
+
+Append@File[file,data:out,error]
+{
+	,error <- [file]Open["w"]
+	{
+		out,error <- [~]Append[data]
+	}
+}
+
+String@File[file:out,error]
+{
+	,error <- [file]Open["w"]
+	{
+		out,error <- String[~]
+	}
+}
+
+Read@File Read[file,inbytes(Int32):data,outfile,error]
+{
+	buflen <- [[file]Buffer >>]Length
+	If[buflen]
+	{
+		If[[inbytes]=[buflen]]
+		{	
+			data <- [file]Buffer >>
+			outfile <- [file]Buffer <<[Array[]]
+		}{
+			If[[inbytes]<[buflen]]
+			{
+			
+			}{
+				
+			}
+		}
+	}{
+		readbytes, mdata <- read[[file]Descriptor >>, [Array[]]Set[inbytes, 0u8], Int64[inbytes]]
+		error <- If[[readbytes]<[0i64]] {}
+		{
+			outfile <- file
+			data <- [mdata]Length <<[ Trunc Int32[readbytes] ]
+		}
+			
+	}
+}
+
--- a/kernel.rhope	Thu Jul 08 21:55:47 2010 -0400
+++ b/kernel.rhope	Sat Jul 10 18:02:04 2010 -0400
@@ -40,8 +40,11 @@
 
 Foreign C:libc
 {
+	open[name(Array,Raw Pointer),flags(Int32,Naked):filedes(Int32,Naked)]
 	write[filedes(Int32,Naked),buf(Array,Raw Pointer),nbyte(Int64,Naked):written(Int32,Naked)]
 	read[filedes(Int32,Naked),buf(Array,Raw Pointer,Mutable),nbyte(Int64,Naked):read(Int64,Naked),buf]
+	close[filedes(Int32,Naked):status(Int32,Naked)]
+	fsync[filedes(Int32,Naked):status(Int32,Naked)]
 }
 
 _Print Int32[n,buf:out]