Changeset aa15080
- Timestamp:
- Nov 29, 2018, 12:07:58 AM (6 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master
- Children:
- d22b568
- Parents:
- a6065b9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/utils_tests.h
ra6065b9 raa15080 64 64 } 65 65 66 // create_temp_sink / close_temp_sink 67 #if defined(__GNUC__) // mkstemp 68 69 int create_temp_sink(char *sink_path) 70 { 71 return mkstemp(sink_path); 72 } 73 74 int close_temp_sink(char *sink_path, int sink_fildes) 75 { 76 int err; 77 if ((err = close(sink_fildes)) != 0) return err; 78 if ((err = unlink(sink_path)) != 0) return err; 79 return err; 80 } 81 82 #elif (defined(HAVE_WIN_HACKS) //&& !defined(__GNUC__)) 83 // windows workaround, where mkstemp does not exist... 84 int create_temp_sink(char *templ) 85 { 86 int i = 0; 87 static const char letters[] = "abcdefg0123456789"; 88 int letters_len = strlen(letters); 89 int templ_len = strlen(templ); 90 if (templ_len == 0) return 0; 91 utils_init_random(); 92 for (i = 0; i < 6; i++) 93 { 94 templ[templ_len - i] = letters[rand() % letters_len]; 95 } 96 return 1; 97 } 98 99 int close_temp_sink(char* sink_path, int sink_fildes) { 100 // the file should be closed when not using mkstemp, no need to open it 101 if (sink_fildes == 0) return 1; 102 return _unlink(sink_path); 103 } 104 105 #else // windows workaround 106 // otherwise, we don't really know what to do yet 107 #error "mkstemp undefined, but not on windows. additional workaround required." 108 #endif 109 110 66 111 int run_on_default_sink( int main(int, char**) ) 67 112 { … … 69 114 char* argv[argc]; 70 115 char sink_path[PATH_MAX] = "tmp_aubio_XXXXXX"; 71 int fd = mkstemp(sink_path); 116 int fd = create_temp_sink(sink_path); 117 if (!fd) return 1; 72 118 argv[0] = __FILE__; 73 if (!fd) return 1;74 119 argv[1] = sink_path; 75 120 err = main(argc, argv); 76 unlink(sink_path); 77 close(fd); 121 close_temp_sink(sink_path, fd); 78 122 return err; 79 123 }
Note: See TracChangeset
for help on using the changeset viewer.