Collect strerror_r relative error log printing logs 18/319018/7
authorEunki Hong <eunkiki.hong@samsung.com>
Mon, 3 Feb 2025 07:14:00 +0000 (16:14 +0900)
committerEunki Hong <eunkiki.hong@samsung.com>
Fri, 14 Feb 2025 10:49:22 +0000 (10:49 +0000)
Let we collect all cases to file description error cases.

Until now, we use strerror_r return type value to print error logs.
But it will not works at XSI base kernel.
And also, strerror_r need a lots of parameters so the line of codes increased
wherever we want to print errno value.

So we can control both GNU and XSI case,
and easly check the error occured point.

Change-Id: Ice950acacf7cefc1e3dc3c1427342b91cfa66b5b
Signed-off-by: Eunki Hong <eunkiki.hong@samsung.com>
dali/internal/adaptor-framework/generic/file-loader-impl-generic.cpp
dali/internal/adaptor-framework/generic/file-stream-impl-generic.cpp
dali/internal/legacy/common/tizen-platform-abstraction.cpp
dali/internal/network/common/socket-impl.cpp
dali/internal/system/common/system-error-print.h [new file with mode: 0644]
dali/internal/system/common/trigger-event.cpp
dali/internal/system/file.list
dali/internal/system/generic/system-error-print-generic.cpp [new file with mode: 0644]
dali/internal/system/windows/system-error-print-win.cpp [new file with mode: 0644]

index 14a4657d7e60cb29891c1deaf63ece3f16db872a..5ddfe01a9f1df73943348c82a81b5b931dac332b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2024 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2025 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,6 +23,9 @@
 
 #include <dali/integration-api/debug.h>
 
+// INTERNAL INCLUDES
+#include <dali/internal/system/common/system-error-print.h>
+
 namespace Dali
 {
 namespace Internal
@@ -69,6 +72,7 @@ int ReadFile(const std::string& filename, std::streampos& fileSize, Dali::Vector
     if(file.seekg(0, std::ios::beg).good() == false)
     {
       DALI_LOG_ERROR("Failed to seek the beginning of the file: \"%s\"\n", filename.c_str());
+      DALI_PRINT_SYSTEM_ERROR_LOG();
       return errorCode;
     }
 
@@ -77,6 +81,7 @@ int ReadFile(const std::string& filename, std::streampos& fileSize, Dali::Vector
     if(file.read(reinterpret_cast<char*>(memblock.Begin()), fileSize).good() == false)
     {
       DALI_LOG_ERROR("Failed to read the file: \"%s\"\n", filename.c_str());
+      DALI_PRINT_SYSTEM_ERROR_LOG();
       return errorCode;
     }
     file.close();
@@ -85,8 +90,8 @@ int ReadFile(const std::string& filename, std::streampos& fileSize, Dali::Vector
   }
   else
   {
-    char buf[512];
-    DALI_LOG_ERROR("file open failed for: \"%s\", error : %s\n", filename.c_str(), strerror_r(errno, buf, 512));
+    DALI_LOG_ERROR("file open failed for: \"%s\"\n", filename.c_str());
+    DALI_PRINT_SYSTEM_ERROR_LOG();
   }
 
   return errorCode;
@@ -102,6 +107,11 @@ std::streampos GetFileSize(const std::string& filename)
     size = file.tellg();
     file.close();
   }
+  else
+  {
+    DALI_LOG_ERROR("file open failed for: \"%s\"\n", filename.c_str());
+    DALI_PRINT_SYSTEM_ERROR_LOG();
+  }
 
   return size;
 }
index 585d79f257d00f28dbca5a44a92dc7659bf194f6..e34b7f06f9080afeacbc3a8a2229b8491308e938 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2025 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,6 +23,9 @@
 
 #include <dali/integration-api/debug.h>
 
+// INTERNAL INCLUDES
+#include <dali/internal/system/common/system-error-print.h>
+
 namespace Dali
 {
 FileStream::Impl::Impl(const std::string& filename, uint8_t mode)
@@ -76,6 +79,7 @@ FileStream::Impl::~Impl()
     if(closeFailed)
     {
       DALI_LOG_WARNING("File close failed for FILE: \"%p\".\n", static_cast<void*>(mFile));
+      DALI_PRINT_SYSTEM_ERROR_LOG();
     }
 
     mFile = nullptr;
@@ -132,6 +136,7 @@ std::iostream& FileStream::Impl::GetStream()
     if(!mFileStream.is_open())
     {
       DALI_LOG_WARNING("stream open failed for: \"%s\", in mode: \"%d\".\n", mFileName.c_str(), openMode);
+      DALI_PRINT_SYSTEM_ERROR_LOG();
     }
     return mFileStream;
   }
@@ -144,6 +149,7 @@ std::iostream& FileStream::Impl::GetStream()
                        static_cast<void*>(mBuffer),
                        static_cast<unsigned>(mDataSize),
                        openMode);
+      DALI_PRINT_SYSTEM_ERROR_LOG();
     }
   }
 
@@ -191,9 +197,8 @@ FILE* FileStream::Impl::GetFile()
     mFile = fopen(mFileName.c_str(), openMode);
     if(!mFile)
     {
-      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));
+      DALI_PRINT_SYSTEM_ERROR_LOG();
     }
   }
   else if(mBuffer)
@@ -201,12 +206,11 @@ FILE* FileStream::Impl::GetFile()
     mFile = fmemopen(mBuffer, mDataSize, openMode);
     if(!mFile)
     {
-      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));
+      DALI_PRINT_SYSTEM_ERROR_LOG();
     }
   }
 
index 2fed2c23a28b6f1c398c070939e9a352ca8834df..9f933cbfbb43d7194259acf3cd50460677665296 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2024 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2025 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -33,6 +33,7 @@
 #include <dali/internal/imaging/common/image-loader.h>
 #include <dali/internal/imaging/common/pixel-buffer-impl.h>
 #include <dali/internal/system/common/file-reader.h>
+#include <dali/internal/system/common/system-error-print.h>
 
 namespace Dali
 {
@@ -304,7 +305,7 @@ bool SaveFile(const std::string& filename, const unsigned char* buffer, unsigned
     }
     else
     {
-      DALI_LOG_ERROR("std::ostream.write failed!\n");
+      DALI_LOG_ERROR("std::ostream.write failed! [numBytes:%d]\n", numBytes);
     }
   }
   else
@@ -314,13 +315,8 @@ bool SaveFile(const std::string& filename, const unsigned char* buffer, unsigned
 
   if(!result)
   {
-    const int errorMessageMaxLength               = 128;
-    char      errorMessage[errorMessageMaxLength] = {}; // Initailze as null.
-
-    // Return type of stderror_r is different between system type. We should not use return value.
-    [[maybe_unused]] auto ret = strerror_r(errno, errorMessage, errorMessageMaxLength - 1);
-
-    DALI_LOG_ERROR("Can't write to %s. buffer pointer : %p, length : %u, error message : [%s]\n", filename.c_str(), buffer, numBytes, errorMessage);
+    DALI_LOG_ERROR("Can't write to %s. buffer pointer : %p, length : %u\n", filename.c_str(), buffer, numBytes);
+    DALI_PRINT_SYSTEM_ERROR_LOG();
   }
 
   return result;
index 5929e1323245ee196f27587a9ed34b6d9466c25e..5c08e3b7828e2739a3a23b03b2ae8d2ef965c1e5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2024 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2025 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -27,6 +27,9 @@
 #include <sys/types.h>
 #include <unistd.h>
 
+// INTERNAL INCLUDES
+#include <dali/internal/system/common/system-error-print.h>
+
 // Sockets enums like INADDR_ANY use C-Casts
 #pragma GCC diagnostic push
 #pragma GCC diagnostic ignored "-Wold-style-cast"
@@ -64,6 +67,7 @@ Socket::Socket(Protocol protocol, int fileDescriptor)
     if(mSocketFileDescriptor == -1)
     {
       DALI_LOG_ERROR("Unable to create socket\n");
+      DALI_PRINT_SYSTEM_ERROR_LOG();
     }
   }
   else
@@ -102,6 +106,7 @@ bool Socket::CloseSocket()
   if(ret == -1)
   {
     DALI_LOG_ERROR("Socket close failed\n");
+    DALI_PRINT_SYSTEM_ERROR_LOG();
     return false;
   }
   return true;
@@ -127,8 +132,8 @@ bool Socket::Bind(uint16_t port)
 
   if(ret == -1)
   {
-    char buf[512];
-    DALI_LOG_ERROR("bind failed for port %d %s \n", port, strerror_r(errno, buf, 512));
+    DALI_LOG_ERROR("Socket bind failed\n");
+    DALI_PRINT_SYSTEM_ERROR_LOG();
     return false;
   }
 
@@ -149,6 +154,7 @@ bool Socket::Listen(int blacklog)
   if(ret == -1)
   {
     DALI_LOG_ERROR("Listen failed\n");
+    DALI_PRINT_SYSTEM_ERROR_LOG();
     return false;
   }
 
@@ -173,6 +179,7 @@ SocketInterface* Socket::Accept() const
   if(clientFileDescriptor == -1)
   {
     DALI_LOG_ERROR("Accept failed\n");
+    DALI_PRINT_SYSTEM_ERROR_LOG();
     return NULL;
   }
 
@@ -192,6 +199,7 @@ bool Socket::CreateQuitPipe()
     if(ret != 0)
     {
       DALI_LOG_ERROR("Pipe creation failed\n");
+      DALI_PRINT_SYSTEM_ERROR_LOG();
       return false;
     }
     mQuitPipeCreated = true;
@@ -233,6 +241,7 @@ SocketInterface::SelectReturn Socket::Select()
     if(ret == -1)
     {
       DALI_LOG_ERROR("select failed\n");
+      DALI_PRINT_SYSTEM_ERROR_LOG();
       return ERROR;
     }
     else if(FD_ISSET(mQuitPipe[0], &readFileDescriptors))
@@ -259,6 +268,7 @@ void Socket::ExitSelect()
     if(ret < 1)
     {
       DALI_LOG_ERROR("ExitSelect failed!\n");
+      DALI_PRINT_SYSTEM_ERROR_LOG();
     }
     return;
   }
@@ -277,8 +287,7 @@ bool Socket::ReuseAddress(bool reUse)
   int ret = setsockopt(mSocketFileDescriptor, SOL_SOCKET, SO_REUSEADDR, &reUseInteger, sizeof(reUseInteger));
   if(ret == -1)
   {
-    char buf[512];
-    DALI_LOG_ERROR("SO_REUSEADDR option failed %s \n", strerror_r(errno, buf, 512));
+    DALI_PRINT_SYSTEM_ERROR_LOG();
     return false;
   }
   return true;
@@ -301,6 +310,7 @@ bool Socket::SetBufferSize(SocketInterface::BufferType type, unsigned int size)
   if(ret == -1)
   {
     DALI_LOG_ERROR("SO_RCVBUF / SO_SNDBUF  option failed \n");
+    DALI_PRINT_SYSTEM_ERROR_LOG();
     return false;
   }
   return true;
@@ -316,7 +326,15 @@ bool Socket::Read(void* buffer, unsigned int bufferSizeInBytes, unsigned int& by
     return false;
   }
 
-  bytesRead = static_cast<unsigned int>(read(mSocketFileDescriptor, buffer, bufferSizeInBytes));
+  int ret = read(mSocketFileDescriptor, buffer, bufferSizeInBytes);
+  if(ret == -1)
+  {
+    DALI_LOG_ERROR("Socket read error \n");
+    DALI_PRINT_SYSTEM_ERROR_LOG();
+    return false;
+  }
+
+  bytesRead = static_cast<unsigned int>(ret);
 
   return true;
 }
@@ -355,6 +373,7 @@ bool Socket::Write(const void* buffer, unsigned int bufferSizeInBytes)
     if(ret < 1)
     {
       DALI_LOG_ERROR("Socket writer error \n");
+      DALI_PRINT_SYSTEM_ERROR_LOG();
       return false;
     }
     else
diff --git a/dali/internal/system/common/system-error-print.h b/dali/internal/system/common/system-error-print.h
new file mode 100644 (file)
index 0000000..1e08c6c
--- /dev/null
@@ -0,0 +1,41 @@
+#ifndef DALI_TIZEN_SYSTEM_ERROR_PRINT_H
+#define DALI_TIZEN_SYSTEM_ERROR_PRINT_H
+
+/*
+ * Copyright (c) 2025 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#include <dali/integration-api/debug.h>
+
+namespace Dali
+{
+namespace TizenPlatform
+{
+/**
+ * @brief Print errno and the error message to Dali::TizenPlatform::LogMessage as error level.
+ * Please use this function with DALI_PRINT_SYSTEM_ERROR_LOG macro
+ */
+void PrintSystemError(const char* fileName, const char* functionName, const int lineNumber);
+
+} // namespace TizenPlatform
+
+#ifndef DALI_PRINT_SYSTEM_ERROR_LOG
+#define DALI_PRINT_SYSTEM_ERROR_LOG() Dali::TizenPlatform::PrintSystemError(DALI_LOG_FORMAT_PREFIX_ARGS);
+#endif
+
+} // namespace Dali
+
+#endif // DALI_TIZEN_SYSTEM_ERROR_PRINT_H
index f62119b0a8af94b94a997dbe354cc58a1d8b719d..38412cce1f55907a2e1398aa0ce16b73a08dab52 100644 (file)
@@ -26,6 +26,7 @@
 
 // INTERNAL INCLUDES
 #include <dali/internal/system/common/file-descriptor-monitor.h>
+#include <dali/internal/system/common/system-error-print.h>
 #include <dali/internal/system/common/system-factory.h>
 
 namespace Dali
@@ -51,6 +52,7 @@ TriggerEvent::TriggerEvent(CallbackBase* callback, TriggerEventInterface::Option
   else
   {
     DALI_LOG_ERROR("Unable to create TriggerEvent File descriptor\n");
+    DALI_PRINT_SYSTEM_ERROR_LOG();
   }
 }
 
@@ -81,6 +83,7 @@ void TriggerEvent::Trigger()
     if(size != sizeof(uint64_t))
     {
       DALI_LOG_ERROR("Unable to write to UpdateEvent File descriptor\n");
+      DALI_PRINT_SYSTEM_ERROR_LOG();
     }
   }
   else
@@ -105,6 +108,7 @@ void TriggerEvent::Triggered(FileDescriptorMonitor::EventType eventBitMask, int
   if(size != sizeof(uint64_t))
   {
     DALI_LOG_WARNING("Unable to read to UpdateEvent File descriptor\n");
+    DALI_PRINT_SYSTEM_ERROR_LOG();
   }
 
   // Save value to prevent duplicate deletion
index 00b61e99d0dd41964aa96adb48cbe5007402d53b..e0bb026565de44020aa8b74408fd385cb7051402 100644 (file)
@@ -30,10 +30,11 @@ SET( adaptor_system_common_src_files
 # module: system, backend: linux
 SET( adaptor_system_linux_src_files
     ${adaptor_system_dir}/common/shared-file.cpp
+    ${adaptor_system_dir}/common/time-service.cpp
     ${adaptor_system_dir}/common/trigger-event.cpp
     ${adaptor_system_dir}/common/trigger-event-factory.cpp
-    ${adaptor_system_dir}/common/time-service.cpp
     ${adaptor_system_dir}/generic/shared-file-operations-generic.cpp
+    ${adaptor_system_dir}/generic/system-error-print-generic.cpp
     ${adaptor_system_dir}/glib/callback-manager-glib.cpp
     ${adaptor_system_dir}/glib/file-descriptor-monitor-glib.cpp
     ${adaptor_system_dir}/glib/timer-impl-glib.cpp
@@ -46,12 +47,14 @@ SET( adaptor_system_linux_src_files
 # module: system, backend: tizen-wayland
 SET( adaptor_system_tizen_wayland_src_files
     ${adaptor_system_dir}/common/shared-file.cpp
+    ${adaptor_system_dir}/common/time-service.cpp
     ${adaptor_system_dir}/common/trigger-event.cpp
     ${adaptor_system_dir}/common/trigger-event-factory.cpp
+    ${adaptor_system_dir}/generic/shared-file-operations-generic.cpp
+    ${adaptor_system_dir}/generic/system-error-print-generic.cpp
     ${adaptor_system_dir}/tizen-wayland/logging-tizen.cpp
     ${adaptor_system_dir}/tizen-wayland/system-settings-tizen.cpp
     ${adaptor_system_dir}/tizen-wayland/widget-application-impl-tizen.cpp
-    ${adaptor_system_dir}/common/time-service.cpp
     ${adaptor_system_dir}/tizen-wayland/widget-controller-tizen.cpp
 )
 
@@ -63,12 +66,14 @@ SET( adaptor_system_tizen_wearable_src_files
 # module: system, backend: ubuntu-x11
 SET( adaptor_system_ubuntu_x11_src_files
     ${adaptor_system_dir}/common/shared-file.cpp
+    ${adaptor_system_dir}/common/time-service.cpp
     ${adaptor_system_dir}/common/trigger-event.cpp
     ${adaptor_system_dir}/common/trigger-event-factory.cpp
+    ${adaptor_system_dir}/generic/shared-file-operations-generic.cpp
+    ${adaptor_system_dir}/generic/system-error-print-generic.cpp
     ${adaptor_system_dir}/ubuntu-x11/logging-x.cpp
     ${adaptor_system_dir}/ubuntu-x11/system-settings-x.cpp
     ${adaptor_system_dir}/ubuntu-x11/widget-application-impl-x.cpp
-    ${adaptor_system_dir}/common/time-service.cpp
     ${adaptor_system_dir}/ubuntu-x11/widget-controller-x.cpp
 )
 
@@ -80,6 +85,7 @@ SET( adaptor_system_libuv_src_files
     ${adaptor_system_dir}/common/trigger-event.cpp
     ${adaptor_system_dir}/common/trigger-event-factory.cpp
     ${adaptor_system_dir}/generic/shared-file-operations-generic.cpp
+    ${adaptor_system_dir}/generic/system-error-print-generic.cpp
     ${adaptor_system_dir}/libuv/callback-manager-libuv.cpp
     ${adaptor_system_dir}/libuv/file-descriptor-monitor-libuv.cpp
     ${adaptor_system_dir}/libuv/system-factory-libuv.cpp
@@ -97,6 +103,7 @@ SET( adaptor_system_glib_src_files
     ${adaptor_system_dir}/common/trigger-event.cpp
     ${adaptor_system_dir}/common/trigger-event-factory.cpp
     ${adaptor_system_dir}/generic/shared-file-operations-generic.cpp
+    ${adaptor_system_dir}/generic/system-error-print-generic.cpp
     ${adaptor_system_dir}/glib/callback-manager-glib.cpp
     ${adaptor_system_dir}/glib/file-descriptor-monitor-glib.cpp
     ${adaptor_system_dir}/glib/system-factory-glib.cpp
@@ -110,6 +117,7 @@ SET( adaptor_system_glib_src_files
 # module: system, backend: android
 SET( adaptor_system_android_src_files
     ${adaptor_system_dir}/common/shared-file.cpp
+    ${adaptor_system_dir}/common/time-service.cpp
     ${adaptor_system_dir}/common/trigger-event.cpp
     ${adaptor_system_dir}/common/trigger-event-factory.cpp
     ${adaptor_system_dir}/android/callback-manager-android.cpp
@@ -119,14 +127,16 @@ SET( adaptor_system_android_src_files
     ${adaptor_system_dir}/android/system-factory-android.cpp
     ${adaptor_system_dir}/android/system-settings-android.cpp
     ${adaptor_system_dir}/android/timer-impl-android.cpp
-    ${adaptor_system_dir}/common/time-service.cpp
     ${adaptor_system_dir}/android/widget-application-impl-android.cpp
+    ${adaptor_system_dir}/generic/system-error-print-generic.cpp
 )
 
 # module: system, backend: windows
 SET( adaptor_system_windows_src_files
+    ${adaptor_system_dir}/common/time-service.cpp
     ${adaptor_system_dir}/windows/callback-manager-win.cpp
     ${adaptor_system_dir}/windows/file-descriptor-monitor-windows.cpp
+    ${adaptor_system_dir}/windows/system-error-print-win.cpp
     ${adaptor_system_dir}/windows/system-factory-win.cpp
     ${adaptor_system_dir}/windows/system-settings-win.cpp
     ${adaptor_system_dir}/windows/timer-impl-win.cpp
@@ -134,22 +144,22 @@ SET( adaptor_system_windows_src_files
     ${adaptor_system_dir}/windows/trigger-event-factory.cpp
     ${adaptor_system_dir}/windows/logging-win.cpp
     ${adaptor_system_dir}/windows/widget-application-impl-win.cpp
-    ${adaptor_system_dir}/common/time-service.cpp
     ${adaptor_system_dir}/windows/widget-controller-win.cpp
 )
 
 # module: system, backend: macOS
 SET( adaptor_system_macos_src_files
-    ${adaptor_system_dir}/ubuntu-x11/logging-x.cpp
+    ${adaptor_system_dir}/common/shared-file.cpp
+    ${adaptor_system_dir}/common/time-service.cpp
+    ${adaptor_system_dir}/common/trigger-event-factory.cpp
+    ${adaptor_system_dir}/generic/shared-file-operations-generic.cpp
+    ${adaptor_system_dir}/generic/system-error-print-generic.cpp
     ${adaptor_system_dir}/macos/file-descriptor-monitor-macos.cpp
     ${adaptor_system_dir}/macos/system-factory-mac.cpp
     ${adaptor_system_dir}/macos/system-settings-mac.cpp
     ${adaptor_system_dir}/macos/timer-impl-mac.cpp
-    ${adaptor_system_dir}/common/shared-file.cpp
-    ${adaptor_system_dir}/common/trigger-event-factory.cpp
-    ${adaptor_system_dir}/generic/shared-file-operations-generic.cpp
-    ${adaptor_system_dir}/common/time-service.cpp
     ${adaptor_system_dir}/macos/trigger-event.mm
     ${adaptor_system_dir}/macos/callback-manager-mac.mm
     ${adaptor_system_dir}/macos/widget-application-impl-mac.cpp
+    ${adaptor_system_dir}/ubuntu-x11/logging-x.cpp
 )
diff --git a/dali/internal/system/generic/system-error-print-generic.cpp b/dali/internal/system/generic/system-error-print-generic.cpp
new file mode 100644 (file)
index 0000000..1081382
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2025 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// FUNCTION HEADER
+#include <dali/internal/system/common/system-error-print.h>
+
+// EXTERNAL INCLUDES
+#include <cerrno>  ///< for errno
+#include <cstring> ///< for strerror_r
+#include <sstream> ///< for std::ostringstream
+#include <string>
+
+// INTERNAL INCLUDES
+#include <dali/internal/system/common/logging.h>
+
+namespace Dali
+{
+namespace TizenPlatform
+{
+namespace
+{
+// Reference : https://github.com/intel/intel-graphics-compiler/issues/213
+// Seperate function logic for GNU-specific and XSI-compliant by the type of return value.
+
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wunused-function"
+// For GNU case
+std::string ConvertResultToString(const char* errorName, const char* /* not used */)
+{
+  return std::string(DALI_LIKELY(errorName) ? errorName : "null");
+}
+
+// For XSI case
+std::string ConvertResultToString(int /* not used */, const char* errorName)
+{
+  return std::string(DALI_LIKELY(errorName) ? errorName : "null");
+}
+#pragma GCC diagnostic pop
+} // namespace
+
+void PrintSystemError(const char* fileName, const char* functionName, const int lineNumber)
+{
+  std::ostringstream oss;
+
+  const static int         errorMessageMaxLength               = 128;
+  thread_local static char errorMessage[errorMessageMaxLength] = {}; // Initialze as null.
+
+  int copiedErrorNumber = errno;
+
+  auto reternValue = strerror_r(copiedErrorNumber, errorMessage, errorMessageMaxLength - 1);
+
+  if(DALI_LIKELY(fileName))
+  {
+    oss << fileName << ": ";
+  }
+  if(DALI_LIKELY(functionName))
+  {
+    oss << functionName << "";
+  }
+  oss << "(" << lineNumber << ") > ";
+
+  oss << "errno [" << copiedErrorNumber << "] ";
+  oss << ConvertResultToString(reternValue, static_cast<const char*>(&errorMessage[0])) << "\n";
+
+  std::string message = oss.str();
+  LogMessage(Dali::Integration::Log::DebugPriority::ERROR, message);
+}
+
+} // namespace TizenPlatform
+
+} // namespace Dali
diff --git a/dali/internal/system/windows/system-error-print-win.cpp b/dali/internal/system/windows/system-error-print-win.cpp
new file mode 100644 (file)
index 0000000..d6eef29
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (c) 2025 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// WINDOWS INCLUDES
+#include <Windows.h> // For GetLastError and FormatMessage
+
+// Need to undef the following constants as they are defined in one of the headers in Windows.h but used in DALi (via debug.h)
+#undef TRANSPARENT // Used in constants.h
+#undef CopyMemory  // Used in dali-vector.h
+
+// FUNCTION HEADER
+#include <dali/internal/system/common/system-error-print.h>
+
+// EXTERNAL INCLUDES
+#include <sstream> ///< for std::ostringstream
+#include <string>
+
+// INTERNAL INCLUDES
+#include <dali/internal/system/common/logging.h>
+
+namespace Dali
+{
+namespace TizenPlatform
+{
+void PrintSystemError(const char* fileName, const char* functionName, const int lineNumber)
+{
+  std::ostringstream oss;
+
+  // Windows error messages are very long! (error code 10401 message length is 2174)
+  // Use FormatMessage limitation length here : 65535
+  const static DWORD       errorMessageMaxLength               = 0xffff;
+  thread_local static char errorMessage[errorMessageMaxLength] = {}; // Initialze as null.
+
+  DWORD copiedErrorNumber = GetLastError();
+
+  // FORMAT_MESSAGE_IGNORE_INSERTS Should be used when we try to get FORMAT_MESSAGE_FROM_SYSTEM
+  DWORD errorMessageLength = FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM, NULL, copiedErrorNumber, 0, (LPTSTR) & (&errorMessage[0]), errorMessageMaxLength - 1, NULL);
+
+  if(DALI_LIKELY(fileName))
+  {
+    oss << fileName << ": ";
+  }
+  if(DALI_LIKELY(functionName))
+  {
+    oss << functionName << "";
+  }
+  oss << "(" << lineNumber << ") > ";
+
+  oss << "errno [" << copiedErrorNumber << "] ";
+  oss << std::string(&errorMessage[0], (size_t)errorMessageLength) << "\n";
+
+  std::string message = oss.str();
+  LogMessage(Dali::Integration::Log::DebugPriority::ERROR, message);
+}
+
+} // namespace TizenPlatform
+
+} // namespace Dali