]> granicus.if.org Git - graphviz/commitdiff
glcomp plugin file_exists: simplify readability test
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 19 Jul 2022 02:46:29 +0000 (19:46 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Tue, 26 Jul 2022 02:01:27 +0000 (19:01 -0700)
We do not need to open a file to test if it is readable.

lib/glcomp/CMakeLists.txt
lib/glcomp/glcomp.vcxproj
lib/glcomp/glpangofont.c

index 1ca6396749cf511119a36f4f21b1834640d9099f..536fd05ca1f47100eda932b19fbf959348b6da02 100644 (file)
@@ -48,6 +48,10 @@ if(with_smyrna)
     ${XRENDER_INCLUDE_DIRS}
   )
 
+  if(WIN32 AND NOT MINGW)
+    target_include_directories(glcomp PRIVATE ../../windows/include/unistd)
+  endif()
+
   target_link_libraries(glcomp PRIVATE
     ${Freetype_LIBRARIES}
     ${GLUT_LIBRARIES}
index ec6e28e81e2e07c3bec0e438ce9d4928c1fde1cc..c654f04e9490ac901cac120667017e6071d60418 100644 (file)
@@ -51,7 +51,7 @@
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
     <ClCompile>
       <Optimization>Disabled</Optimization>
-      <AdditionalIncludeDirectories>$(SolutionDir)windows\dependencies\libraries\x86\include;$(SolutionDir)windows\dependencies\libraries\x86\include\cairo;$(SolutionDir)lib;$(SolutionDir)lib\common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>$(SolutionDir)windows\dependencies\libraries\x86\include;$(SolutionDir)windows\dependencies\libraries\x86\include\cairo;$(SolutionDir)windows\include\unistd;$(SolutionDir)lib;$(SolutionDir)lib\common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>_DEBUG;_LIB;_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
       <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
@@ -65,7 +65,7 @@
   </ItemDefinitionGroup>
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
     <ClCompile>
-      <AdditionalIncludeDirectories>$(SolutionDir)windows\dependencies\libraries\x86\include;$(SolutionDir)windows\dependencies\libraries\x86\include\cairo;$(SolutionDir)lib;$(SolutionDir)lib\common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
+      <AdditionalIncludeDirectories>$(SolutionDir)windows\dependencies\libraries\x86\include;$(SolutionDir)windows\dependencies\libraries\x86\include\cairo;$(SolutionDir)windows\include\unistd;$(SolutionDir)lib;$(SolutionDir)lib\common;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
       <PreprocessorDefinitions>NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <PrecompiledHeader />
       <WarningLevel>Level4</WarningLevel>
index 02943df071fb899c423d337c1ecacfb13aec01e5..67dadc189fe02de7d922ecee8a5099262d4ae94a 100644 (file)
@@ -9,6 +9,7 @@
  *************************************************************************/
 
 #include <glcomp/glpangofont.h>
+#include <unistd.h>
 
 #define DEFAULT_FONT_FAMILY "Arial"
 #define DEFAULT_FONT_SIZE 32
 
 static int file_exists(const char *filename)
 {
-    FILE *file;
-    if ((file = fopen(filename, "r"))) {
-       fclose(file);
-       return 1;
-    }
-    return 0;
+  return access(filename, R_OK) == 0;
 }
 
 static PangoLayout *get_pango_layout(char *markup_text,