From 00e37224edb22228fc6bf867872a3f4c8ee2ff57 Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Sat, 26 Sep 2015 13:41:44 +0200 Subject: [PATCH] gsdx: check the return value of mkdir function Reported by coverity --- plugins/GSdx/GSCapture.cpp | 6 ++---- plugins/GSdx/GSState.cpp | 8 ++------ plugins/GSdx/GSUtil.cpp | 8 ++++++++ plugins/GSdx/GSUtil.h | 3 +++ plugins/GSdx/stdafx.h | 4 ++++ 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/plugins/GSdx/GSCapture.cpp b/plugins/GSdx/GSCapture.cpp index 54f1791dc6..0c451af6c4 100644 --- a/plugins/GSdx/GSCapture.cpp +++ b/plugins/GSdx/GSCapture.cpp @@ -22,9 +22,7 @@ #include "stdafx.h" #include "GSCapture.h" #include "GSPng.h" -#ifdef __linux__ -#include // mkdir -#endif +#include "GSUtil.h" #ifdef _WINDOWS @@ -482,7 +480,7 @@ bool GSCapture::BeginCapture(float fps, GSVector2i recomendedResolution, float a #elif __linux__ // Note I think it doesn't support multiple depth creation - mkdir(m_out_dir.c_str(), 0777); + GSmkdir(m_out_dir.c_str()); // Really cheap recording m_frame = 0; diff --git a/plugins/GSdx/GSState.cpp b/plugins/GSdx/GSState.cpp index f515e00e15..b6b66fd038 100644 --- a/plugins/GSdx/GSState.cpp +++ b/plugins/GSdx/GSState.cpp @@ -23,10 +23,6 @@ #include "GSState.h" #include "GSdx.h" -#ifdef __linux__ -#include // mkdir -#endif - //#define Offset_ST // Fixes Persona3 mini map alignment which is off even in software rendering static int s_crc_hack_level = 3; @@ -59,8 +55,8 @@ GSState::GSState() s_savel = theApp.GetConfig("savel", 5000); #ifdef __linux__ if (s_dump) { - mkdir("/tmp/GS_HW_dump", 0777); - mkdir("/tmp/GS_SW_dump", 0777); + GSmkdir("/tmp/GS_HW_dump"); + GSmkdir("/tmp/GS_SW_dump"); } #endif diff --git a/plugins/GSdx/GSUtil.cpp b/plugins/GSdx/GSUtil.cpp index 02950970b5..c43138a804 100644 --- a/plugins/GSdx/GSUtil.cpp +++ b/plugins/GSdx/GSUtil.cpp @@ -415,4 +415,12 @@ D3D_FEATURE_LEVEL GSUtil::CheckDirect3D11Level(IDXGIAdapter *adapter, D3D_DRIVER return SUCCEEDED(hr) ? level : (D3D_FEATURE_LEVEL)0; } +#else + +void GSmkdir(const char* dir) +{ + if (mkdir(dir, 0777)) + fprintf(stderr, "Failed to create directory: %s\n", dir); +} + #endif diff --git a/plugins/GSdx/GSUtil.h b/plugins/GSdx/GSUtil.h index 5a722cd251..61182addaf 100644 --- a/plugins/GSdx/GSUtil.h +++ b/plugins/GSdx/GSUtil.h @@ -65,3 +65,6 @@ public: #endif }; +#ifdef __linux__ +void GSmkdir(const char* dir); +#endif diff --git a/plugins/GSdx/stdafx.h b/plugins/GSdx/stdafx.h index ed38710a96..d1b16d3e5e 100644 --- a/plugins/GSdx/stdafx.h +++ b/plugins/GSdx/stdafx.h @@ -116,6 +116,10 @@ using namespace std; using namespace stdext; #endif +#ifdef __linux__ +#include // mkdir +#endif + #ifdef _WINDOWS // Note use GL/glcorearb.h on the future