diff options
author | Roger Leigh <rleigh@debian.org> | 2011-03-01 12:58:41 +0000 |
---|---|---|
committer | Roger Leigh <rleigh@debian.org> | 2011-03-01 12:58:41 +0000 |
commit | 0fffa8573eec10016e848f180932f29b9656c6a0 (patch) | |
tree | c1cf1d52b40467b48eaa3b100fec583130a4601b | |
parent | 71d4992ea38501959f24521375018f2f0cd5933f (diff) | |
download | schroot-0fffa8573eec10016e848f180932f29b9656c6a0.tar.gz |
sbuild: Replace GCC-specific stdio_filebuf with Boost.Iostreams
Use Boost.Iostreams file_descriptor classes with stream to replace
__gnu_cxx::stdio_filebuf. This means that the source no longer
absolutely depends upon GCC to build, so may build with other
compilers.
-rw-r--r-- | configure.ac | 28 | ||||
-rw-r--r-- | sbuild/Makefile.am | 1 | ||||
-rw-r--r-- | sbuild/sbuild-chroot-config.cc | 10 | ||||
-rw-r--r-- | sbuild/sbuild-chroot.cc | 10 | ||||
-rw-r--r-- | sbuild/sbuild-ctty.cc | 7 | ||||
-rw-r--r-- | sbuild/sbuild-ctty.h | 6 | ||||
-rw-r--r-- | sbuild/sbuild-fdstream.h | 45 |
7 files changed, 77 insertions, 30 deletions
diff --git a/configure.ac b/configure.ac index 6810d658..fc54f673 100644 --- a/configure.ac +++ b/configure.ac @@ -360,10 +360,10 @@ AC_CHECK_HEADERS([boost/tuple/tuple.hpp],, [ fi]) AC_CHECK_HEADERS([boost/format.hpp],, [AC_MSG_ERROR([Boost.Format (Boost C++ Libraries) is not installed, but is required by schroot])]) +AC_CHECK_HEADERS([boost/iostreams/device/file_descriptor.hpp],, [AC_MSG_ERROR([Boost.Iostreams (Boost C++ Libraries) is not installed, but is required by schroot])]) AC_CHECK_HEADERS([boost/program_options.hpp],, [AC_MSG_ERROR([Boost.Program_options (Boost C++ Libraries) is not installed, but is required by schroot])]) AC_CHECK_HEADERS([boost/type_traits.hpp],, [AC_MSG_ERROR([Boost.TypeTraits (Boost C++ Libraries) is not installed, but is required by schroot])]) -AC_CHECK_HEADERS([ext/stdio_filebuf.h],, [AC_MSG_ERROR([__gnu_cxx::stdio_filebuf (GNU libstdc++) is not installed, but is required by schroot])]) AC_CHECK_HEADERS([sys/personality.h], [PERSONALITY_HEADER="yes"], @@ -670,6 +670,24 @@ AC_LINK_IFELSE(testprog, AC_MSG_FAILURE([libboost_regex (Boost C++ Libraries) is not installed, but is required by schroot])])]) LIBS="${saved_LIBS}" +AC_MSG_CHECKING([for boost::iostreams in -lboost_iostreams]) +saved_LIBS="${LIBS}" +LIBS="${saved_LIBS} -lboost_iostreams" +define([testprog], [AC_LANG_PROGRAM([#include <boost/iostreams/device/file_descriptor.hpp> +#include <boost/iostreams/stream.hpp> +], + [ boost::iostreams::stream<boost::iostreams::file_descriptor> fdstream;])]) +AC_LINK_IFELSE(testprog, + [AC_MSG_RESULT([yes]) + BOOST_LIBS="${BOOST_LIBS} -lboost_iostreams"], +[LIBS="${saved_LIBS} -lboost_iostreams-mt" + AC_LINK_IFELSE(testprog, + [AC_MSG_RESULT([yes]) + BOOST_LIBS="${BOOST_LIBS} -lboost_iostreams-mt"], + [AC_MSG_RESULT([no]) + AC_MSG_FAILURE([libboost_iostreams (Boost C++ Libraries) is not installed, but is required by schroot])])]) +LIBS="${saved_LIBS}" + AC_MSG_CHECKING([for boost::filesystem in -lboost_filesystem]) saved_LIBS="${LIBS}" LIBS="${saved_LIBS} -lboost_filesystem -lboost_system" @@ -689,14 +707,6 @@ LIBS="${saved_LIBS}" AC_SUBST([BOOST_LIBS]) AC_SUBST([BOOST_FILESYSTEM_LIBS]) -AC_MSG_CHECKING([for __gnu_cxx::stdio_filebuf in libstdc++]) -AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <ext/stdio_filebuf.h> -#include <unistd.h>], - [__gnu_cxx::stdio_filebuf<char> fdbuf(STDOUT_FILENO, std::ios::out)])], - [AC_MSG_RESULT([yes])], - [AC_MSG_RESULT([no]) - AC_MSG_FAILURE([__gnu_cxx::stdio_filebuf (GNU libstdc++) is not installed, but is required by schroot])]) - dnl Set PACKAGE_LOCALE_DIR in config.h AH_TEMPLATE(PACKAGE_LOCALE_DIR, [Package locale directory]) if test "x${prefix}" = "xNONE"; then diff --git a/sbuild/Makefile.am b/sbuild/Makefile.am index 19f5ce0c..3843516b 100644 --- a/sbuild/Makefile.am +++ b/sbuild/Makefile.am @@ -48,6 +48,7 @@ sbuild_public_h_sources = \ sbuild-environment.h \ sbuild-error.h \ sbuild-error.tcc \ + sbuild-fdstream.h \ sbuild-format-detail.h \ sbuild-i18n.h \ sbuild-keyfile-base.h \ diff --git a/sbuild/sbuild-chroot-config.cc b/sbuild/sbuild-chroot-config.cc index fe549f89..7f760894 100644 --- a/sbuild/sbuild-chroot-config.cc +++ b/sbuild/sbuild-chroot-config.cc @@ -23,6 +23,7 @@ #include "sbuild-chroot-facet-session-clonable.h" #include "sbuild-chroot-facet-source-clonable.h" #include "sbuild-chroot-config.h" +#include "sbuild-fdstream.h" #include "sbuild-lock.h" #include <cassert> @@ -30,8 +31,6 @@ #include <cstdlib> #include <cstring> -#include <ext/stdio_filebuf.h> - #include <boost/filesystem/operations.hpp> #include <sys/types.h> @@ -676,10 +675,9 @@ chroot_config::load_data (std::string const& chroot_namespace, if (!file_status2.is_regular()) throw error(file, FILE_NOTREG); - // Create a stream buffer from the file descriptor. The fd will - // be closed when the buffer is destroyed. - __gnu_cxx::stdio_filebuf<char> fdbuf(fd, std::ios::in); - std::istream input(&fdbuf); + // Create a stream from the file descriptor. The fd will be closed + // when the stream is destroyed. + fdistream input(fd, boost::iostreams::close_handle); input.imbue(std::locale::classic()); try diff --git a/sbuild/sbuild-chroot.cc b/sbuild/sbuild-chroot.cc index 67f8c446..46ac0c1a 100644 --- a/sbuild/sbuild-chroot.cc +++ b/sbuild/sbuild-chroot.cc @@ -40,14 +40,13 @@ #include "sbuild-chroot-facet-session.h" #include "sbuild-chroot-facet-session-clonable.h" #include "sbuild-chroot-facet-source.h" +#include "sbuild-fdstream.h" #include "sbuild-lock.h" #include <cerrno> #include <map> #include <utility> -#include <ext/stdio_filebuf.h> - #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> @@ -513,10 +512,9 @@ sbuild::chroot::setup_session_info (bool start) if (fd < 0) throw error(file, SESSION_WRITE, strerror(errno)); - // Create a stream buffer from the file descriptor. The fd will - // be closed when the buffer is destroyed. - __gnu_cxx::stdio_filebuf<char> fdbuf(fd, std::ios::out); - std::ostream output(&fdbuf); + // Create a stream from the file descriptor. The fd will be + // closed when the stream is destroyed. + fdostream output(fd, boost::iostreams::close_handle); output.imbue(std::locale::classic()); file_lock lock(fd); diff --git a/sbuild/sbuild-ctty.cc b/sbuild/sbuild-ctty.cc index 35d07a7c..65e118d5 100644 --- a/sbuild/sbuild-ctty.cc +++ b/sbuild/sbuild-ctty.cc @@ -23,8 +23,6 @@ #include <cerrno> #include <cstring> -#include <ext/stdio_filebuf.h> - #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> @@ -121,9 +119,8 @@ namespace } /// A streambuf for cctty. - __gnu_cxx::stdio_filebuf<char> cttybuf(cttybuf_fd(), - std::ios::in|std::ios::out); + // boost::iostreams::file_descriptor cttybuf(cttybuf_fd(), close_handle); } -std::iostream sbuild::cctty(&cttybuf); +fdstream sbuild::cctty(cttybuf_fd(), boost::iostreams::close_handle); diff --git a/sbuild/sbuild-ctty.h b/sbuild/sbuild-ctty.h index 9d7273c4..c1f03b82 100644 --- a/sbuild/sbuild-ctty.h +++ b/sbuild/sbuild-ctty.h @@ -19,11 +19,9 @@ #ifndef SBUILD_CTTY_H #define SBUILD_CTTY_H +#include <sbuild/sbuild-fdstream.h> #include <sbuild/sbuild-parse-error.h> -#include <streambuf> -#include <ostream> - namespace sbuild { @@ -51,7 +49,7 @@ namespace sbuild * CTTY stream. A stream to the Controlling TTY, or standard input * if not available. */ - extern std::iostream cctty; + extern fdstream cctty; } diff --git a/sbuild/sbuild-fdstream.h b/sbuild/sbuild-fdstream.h new file mode 100644 index 00000000..42ef81a6 --- /dev/null +++ b/sbuild/sbuild-fdstream.h @@ -0,0 +1,45 @@ +/* Copyright © 2011 Roger Leigh <rleigh@debian.org> + * + * schroot 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 3 of the License, or + * (at your option) any later version. + * + * schroot 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, see + * <http://www.gnu.org/licenses/>. + * + *********************************************************************/ + +#ifndef SBUILD_FDSTREAM_H +#define SBUILD_FDSTREAM_H + +#include <boost/iostreams/device/file_descriptor.hpp> +#include <boost/iostreams/stream.hpp> + +namespace sbuild +{ + + // Stream type. + typedef boost::iostreams::stream<boost::iostreams::file_descriptor> fdstream; + + // Stream type. + typedef boost::iostreams::stream<boost::iostreams::file_descriptor_source> fdistream; + + // Stream type. + typedef boost::iostreams::stream<boost::iostreams::file_descriptor_sink> fdostream; + +} + +#endif /* SBUILD_FDSTREAM_H */ + +/* + * Local Variables: + * mode:C++ + * End: + */ |