move ScopedFileDescriptor into libpbd and use it

This commit is contained in:
Paul Davis 2014-12-14 12:26:00 -05:00
parent 06f2136c4f
commit 0fa5643d20
3 changed files with 38 additions and 9 deletions

View File

@ -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

View File

@ -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;

View File

@ -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__ */