3 * Copyright 2004,2006,2007,2009 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
7 * GNU Radio is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3, or (at your option)
12 * GNU Radio is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Radio; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street,
20 * Boston, MA 02110-1301, USA.
27 #include <gr_file_sink_base.h>
29 #include <sys/types.h>
34 #include <gruel/thread.h>
36 // win32 (mingw/msvc) specific
41 #define OUR_O_BINARY O_BINARY
43 #define OUR_O_BINARY 0
46 // should be handled via configure
48 #define OUR_O_LARGEFILE O_LARGEFILE
50 #define OUR_O_LARGEFILE 0
53 gr_file_sink_base::gr_file_sink_base(const char *filename, bool is_binary)
54 : d_fp(0), d_new_fp(0), d_updated(false), d_is_binary(is_binary)
57 throw std::runtime_error ("can't open file");
60 gr_file_sink_base::~gr_file_sink_base ()
70 gr_file_sink_base::open(const char *filename)
72 gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function
74 // we use the open system call to get access to the O_LARGEFILE flag.
76 if ((fd = ::open (filename,
77 O_WRONLY|O_CREAT|O_TRUNC|OUR_O_LARGEFILE|OUR_O_BINARY,
83 if (d_new_fp){ // if we've already got a new one open, close it
88 if ((d_new_fp = fdopen (fd, d_is_binary ? "wb" : "w")) == NULL){
90 ::close(fd); // don't leak file descriptor if fdopen fails.
98 gr_file_sink_base::close()
100 gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this function
110 gr_file_sink_base::do_update()
113 gruel::scoped_lock guard(d_mutex); // hold mutex for duration of this block
116 d_fp = d_new_fp; // install new file pointer