{"id":131,"date":"2015-08-16T09:52:26","date_gmt":"2015-08-16T09:52:26","guid":{"rendered":"http:\/\/emacslisp.com\/?p=131"},"modified":"2015-08-16T09:54:01","modified_gmt":"2015-08-16T09:54:01","slug":"libtar-and-its-api","status":"publish","type":"post","link":"http:\/\/emacslisp.com\/?p=131","title":{"rendered":"libtar and its api"},"content":{"rendered":"<p>libtar is small but effective library, although it has some bugs when dealing with long path.<\/p>\n<p>The Steps are following:<br \/>\ndownload libtar-1.2.11 and uncompress it, the main path is \/path\/libtar-1.2.11<\/p>\n<p>build with command &#8220;.\/configure &amp;&amp; make&#8221;, if you want to debug, add &#8220;-g&#8221; for gcc to build.<\/p>\n<p>make &#8220;test&#8221; folder &#8220;\/path\/libtar-1.2.11\/test&#8221;. find header file and libtar.a file<\/p>\n<p>put 1.c in &#8220;\/path\/libtar-1.2.11\/test&#8221;<\/p>\n<p>so finally, the build command will be &#8220;g++ 1.c -o 1 ..\/lib\/libtar.a -I ..\/bin\/libtar-1.2.11\/include&#8221;<\/p>\n<p>some important code, for example, <strong>char* subfile1 = &#8220;.\/sub1\/1.txt&#8221;<\/strong><br \/>\nthis is for file under sub folder.<\/p>\n<pre lang=\"c\" line=\"1\">  \r\n #include <tar.h>  \r\n #include <libtar.h>  \r\n #include <iostream>                                                             \r\n #include <fcntl.h>    \r\n     \r\n using namespace std;                               \r\n                                   \r\n int main(){                                                        \r\n     \/\/ tar                         \r\n     if(1){                                                          \r\n         TAR* tar_handle;\r\n         char* tar_fname = \"test.tar\";\r\n         tar_open(&amp;tar_handle, tar_fname, NULL,  O_WRONLY | O_CREAT,  0644,  TAR_GNU);\r\n         char* subfile1 = \".\/sub1\/1.txt\";\r\n         tar_append_file(tar_handle, subfile1,  subfile1);\r\n         char* subfile2 = \"test1.c\";\r\n         tar_append_file(tar_handle, subfile2,  subfile2);\r\n         tar_close(tar_handle);\r\n     }\r\n\r\n     \/\/ untar\r\n     if(0){\r\n         TAR* tar_handle;\r\n         char* tar_fname = \"test.tar\";\r\n         tar_open(&amp;tar_handle, tar_fname, NULL,  O_RDONLY,  0644,  TAR_GNU);\r\n         char* savefold = \"temp\";\r\n         tar_extract_all(tar_handle, \"temp\");\r\n         tar_close(tar_handle);\r\n     }\r\n\r\n     return 0;\r\n }   \r\n\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>libtar is small but effective library, although it has some bugs when dealing with long path. The Steps are following: download libtar-1.2.11 and uncompress it, the main path is \/path\/libtar-1.2.11 build with command &#8220;.\/configure &amp;&amp; make&#8221;, if you want to debug, add &#8220;-g&#8221; for gcc to build. make &#8220;test&#8221; folder &#8220;\/path\/libtar-1.2.11\/test&#8221;. find header file and [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-131","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/emacslisp.com\/index.php?rest_route=\/wp\/v2\/posts\/131","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/emacslisp.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/emacslisp.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/emacslisp.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/emacslisp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=131"}],"version-history":[{"count":3,"href":"http:\/\/emacslisp.com\/index.php?rest_route=\/wp\/v2\/posts\/131\/revisions"}],"predecessor-version":[{"id":134,"href":"http:\/\/emacslisp.com\/index.php?rest_route=\/wp\/v2\/posts\/131\/revisions\/134"}],"wp:attachment":[{"href":"http:\/\/emacslisp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=131"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/emacslisp.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=131"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/emacslisp.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=131"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}