Browse Source

HADOOP-1582. Fix hdfslib to return 0 at EOF instead of -1, per C conventions. Contributed by Chistian Kunz.

git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk@555387 13f79535-47bb-0310-9956-ffa450edef68
Doug Cutting 18 years ago
parent
commit
6768fed517
2 changed files with 9 additions and 2 deletions
  1. 3 0
      CHANGES.txt
  2. 6 2
      src/c++/libhdfs/hdfs.c

+ 3 - 0
CHANGES.txt

@@ -309,6 +309,9 @@ Trunk (unreleased changes)
  95. HADOOP-1473.  Make job ids unique across jobtracker restarts.
      (omalley via cutting)
 
+ 96. HADOOP-1582.  Fix hdfslib to return 0 instead of -1 at
+     end-of-file, per C conventions.  (Christian Kunz via cutting)
+
 
 Release 0.13.0 - 2007-06-08
 

+ 6 - 2
src/c++/libhdfs/hdfs.c

@@ -481,8 +481,10 @@ tSize hdfsRead(hdfsFS fs, hdfsFile f, void* buffer, tSize length)
         noReadBytes = jVal.i;
         if (noReadBytes > 0) {
             (*env)->GetByteArrayRegion(env, jbRarray, 0, noReadBytes, buffer);
+        }  else {
+            //This is a valid case: there aren't any bytes left to read!
+            noReadBytes = 0;
         }
-        //This is a valid case: there aren't any bytes left to read!
         errno = 0;
     }
 
@@ -536,8 +538,10 @@ tSize hdfsPread(hdfsFS fs, hdfsFile f, tOffset position,
         noReadBytes = jVal.i;
         if (noReadBytes > 0) {
             (*env)->GetByteArrayRegion(env, jbRarray, 0, noReadBytes, buffer);
+        }  else {
+            //This is a valid case: there aren't any bytes left to read!
+            noReadBytes = 0;
         }
-        //This is a valid case: there aren't any bytes left to read!
         errno = 0;
     }
     destroyLocalReference(env, jbRarray);