X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=ETL%2Ftrunk%2FETL%2F_stringf.h;h=f91cfca48936881caa504771d354914675a6866d;hb=5fcd703aaea3794acfcaee35f91265d7ad2247ac;hp=60653c36feaa4608cdbae396225d241040b75b4a;hpb=4ec81d053bf1d0cbcd9f0bf048914ec8eca08f4c;p=synfig.git diff --git a/ETL/trunk/ETL/_stringf.h b/ETL/trunk/ETL/_stringf.h index 60653c3..f91cfca 100644 --- a/ETL/trunk/ETL/_stringf.h +++ b/ETL/trunk/ETL/_stringf.h @@ -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 @@ -39,6 +40,14 @@ #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 @@ -82,9 +91,12 @@ vstrprintf(const char *format, va_list args) #ifdef HAVE_VASPRINTF // This is the preferred method (and safest) char *buffer; std::string ret; - vasprintf(&buffer,format,args); - ret=buffer; - free(buffer); + int i=vasprintf(&buffer,format,args); + if (i>-1) + { + ret=buffer; + free(buffer); + } return ret; #else #ifdef HAVE_VSNPRINTF // This is the secondary method (Safe, but bulky) @@ -189,14 +201,38 @@ dirname(const std::string &str) break; if(iter==str.begin()) + { if (*iter==ETL_DIRECTORY_SEPARATOR) return "/"; else return "."; + } 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) {