Ver código fonte

BUG: #81880 Return a string buffer, and notify user on error condition

Signed-off-by: Gavin Halliday <gavin.halliday@lexisnexis.com>
Gavin Halliday 14 anos atrás
pai
commit
c4e30764dd
3 arquivos alterados com 15 adições e 4 exclusões
  1. 3 3
      system/jlib/jfile.cpp
  2. 1 1
      system/jlib/jfile.hpp
  3. 11 0
      tools/testsocket/testsocket.cpp

+ 3 - 3
system/jlib/jfile.cpp

@@ -6333,14 +6333,14 @@ extern jlib_decl void writeSentinelFile(IFile * sentinelFile)
     sentinel->write(0, 5, "rerun");
 }
 
-jlib_decl void getCurrentDirectory(StringBuffer & target, bool blankIfFails)
+jlib_decl StringBuffer & getCurrentDirectory(StringBuffer & target, bool blankIfFails)
 {
     char temp[_MAX_PATH+1];
     if (!getcwd(temp,sizeof(temp)))
     {
         if (blankIfFails)
-            return;
+            return target;
         throw MakeStringException(JLIBERR_InternalError, "getcwd failed (%d)", errno);
     }
-    target.append(temp);
+    return target.append(temp);
 }

+ 1 - 1
system/jlib/jfile.hpp

@@ -600,6 +600,6 @@ extern jlib_decl IFileIOCache* createFileIOCache(unsigned max);
 extern jlib_decl void setIORetryCount(unsigned _ioRetryCount); // default 0 == off, retries if read op. fails, linux only
 extern jlib_decl IFile * createSentinelTarget(const char * argv0, const char * component);
 extern jlib_decl void writeSentinelFile(IFile * file);
-extern jlib_decl void getCurrentDirectory(StringBuffer & target, bool blankIfFails);
+extern jlib_decl StringBuffer & getCurrentDirectory(StringBuffer & target, bool blankIfFails);
 
 #endif

+ 11 - 0
tools/testsocket/testsocket.cpp

@@ -103,8 +103,13 @@ void sendFile(const char * filename, ISocket * socket)
         size_t numRead = fread(buff, 1, size, in);
         fclose(in);
         if (numRead != size)
+		{
+            printf("read from file %s failed (%u/%u)\n", filename, (unsigned)numRead, size);
             size = 0;
+		}
     }
+	else
+		printf("read from file %s failed\n", filename);
 
     unsigned dllLen = size;
     _WINREV(dllLen);
@@ -136,8 +141,14 @@ void sendFileChunk(const char * filename, offset_t offset, ISocket * socket)
         size_t numRead = fread(buff, 1, size, in);
         fclose(in);
         if (numRead != size)
+		{
+            printf("read from file %s failed (%u/%u)\n", filename, (unsigned)numRead, size);
             size = 0;
+		}
     }
+	else
+		printf("read from file %s failed\n", filename);
+
 
     if (size > 0)
     {