diff options
author | Andy Cedilnik <andy.cedilnik@kitware.com> | 2005-12-28 21:30:55 (GMT) |
---|---|---|
committer | Andy Cedilnik <andy.cedilnik@kitware.com> | 2005-12-28 21:30:55 (GMT) |
commit | fdc844ecdb4d3f67e83ebcb7303ba67a115ac9eb (patch) | |
tree | 6c5806e7deee91efd590125038b27fdb16549059 /Source/cmSystemTools.cxx | |
parent | ba63b6f15ecb8c3011244468e7c6257a43d2dc6b (diff) | |
download | CMake-fdc844ecdb4d3f67e83ebcb7303ba67a115ac9eb.zip CMake-fdc844ecdb4d3f67e83ebcb7303ba67a115ac9eb.tar.gz CMake-fdc844ecdb4d3f67e83ebcb7303ba67a115ac9eb.tar.bz2 |
ENH: Add method to create tar
Diffstat (limited to 'Source/cmSystemTools.cxx')
-rw-r--r-- | Source/cmSystemTools.cxx | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/Source/cmSystemTools.cxx b/Source/cmSystemTools.cxx index e2df4b2..bc350cd 100644 --- a/Source/cmSystemTools.cxx +++ b/Source/cmSystemTools.cxx @@ -1358,3 +1358,59 @@ bool cmSystemTools::IsPathToFramework(const char* path) } return false; } + +#include <libtar/libtar.h> +#include <memory> // auto_ptr + +bool cmSystemTools::CreateTar(const char* outFileName, const std::vector<cmStdString>& files) +{ + TAR *t; + char buf[TAR_MAXPATHLEN]; + char pathname[TAR_MAXPATHLEN]; + + // Ok, this libtar is not const safe. for now use auto_ptr hack + char* realName = new char[ strlen(outFileName) + 1 ]; + std::auto_ptr<char> realNamePtr(realName); + strcpy(realName, outFileName); + if (tar_open(&t, realName, + NULL, + O_WRONLY | O_CREAT, 0644, + TAR_VERBOSE + | 0) == -1) + { + fprintf(stderr, "tar_open(): %s\n", strerror(errno)); + return -1; + } + + std::vector<cmStdString>::const_iterator it; + for (it = files.begin(); it != files.end(); ++ it ) + { + strncpy(pathname, it->c_str(), sizeof(pathname)); + pathname[sizeof(pathname)-1] = 0; + strncpy(buf, pathname, sizeof(buf)); + buf[sizeof(buf)-1] = 0; + if (tar_append_tree(t, buf, pathname) != 0) + { + fprintf(stderr, + "tar_append_tree(\"%s\", \"%s\"): %s\n", buf, + pathname, strerror(errno)); + tar_close(t); + return -1; + } + } + + if (tar_append_eof(t) != 0) + { + fprintf(stderr, "tar_append_eof(): %s\n", strerror(errno)); + tar_close(t); + return -1; + } + + if (tar_close(t) != 0) + { + fprintf(stderr, "tar_close(): %s\n", strerror(errno)); + return -1; + } + std::cout << "CreateTar: " << outFileName << std::endl; + return false; +} |