3 * Copyright 2004,2006,2007 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>
35 // win32 (mingw/msvc) specific
40 #define OUR_O_BINARY O_BINARY
42 #define OUR_O_BINARY 0
45 // should be handled via configure
47 #define OUR_O_LARGEFILE O_LARGEFILE
49 #define OUR_O_LARGEFILE 0
52 gr_file_sink_base::gr_file_sink_base(const char *filename, bool is_binary)
53 : d_fp(0), d_new_fp(0), d_updated(false), d_is_binary(is_binary)
56 throw std::runtime_error ("can't open file");
59 gr_file_sink_base::~gr_file_sink_base ()
69 gr_file_sink_base::open(const char *filename)
71 omni_mutex_lock l(d_mutex); // hold mutex for duration of this function
73 // we use the open system call to get access to the O_LARGEFILE flag.
75 if ((fd = ::open (filename,
76 O_WRONLY|O_CREAT|O_TRUNC|OUR_O_LARGEFILE|OUR_O_BINARY,
82 if (d_new_fp){ // if we've already got a new one open, close it
87 if ((d_new_fp = fdopen (fd, d_is_binary ? "wb" : "w")) == NULL){
89 ::close(fd); // don't leak file descriptor if fdopen fails.
97 gr_file_sink_base::close()
99 omni_mutex_lock l(d_mutex); // hold mutex for duration of this function
109 gr_file_sink_base::do_update()
112 omni_mutex_lock l(d_mutex); // hold mutex for duration of this block
115 d_fp = d_new_fp; // install new file pointer