1 // Generated by gtkmmproc -- DO NOT MODIFY!
3 #include <glibmm/fileutils.h>
4 #include <glibmm/private/fileutils_p.h>
9 /* Copyright (C) 2002 The gtkmm Development Team
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Library General Public
13 * License as published by the Free Software Foundation; either
14 * version 2 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Library General Public License for more details.
21 * You should have received a copy of the GNU Library General Public
22 * License along with this library; if not, write to the Free
23 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #include <glib/gdir.h>
27 #include <glib/gfileutils.h>
28 #include <glib/gstrfuncs.h>
29 #include <glibmm/utility.h>
35 /**** Glib::Dir ************************************************************/
37 Dir::Dir(const std::string& path)
40 gobject_ = g_dir_open(path.c_str(), 0, &error);
43 Glib::Error::throw_exception(error);
46 Dir::Dir(GDir* gobject)
54 g_dir_close(gobject_);
57 std::string Dir::read_name()
59 const char *const name = g_dir_read_name(gobject_);
60 return (name) ? std::string(name) : std::string();
65 g_dir_rewind(gobject_);
72 g_dir_close(gobject_);
77 DirIterator Dir::begin()
79 g_dir_rewind(gobject_);
80 return DirIterator(gobject_, g_dir_read_name(gobject_));
83 DirIterator Dir::end()
85 return DirIterator(gobject_, 0);
89 /**** Glib::DirIterator ****************************************************/
91 DirIterator::DirIterator()
97 DirIterator::DirIterator(GDir* gobject, const char* current)
103 std::string DirIterator::operator*() const
105 return (current_) ? std::string(current_) : std::string();
108 DirIterator& DirIterator::operator++()
110 current_ = g_dir_read_name(gobject_);
114 void DirIterator::operator++(int)
116 current_ = g_dir_read_name(gobject_);
119 bool DirIterator::operator==(const DirIterator& rhs) const
121 return (current_ == rhs.current_);
124 bool DirIterator::operator!=(const DirIterator& rhs) const
126 return (current_ != rhs.current_);
130 bool file_test(const std::string& filename, FileTest test)
132 return g_file_test(filename.c_str(), static_cast<GFileTest>(unsigned(test)));
135 int mkstemp(std::string& filename_template)
137 const ScopedPtr<char> buf (g_strndup(filename_template.data(), filename_template.size()));
138 const int fileno = g_mkstemp(buf.get());
140 filename_template = buf.get();
144 int file_open_tmp(std::string& name_used, const std::string& prefix)
146 std::string basename_template (prefix);
147 basename_template += "XXXXXX"; // this sillyness shouldn't be in the interface
150 ScopedPtr<char> buf_name_used;
152 const int fileno = g_file_open_tmp(basename_template.c_str(), buf_name_used.addr(), &error);
155 Glib::Error::throw_exception(error);
157 name_used = buf_name_used.get();
161 int file_open_tmp(std::string& name_used)
164 ScopedPtr<char> buf_name_used;
166 const int fileno = g_file_open_tmp(0, buf_name_used.addr(), &error);
169 Glib::Error::throw_exception(error);
171 name_used = buf_name_used.get();
175 std::string file_get_contents(const std::string& filename)
177 ScopedPtr<char> contents;
181 g_file_get_contents(filename.c_str(), contents.addr(), &length, &error);
184 Glib::Error::throw_exception(error);
186 return std::string(contents.get(), length);
194 } // anonymous namespace
197 Glib::FileError::FileError(Glib::FileError::Code error_code, const Glib::ustring& error_message)
199 Glib::Error (G_FILE_ERROR, error_code, error_message)
202 Glib::FileError::FileError(GError* gobject)
204 Glib::Error (gobject)
207 Glib::FileError::Code Glib::FileError::code() const
209 return static_cast<Code>(Glib::Error::code());
212 void Glib::FileError::throw_func(GError* gobject)
214 throw Glib::FileError(gobject);