[kaffe] CVS kaffe (robilad): Wrapped remaining file target functions

Kaffe CVS cvs-commits at kaffe.org
Thu Aug 4 18:19:26 PDT 2005


PatchSet 6782 
Date: 2005/08/05 01:14:33
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Wrapped remaining file target functions

2005-08-05  Dalibor Topic  <robilad at kaffe.org>

* include/jsyscall.h (KFTRUNCATE, KFSYNC, KREAD, KWRITE): Documented.

2005-08-05  Dalibor Topic  <robilad at kaffe.org>

* libraries/clib/target/Linux/target_native_file.h (TARGET_NATIVE_FILE_FSYNC,
TARGET_NATIVE_FILE_TRUNCATE, TARGET_NATIVE_FILE_WRITE,
TARGET_NATIVE_FILE_READ): New macros used to delegate
system calls to thread-safe wrappers for system calls.

Members: 
	ChangeLog:1.4307->1.4308 
	include/jsyscall.h:1.22->1.23 
	libraries/clib/target/Linux/target_native_file.h:1.3->1.4 
	libraries/clib/target/generic/target_generic_file.h:1.1->1.2 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.4307 kaffe/ChangeLog:1.4308
--- kaffe/ChangeLog:1.4307	Thu Aug  4 01:59:55 2005
+++ kaffe/ChangeLog	Fri Aug  5 01:14:33 2005
@@ -1,3 +1,15 @@
+2005-08-05  Dalibor Topic  <robilad at kaffe.org>
+
+	* include/jsyscall.h (KFTRUNCATE, KFSYNC, KREAD, KWRITE): Documented.
+
+2005-08-05  Dalibor Topic  <robilad at kaffe.org>
+
+	* libraries/clib/target/Linux/target_native_file.h (TARGET_NATIVE_FILE_FSYNC,
+	TARGET_NATIVE_FILE_TRUNCATE, TARGET_NATIVE_FILE_WRITE,
+	TARGET_NATIVE_FILE_READ): New macros used to delegate
+	system calls to thread-safe wrappers for system calls.
+
+	
 2005-08-04  Dalibor Topic  <robilad at kaffe.org>
 
 	* libraries/clib/target/Linux/target_native_file.h 
Index: kaffe/include/jsyscall.h
diff -u kaffe/include/jsyscall.h:1.22 kaffe/include/jsyscall.h:1.23
--- kaffe/include/jsyscall.h:1.22	Tue Aug  2 09:52:14 2005
+++ kaffe/include/jsyscall.h	Fri Aug  5 01:14:36 2005
@@ -122,8 +122,33 @@
 #define	KOPEN(filename, flags, permissions, filedescriptor)	\
   (*Kaffe_SystemCallInterface._open)(filename, flags, permissions, filedescriptor)
 
-#define	KREAD(A,B,C,D)	(*Kaffe_SystemCallInterface._read)(A,B,C,D)
-#define	KWRITE(A,B,C,D)	(*Kaffe_SystemCallInterface._write)(A,B,C,D)
+/**
+ * Read bytes from a file into a buffer in a 
+ * platform-independant, thread-safe way.
+ *
+ * @param filedescriptor filedescriptor to read from
+ * @param buffer buffer to read the bytes into
+ * @param length number of bytes to be read
+ * @param bytesRead number of bytes actually read
+ * 
+ * @return 0 on success, or errno on failure.
+ */
+#define	KREAD(filedescriptor, buffer, length, bytesRead)	\
+  (*Kaffe_SystemCallInterface._read)(filedescriptor, buffer, length, bytesRead)
+
+/**
+ * Write bytes to a file from a buffer in a 
+ * platform-independant, thread-safe way.
+ *
+ * @param filedescriptor filedescriptor to write to
+ * @param buffer buffer to write the bytes from
+ * @param length number of bytes to be written
+ * @param bytesWritten number of bytes actually written
+ * 
+ * @return 0 on success, or errno on failure.
+ */
+#define	KWRITE(filedescriptor, buffer, length, bytesWritten)	\
+  (*Kaffe_SystemCallInterface._write)(filedescriptor, buffer, length, bytesWritten)
 
 /**
  * Reposition read/write offset in a file in a 
@@ -157,10 +182,30 @@
  * 
  * @return 0 on success, or errno on failure.
  */
-#define	KFSTAT(filedescriptor, stats)	(*Kaffe_SystemCallInterface._fstat)(filedescriptor, stats)
+#define	KFSTAT(filedescriptor, stats)	\
+  (*Kaffe_SystemCallInterface._fstat)(filedescriptor, stats)
 #define	KSTAT(A,B)	(*Kaffe_SystemCallInterface._stat)(A,B)
-#define KFTRUNCATE(A,B) (*Kaffe_SystemCallInterface._ftruncate)(A,B)
-#define KFSYNC(A)       (*Kaffe_SystemCallInterface._fsync)(A)
+
+/**
+ * FTruncate a file in a platform-independant, thread-safe way.
+ *
+ * @param filedescriptor filedescriptor to truncate
+ * @param offset pffest at which the filedescriptor should be truncated
+ * 
+ * @return 0 on success, or errno on failure.
+ */
+#define KFTRUNCATE(filedescriptor,offset) \
+  (*Kaffe_SystemCallInterface._ftruncate)(filedescriptor, offset)
+
+/**
+ * Synchrnoze a file in a platform-independant, thread-safe way.
+ *
+ * @param filedescriptor filedescriptor to synchronize
+ * 
+ * @return 0 on success, or errno on failure.
+ */
+#define KFSYNC(filedescriptor) \
+  (*Kaffe_SystemCallInterface._fsync)(filedescriptor)
 
 #define	KMKDIR(A,B)	(*Kaffe_SystemCallInterface._mkdir)(A,B)
 #define	KRMDIR(A)	(*Kaffe_SystemCallInterface._rmdir)(A)
Index: kaffe/libraries/clib/target/Linux/target_native_file.h
diff -u kaffe/libraries/clib/target/Linux/target_native_file.h:1.3 kaffe/libraries/clib/target/Linux/target_native_file.h:1.4
--- kaffe/libraries/clib/target/Linux/target_native_file.h:1.3	Thu Aug  4 01:59:56 2005
+++ kaffe/libraries/clib/target/Linux/target_native_file.h	Fri Aug  5 01:14:36 2005
@@ -281,7 +281,67 @@
     } while (0)
 #endif
 
-/* TODO: WRITE, READ, TRUNCATE, FSYNC */
+/***********************************************************************\
+* Name       : TARGET_NATIVE_FILE_READ|WRITE
+* Purpose    : read/write from/to frile
+* Input      : -
+* Output     : -
+* Return     : -
+* Side-effect: unknown
+* Notes      : -
+\***********************************************************************/
+
+#ifndef TARGET_NATIVE_FILE_READ
+  #include <unistd.h>
+  #define TARGET_NATIVE_FILE_READ(filedescriptor,buffer,length,bytesRead,result) \
+    do { \
+      int kread_result = KREAD(filedescriptor,buffer,length, &bytesRead); \
+      result=(kread_result==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
+    } while (0)
+#endif
+#ifndef TARGET_NATIVE_FILE_WRITE
+  #include <unistd.h>
+  #define TARGET_NATIVE_FILE_WRITE(filedescriptor,buffer,length,bytesWritten,result) \
+    do { \
+      int kwrite_result=KWRITE(filedescriptor,buffer,length, &bytesWritten);	      \
+      result=(kwrite_result==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
+    } while (0)
+#endif
+
+/***********************************************************************\
+* Name       : TARGET_NATIVE_FILE_TRUNCATE
+* Purpose    : truncate a file
+* Input      : -
+* Output     : -
+* Return     : -
+* Side-effect: unknown
+* Notes      : -
+\***********************************************************************/
+
+#ifndef TARGET_NATIVE_FILE_TRUNCATE
+  #include <unistd.h>
+  #define TARGET_NATIVE_FILE_TRUNCATE(filedescriptor,offset,result) \
+    do { \
+      result=(KFTRUNCATE(filedescriptor,offset)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
+    } while (0)
+#endif
+
+/***********************************************************************\
+* Name       : TARGET_NATIVE_FILE_FSYNC
+* Purpose    : do filesystem sync
+* Input      : -
+* Output     : -
+* Return     : -
+* Side-effect: unknown
+* Notes      : -
+\***********************************************************************/
+
+#ifndef TARGET_NATIVE_FILE_FSYNC
+  #define TARGET_NATIVE_FILE_FSYNC(filedescriptor,result) \
+    do { \
+      result=(fsync(filedescriptor)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
+    } while(0)
+#endif
 
 /* include rest of definitions from generic file (do not move it to 
    another position!) */
Index: kaffe/libraries/clib/target/generic/target_generic_file.h
diff -u kaffe/libraries/clib/target/generic/target_generic_file.h:1.1 kaffe/libraries/clib/target/generic/target_generic_file.h:1.2
--- kaffe/libraries/clib/target/generic/target_generic_file.h:1.1	Tue Jul 19 01:16:37 2005
+++ kaffe/libraries/clib/target/generic/target_generic_file.h	Fri Aug  5 01:14:36 2005
@@ -828,7 +828,7 @@
 #ifndef TARGET_NATIVE_FILE_FSYNC
   #define TARGET_NATIVE_FILE_FSYNC(filedescriptor,result) \
     do { \
-      result=(fsync(filedescriptor)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
+      result=(KFSYNC(filedescriptor)==0)?TARGET_NATIVE_OK:TARGET_NATIVE_ERROR; \
     } while(0)
 #endif
 




More information about the kaffe mailing list