summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libs/ardour/audiosource.cc8
-rw-r--r--libs/pbd/file_utils.cc5
-rw-r--r--libs/pbd/pbd/scoped_file_descriptor.h34
3 files changed, 38 insertions, 9 deletions
diff --git a/libs/ardour/audiosource.cc b/libs/ardour/audiosource.cc
index f543c3ee08..b0b229a57a 100644
--- a/libs/ardour/audiosource.cc
+++ b/libs/ardour/audiosource.cc
@@ -43,6 +43,7 @@
#include <glibmm/fileutils.h>
#include <glibmm/miscutils.h>
+#include "pbd/scoped_file_descriptor.h"
#include "pbd/xml++.h"
#include "ardour/audiosource.h"
@@ -320,13 +321,6 @@ AudioSource::read_peaks (PeakData *peaks, framecnt_t npeaks, framepos_t start, f
* @param npeaks Number of peaks to write.
*/
-struct ScopedFileDescriptor {
- ScopedFileDescriptor (int fd) : _fd (fd) {}
- ~ScopedFileDescriptor() { if ((-1) != _fd) close (_fd); }
- operator int() { return _fd; }
- int _fd;
-};
-
int
AudioSource::read_peaks_with_fpp (PeakData *peaks, framecnt_t npeaks, framepos_t start, framecnt_t cnt,
double samples_per_visual_peak, framecnt_t samples_per_file_peak) const
diff --git a/libs/pbd/file_utils.cc b/libs/pbd/file_utils.cc
index 89f6818704..f8ab326c5b 100644
--- a/libs/pbd/file_utils.cc
+++ b/libs/pbd/file_utils.cc
@@ -54,6 +54,7 @@
#include "pbd/debug.h"
#include "pbd/error.h"
#include "pbd/pathexpand.h"
+#include "pbd/scoped_file_descriptor.h"
#include "pbd/stl_delete.h"
#include "i18n.h"
@@ -281,8 +282,8 @@ copy_file(const std::string & from_path, const std::string & to_path)
{
if (!Glib::file_test (from_path, Glib::FILE_TEST_EXISTS)) return false;
- int fd_from (::open (from_path.c_str(), O_RDONLY));
- int fd_to (::open (to_path.c_str(), O_CREAT|O_TRUNC|O_RDWR, 0666));
+ PBD::ScopedFileDescriptor fd_from (::open (from_path.c_str(), O_RDONLY));
+ PBD::ScopedFileDescriptor fd_to (::open (to_path.c_str(), O_CREAT|O_TRUNC|O_RDWR, 0666));
char buf[4096]; // BUFSIZ ??
ssize_t nread;
diff --git a/libs/pbd/pbd/scoped_file_descriptor.h b/libs/pbd/pbd/scoped_file_descriptor.h
new file mode 100644
index 0000000000..ee0498e8a8
--- /dev/null
+++ b/libs/pbd/pbd/scoped_file_descriptor.h
@@ -0,0 +1,34 @@
+/*
+ Copyright (C) 2014 Paul Davis
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#ifndef __libpbd_scoped_file_descriptor_h__
+#define __libpbd_scoped_file_descriptor_h__
+
+namespace PBD {
+
+struct ScopedFileDescriptor {
+ ScopedFileDescriptor (int fd) : _fd (fd) {}
+ ~ScopedFileDescriptor() { if (_fd >= 0) close (_fd); }
+ operator int() { return _fd; }
+ int _fd;
+};
+
+}
+
+#endif /* __libpbd_scoped_file_descriptor_h__ */