Add error message when the file load fails
[platform/core/uifw/dali-adaptor.git] / dali / internal / adaptor-framework / generic / file-stream-impl-generic.cpp
index 7273b94..98bdb96 100644 (file)
@@ -18,7 +18,7 @@
 #include <dali/internal/adaptor-framework/common/file-stream-impl.h>
 
 // EXTERNAL INCLUDES
-#include <string>
+#include <cstring>
 #include <fstream>
 
 #include <dali/integration-api/debug.h>
@@ -106,27 +106,33 @@ std::iostream& FileStream::Impl::GetStream()
     return mBufferStream;
   }
 
-  std::ios_base::openmode openMode = std::ios::ate;
-  if( mMode & Dali::FileStream::BINARY )
+  int openMode = 0;
+
+  if( mMode & Dali::FileStream::APPEND )
   {
-    openMode |= std::ios::binary;
+    openMode |= ( std::ios::out | std::ios::app );
   }
-
-  if( mMode & Dali::FileStream::WRITE )
+  else if( mMode & Dali::FileStream::WRITE )
   {
-    openMode |= std::ios::out;
+    openMode |= ( std::ios::out | std::ios::ate );
   }
-  else
+
+  if( mMode & Dali::FileStream::READ )
   {
     openMode |= std::ios::in;
   }
 
+  if( mMode & Dali::FileStream::BINARY )
+  {
+    openMode |= std::ios::binary;
+  }
+
   if( !mFileName.empty() )
   {
-    mFileStream.open( mFileName, openMode );
+    mFileStream.open( mFileName, static_cast<std::ios_base::openmode>( openMode ) );
     if( !mFileStream.is_open() )
     {
-      DALI_LOG_WARNING( "stream open failed for: \"%s\", in mode: \"%d\".\n", mFileName, static_cast<int>( openMode ) );
+      DALI_LOG_WARNING( "stream open failed for: \"%s\", in mode: \"%d\".\n", mFileName.c_str(), openMode );
     }
     return mFileStream;
   }
@@ -136,7 +142,7 @@ std::iostream& FileStream::Impl::GetStream()
     if( !mBufferStream.rdbuf()->in_avail() )
     {
       DALI_LOG_WARNING( "File open failed for memory buffer at location: \"%p\", of size: \"%u\", in mode: \"%d\".\n",
-          static_cast<void*>( mBuffer ), static_cast<unsigned>( mDataSize ), static_cast<int>( openMode ) );
+          static_cast<void*>( mBuffer ), static_cast<unsigned>( mDataSize ), openMode );
     }
   }
 
@@ -159,7 +165,11 @@ FILE* FileStream::Impl::GetFile()
   char openMode[16] = { 0 };
   int i = 0;
 
-  if( mMode & Dali::FileStream::WRITE )
+  if( mMode & Dali::FileStream::APPEND )
+  {
+    openMode[i++] = 'a';
+  }
+  else if( mMode & Dali::FileStream::WRITE )
   {
     openMode[i++] = 'w';
   }
@@ -180,7 +190,9 @@ FILE* FileStream::Impl::GetFile()
     mFile = fopen( mFileName.c_str(), openMode );
     if( !mFile )
     {
-      DALI_LOG_WARNING( "file open failed for: \"%s\", in mode: \"%s\".\n", mFileName, openMode );
+      char buf[512];
+      DALI_LOG_ERROR( "file open failed for: \"%s\", in mode: \"%s\".\n", mFileName.c_str(), openMode );
+      DALI_LOG_ERROR( "file open failed error : %s\n", strerror_r( errno, buf, 512 )  );
     }
   }
   else if( mBuffer )
@@ -188,8 +200,10 @@ FILE* FileStream::Impl::GetFile()
     mFile = fmemopen( mBuffer, mDataSize, openMode );
     if( !mFile )
     {
-      DALI_LOG_WARNING( "File open failed for memory buffer at location: \"%p\", of size: \"%u\", in mode: \"%s\".\n",
+      char buf[512];
+      DALI_LOG_ERROR( "File open failed for memory buffer at location: \"%p\", of size: \"%u\", in mode: \"%s\".\n",
           static_cast<void*>( mBuffer ), static_cast<unsigned>( mDataSize ), openMode );
+      DALI_LOG_ERROR( "file open failed error : %s\n",  strerror_r( errno, buf, 512 )  );
     }
   }