harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From arc...@apache.org
Subject svn commit: r370843 - /incubator/harmony/enhanced/jchevm/libjc/zip.c
Date Fri, 20 Jan 2006 15:08:07 GMT
Author: archie
Date: Fri Jan 20 07:08:05 2006
New Revision: 370843

URL: http://svn.apache.org/viewcvs?rev=370843&view=rev
Log:
Avoid using pread(2), it's not as portable as lseek(2) then read(2).

Modified:
    incubator/harmony/enhanced/jchevm/libjc/zip.c

Modified: incubator/harmony/enhanced/jchevm/libjc/zip.c
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/jchevm/libjc/zip.c?rev=370843&r1=370842&r2=370843&view=diff
==============================================================================
--- incubator/harmony/enhanced/jchevm/libjc/zip.c (original)
+++ incubator/harmony/enhanced/jchevm/libjc/zip.c Fri Jan 20 07:08:05 2006
@@ -306,10 +306,18 @@
 		return JNI_ERR;
 	}
 
+	/* Seek to start of data */
+	if (lseek(zip->fd, zent->offset, SEEK_SET) == -1) {
+		_JC_EX_STORE(env, IOException, "can't seek entry `%s'"
+		    " in ZIP file `%s': %s", zent->name, zip->path,
+		    strerror(errno));
+		return JNI_ERR;
+	}
+
 	/* Read data */
 	for (i = 0; i < zent->comp_len; i += r) {
-		if ((r = pread(zip->fd, (char *)data + i,
-		    zent->comp_len - i, zent->offset + i)) == -1) {
+		if ((r = read(zip->fd, (char *)data + i,
+		    zent->comp_len - i)) == -1) {
 			_JC_EX_STORE(env, IOException, "can't read entry `%s'"
 			    " in ZIP file `%s': %s", zent->name, zip->path,
 			    strerror(errno));
@@ -360,6 +368,14 @@
 		_JC_ASSERT(JNI_FALSE);
 	}
 
+	/* Seek to start of data */
+	if (lseek(zip->fd, zent->offset, SEEK_SET) == -1) {
+		_JC_EX_STORE(env, IOException, "can't seek entry `%s' in"
+		    " ZIP file `%s': %s", zent->name, zip->path,
+		    strerror(errno));
+		return JNI_ERR;
+	}
+
 	/* Read and inflate data */
 	for (i = 0; i < zent->comp_len; i += r) {
 		char buf[512];
@@ -370,9 +386,8 @@
 		to_read = zent->comp_len - i;
 		if (to_read > sizeof(buf))
 			to_read = sizeof(buf);
-		if ((r = pread(zip->fd, buf,
-		    to_read, zent->offset + i)) == -1) {
-			_JC_EX_STORE(env, IOException, "error reading entry"
+		if ((r = read(zip->fd, buf, to_read)) == -1) {
+			_JC_EX_STORE(env, IOException, "can't read entry"
 			    " `%s' in ZIP file `%s': %s", zent->name,
 			    zip->path, strerror(errno));
 			goto fail;



Mime
View raw message