Revision: 664
http://assorted.svn.sourceforge.net/assorted/?rev=664&view=rev
Author: yangzhang
Date: 2008-04-19 20:27:10 -0700 (Sat, 19 Apr 2008)
Log Message:
-----------
added pwrite test
Added Paths:
-----------
sandbox/trunk/src/c/pwrite.c
Added: sandbox/trunk/src/c/pwrite.c
===================================================================
--- sandbox/trunk/src/c/pwrite.c (rev 0)
+++ sandbox/trunk/src/c/pwrite.c 2008-04-20 03:27:10 UTC (rev 664)
@@ -0,0 +1,30 @@
+// What does pwrite() do when offset is beyond EOF?
+// It simply appends to the EOF.
+
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdio.h>
+
+int
+main()
+{
+ int fd = creat("/tmp/touchme", O_WRONLY);
+ if (fd < 0) {
+ perror("creat");
+ return -1;
+ }
+ char buf[] = "hello, world!";
+ // Notice the offset!
+ size_t count = sizeof buf, offset = 10;
+ if (pwrite(fd, buf, count, offset) < 0) {
+ perror("pwrite");
+ return -1;
+ }
+ if (close(fd) != 0) {
+ perror("close");
+ return -1;
+ }
+ return 0;
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|