popen() doesn't like type "rb" on Linux, either.
[synfig.git] / ETL / trunk / ETL / _stringf.h
index 60653c3..dfc4bcf 100644 (file)
@@ -4,6 +4,7 @@
 ** $Id$
 **
 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
+** Copyright (c) 2007 Chris Moore
 **
 ** This package is free software; you can redistribute it and/or
 ** modify it under the terms of the GNU General Public License as
 #define ETL_STRPRINTF_MAX_LENGTH       (800)
 #endif
 
+#ifdef WIN32
+#define POPEN_BINARY_READ_TYPE "rb"
+#define POPEN_BINARY_WRITE_TYPE "wb"
+#else
+#define POPEN_BINARY_READ_TYPE "r"
+#define POPEN_BINARY_WRITE_TYPE "w"
+#endif
+
 /* === T Y P E D E F S ===================================================== */
 
 _ETL_BEGIN_CDECLS
@@ -197,6 +206,28 @@ dirname(const std::string &str)
        return std::string(str.begin(),iter);
 }
 
+// filename_extension("/f.e/d.c") => ".c"
+inline std::string
+filename_extension(const std::string &str)
+{
+       std::string base = basename(str);
+       std::string::size_type pos = base.find_last_of('.');
+       if (pos == std::string::npos) return std::string();
+       return base.substr(pos);
+}
+
+// filename_sans_extension("/f.e/d.c") => "/f.e/d"
+inline std::string
+filename_sans_extension(const std::string &str)
+{
+       std::string base = basename(str);
+       std::string::size_type pos = base.find_last_of('.');
+       if (pos == std::string::npos) return str;
+       std::string dir = dirname(str);
+       if (dir == ".") return base.substr(0,pos);
+       return dir + ETL_DIRECTORY_SEPARATOR + base.substr(0,pos);
+}
+
 inline bool
 is_absolute_path(const std::string &path)
 {