@@ -14,26 +14,33 @@ extern "C" {
1414
1515// Create directory if not exists
1616void createDirectory (const char * path) {
17- try {
18- std::filesystem::create_directories (path);
19- } catch ( const std::exception& e ) {
20- fprintf (stderr, " Failed to create directory %s: %s\n " , path, e. what ());
17+ std::error_code ec;
18+ std::filesystem::create_directories (path, ec );
19+ if (ec ) {
20+ fprintf (stderr, " Failed to create directory %s: %s\n " , path, ec. message (). c_str ());
2121 }
2222}
2323
2424// Get current working directory (portable)
25- int getCurrentWorkingDirectory (char * buffer, int size) {
26- try {
27- auto cwd = std::filesystem::current_path ().string ();
28- if (cwd.size () >= size) {
29- return -1 ; // Buffer too small
30- }
31- strcpy (buffer, cwd.c_str ());
32- return 0 ;
33- } catch (const std::exception& e) {
34- fprintf (stderr, " Failed to get current working directory: %s\n " , e.what ());
25+ int getCurrentWorkingDirectory (char * buffer, size_t size) {
26+ if (!buffer || size == 0 ) {
27+ return -1 ;
28+ }
29+
30+ std::error_code ec;
31+ auto cwd = std::filesystem::current_path (ec);
32+ if (ec) {
33+ fprintf (stderr, " Failed to get current working directory: %s\n " , ec.message ().c_str ());
3534 return -1 ;
3635 }
36+
37+ std::string cwd_str = cwd.string ();
38+ if (cwd_str.size () >= size) {
39+ return -1 ; // Buffer too small
40+ }
41+ strncpy (buffer, cwd_str.c_str (), size - 1 );
42+ buffer[size - 1 ] = ' \0 ' ;
43+ return 0 ;
3744}
3845
3946int selectCamera (CcapProvider* provider) {
0 commit comments