-
- if ((sf = sf_open (path.c_str(), SFM_RDWR, &format_info)) == 0) {
- cerr << "Could not open file #" << n << " @ " << path << endl;
+
+ int flags = O_RDWR|O_CREAT|O_TRUNC;
+ int fd = open (path.c_str(), flags, 0644);
+
+ if (fd < 0) {
+ cerr << "Could not open file #" << n << " @ " << path << " (" << strerror (errno) << ")" << endl;
+ return 1;
+ }
+
+#ifdef __APPLE__
+ if (direct) {
+ /* Apple man pages say only that it returns "a value other than -1 on success",
+ which probably means zero, but you just can't be too careful with
+ those guys.
+ */
+ if (fcntl (fd, F_NOCACHE, 1) == -1) {
+ cerr << "Cannot set F_NOCACHE on file # " << n << endl;
+ }
+ }
+#endif
+ if ((sf = sf_open_fd (fd, SFM_RDWR, &format_info, true)) == 0) {
+ cerr << "Could not open SNDFILE #" << n << " @ " << path << " (" << sf_strerror (0) << ")" << endl;