Revision: 392
http://assorted.svn.sourceforge.net/assorted/?rev=392&view=rev
Author: yangzhang
Date: 2008-02-12 10:01:17 -0800 (Tue, 12 Feb 2008)
Log Message:
-----------
fixed bug: omitting end of file
Modified Paths:
--------------
cpp-commons/trunk/src/commons/files.h
Modified: cpp-commons/trunk/src/commons/files.h
===================================================================
--- cpp-commons/trunk/src/commons/files.h 2008-02-12 17:08:58 UTC (rev 391)
+++ cpp-commons/trunk/src/commons/files.h 2008-02-12 18:01:17 UTC (rev 392)
@@ -69,17 +69,19 @@
char *buf = new char[len + 1];
check(buf);
+ ssize_t status = pread(fd, buf, len, 0);
+ size_t nread = static_cast<size_t>(status);
+ check(status != -1 && nread == len);
+
// TODO Use threads to pull data to the correct initial locations?
- // XXX alignment bug: not necessarily reading the full file (omitting final
- // null terminators can cause issues)
- size_t chunk_len = len / ncpus;
- for (unsigned int i = 0; i < ncpus; i++) {
- int off = i *chunk_len;
- ssize_t status = pread(fd, buf + off, chunk_len, off);
- // We read the whole chunk or hit the end.
- size_t nread = static_cast<size_t>(status);
- check(status != -1 && (nread == chunk_len || off + nread == len));
- }
+ // size_t chunk_len = len / ncpus;
+ // for (unsigned int i = 0; i < ncpus; i++) {
+ // int off = i *chunk_len;
+ // ssize_t status = pread(fd, buf + off, chunk_len, off);
+ // // We read the whole chunk or hit the end.
+ // size_t nread = static_cast<size_t>(status);
+ // check(status != -1 && (nread == chunk_len || off + nread == len));
+ // }
check(close(fd) == 0);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|