2929# include < unistd.h> // for getcwd
3030#endif
3131
32- #include " ../src/rawtoaces_util/rawtoaces_util_priv.h"
33- #include < rawtoaces/image_converter.h>
34-
3532using namespace rta ::util;
3633
3734std::string convert_linux_path_to_windows_path ( const std::string &path )
@@ -50,6 +47,25 @@ std::string convert_linux_path_to_windows_path( const std::string &path )
5047 return OIIO::Strutil::join ( segments, " ;" );
5148}
5249
50+ FILE *platform_popen ( const char *command, const char *mode )
51+ {
52+ #ifdef WIN32
53+ return _popen ( command, mode );
54+ #else
55+ return popen ( command, mode );
56+ #endif
57+ }
58+
59+ int platform_pclose ( FILE *pipe )
60+ {
61+ #ifdef WIN32
62+ return _pclose ( pipe );
63+ #else
64+ int status = pclose ( pipe );
65+ return WEXITSTATUS ( status );
66+ #endif
67+ }
68+
5369// / Executes a rawtoaces command with the given arguments and captures its output.
5470// /
5571// / @param args Vector of command-line arguments to pass to rawtoaces (excluding program name).
@@ -72,9 +88,8 @@ std::string run_rawtoaces_command( const std::vector<std::string> &args )
7288 command += " " + arg;
7389 }
7490
75- #ifdef WIN32
76- // Windows implementation using _popen
77- FILE *pipe = _popen ( command.c_str (), " r" );
91+ // Execute command using platform-specific functions
92+ FILE *pipe = platform_popen ( command.c_str (), " r" );
7893 OIIO_CHECK_ASSERT (
7994 pipe != nullptr && " Failed to execute rawtoaces command" );
8095
@@ -87,26 +102,8 @@ std::string run_rawtoaces_command( const std::vector<std::string> &args )
87102 }
88103
89104 // Get exit status and validate
90- int exit_status = _pclose ( pipe );
105+ int exit_status = platform_pclose ( pipe );
91106 OIIO_CHECK_EQUAL ( exit_status, 0 );
92- #else
93- // Unix implementation using popen
94- FILE *pipe = popen ( command.c_str (), " r" );
95- OIIO_CHECK_ASSERT (
96- pipe != nullptr && " Failed to execute rawtoaces command" );
97-
98- // Read output
99- std::string output;
100- char buffer[4096 ];
101- while ( fgets ( buffer, sizeof ( buffer ), pipe ) != nullptr )
102- {
103- output += buffer;
104- }
105-
106- // Get exit status and validate
107- int exit_status = pclose ( pipe );
108- OIIO_CHECK_EQUAL ( WEXITSTATUS ( exit_status ), 0 );
109- #endif
110107
111108 return output;
112109}
@@ -118,7 +115,7 @@ getenv() - Part of standard C library (C89/C99) - available everywhere
118115setenv()/unsetenv() - Part of POSIX standard - only on Unix-like systems
119116*/
120117#ifdef WIN32
121- void set_env_var ( std::string name, std::string value )
118+ void set_env_var ( const std::string & name, const std::string & value )
122119{
123120 _putenv_s ( name.c_str (), value.c_str () );
124121}
@@ -128,7 +125,7 @@ std::string to_os_path( std::string linux_path )
128125 return convert_linux_path_to_windows_path ( linux_path );
129126}
130127
131- void unset_env_var ( std::string name )
128+ void unset_env_var ( const std::string & name )
132129{
133130 _putenv_s ( name.c_str (), " " );
134131}
@@ -138,12 +135,12 @@ std::string to_os_path( std::string linux_path )
138135 return linux_path;
139136}
140137
141- void set_env_var ( std::string name, std::string value )
138+ void set_env_var ( const std::string & name, const std::string & value )
142139{
143140 setenv ( name.c_str (), value.c_str (), 1 );
144141}
145142
146- void unset_env_var ( std::string name )
143+ void unset_env_var ( const std::string & name )
147144{
148145 unsetenv ( name.c_str () );
149146}
0 commit comments