archive_write_set_format_shar.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648
  1. /*-
  2. * Copyright (c) 2003-2007 Tim Kientzle
  3. * Copyright (c) 2008 Joerg Sonnenberger
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
  16. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  17. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  18. * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
  19. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  20. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  21. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  22. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  24. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include "archive_platform.h"
  27. #ifdef HAVE_ERRNO_H
  28. #include <errno.h>
  29. #endif
  30. #include <stdio.h>
  31. #ifdef HAVE_STDLIB_H
  32. #include <stdlib.h>
  33. #endif
  34. #ifdef HAVE_STRING_H
  35. #include <string.h>
  36. #endif
  37. #include "archive.h"
  38. #include "archive_entry.h"
  39. #include "archive_private.h"
  40. #include "archive_write_private.h"
  41. #include "archive_write_set_format_private.h"
  42. struct shar {
  43. int dump;
  44. int end_of_line;
  45. struct archive_entry *entry;
  46. int has_data;
  47. char *last_dir;
  48. /* Line buffer for uuencoded dump format */
  49. char outbuff[45];
  50. size_t outpos;
  51. int wrote_header;
  52. struct archive_string work;
  53. struct archive_string quoted_name;
  54. };
  55. static int archive_write_shar_close(struct archive_write *);
  56. static int archive_write_shar_free(struct archive_write *);
  57. static int archive_write_shar_header(struct archive_write *,
  58. struct archive_entry *);
  59. static ssize_t archive_write_shar_data_sed(struct archive_write *,
  60. const void * buff, size_t);
  61. static ssize_t archive_write_shar_data_uuencode(struct archive_write *,
  62. const void * buff, size_t);
  63. static int archive_write_shar_finish_entry(struct archive_write *);
  64. /*
  65. * Copy the given string to the buffer, quoting all shell meta characters
  66. * found.
  67. */
  68. static void
  69. shar_quote(struct archive_string *buf, const char *str, int in_shell)
  70. {
  71. static const char meta[] = "\n \t'`\";&<>()|*?{}[]\\$!#^~";
  72. size_t len;
  73. while (*str != '\0') {
  74. if ((len = strcspn(str, meta)) != 0) {
  75. archive_strncat(buf, str, len);
  76. str += len;
  77. } else if (*str == '\n') {
  78. if (in_shell)
  79. archive_strcat(buf, "\"\n\"");
  80. else
  81. archive_strcat(buf, "\\n");
  82. ++str;
  83. } else {
  84. archive_strappend_char(buf, '\\');
  85. archive_strappend_char(buf, *str);
  86. ++str;
  87. }
  88. }
  89. }
  90. /*
  91. * Set output format to 'shar' format.
  92. */
  93. int
  94. archive_write_set_format_shar(struct archive *_a)
  95. {
  96. struct archive_write *a = (struct archive_write *)_a;
  97. struct shar *shar;
  98. archive_check_magic(_a, ARCHIVE_WRITE_MAGIC,
  99. ARCHIVE_STATE_NEW, "archive_write_set_format_shar");
  100. /* If someone else was already registered, unregister them. */
  101. if (a->format_free != NULL)
  102. (a->format_free)(a);
  103. shar = calloc(1, sizeof(*shar));
  104. if (shar == NULL) {
  105. archive_set_error(&a->archive, ENOMEM, "Can't allocate shar data");
  106. return (ARCHIVE_FATAL);
  107. }
  108. archive_string_init(&shar->work);
  109. archive_string_init(&shar->quoted_name);
  110. a->format_data = shar;
  111. a->format_name = "shar";
  112. a->format_write_header = archive_write_shar_header;
  113. a->format_close = archive_write_shar_close;
  114. a->format_free = archive_write_shar_free;
  115. a->format_write_data = archive_write_shar_data_sed;
  116. a->format_finish_entry = archive_write_shar_finish_entry;
  117. a->archive.archive_format = ARCHIVE_FORMAT_SHAR_BASE;
  118. a->archive.archive_format_name = "shar";
  119. return (ARCHIVE_OK);
  120. }
  121. /*
  122. * An alternate 'shar' that uses uudecode instead of 'sed' to encode
  123. * file contents and can therefore be used to archive binary files.
  124. * In addition, this variant also attempts to restore ownership, file modes,
  125. * and other extended file information.
  126. */
  127. int
  128. archive_write_set_format_shar_dump(struct archive *_a)
  129. {
  130. struct archive_write *a = (struct archive_write *)_a;
  131. struct shar *shar;
  132. archive_write_set_format_shar(&a->archive);
  133. shar = (struct shar *)a->format_data;
  134. shar->dump = 1;
  135. a->format_write_data = archive_write_shar_data_uuencode;
  136. a->archive.archive_format = ARCHIVE_FORMAT_SHAR_DUMP;
  137. a->archive.archive_format_name = "shar dump";
  138. return (ARCHIVE_OK);
  139. }
  140. static int
  141. archive_write_shar_header(struct archive_write *a, struct archive_entry *entry)
  142. {
  143. const char *linkname;
  144. const char *name;
  145. char *p, *pp;
  146. struct shar *shar;
  147. shar = (struct shar *)a->format_data;
  148. if (!shar->wrote_header) {
  149. archive_strcat(&shar->work, "#!/bin/sh\n");
  150. archive_strcat(&shar->work, "# This is a shell archive\n");
  151. shar->wrote_header = 1;
  152. }
  153. /* Save the entry for the closing. */
  154. archive_entry_free(shar->entry);
  155. shar->entry = archive_entry_clone(entry);
  156. name = archive_entry_pathname(entry);
  157. /* Handle some preparatory issues. */
  158. switch(archive_entry_filetype(entry)) {
  159. case AE_IFREG:
  160. /* Only regular files have non-zero size. */
  161. break;
  162. case AE_IFDIR:
  163. archive_entry_set_size(entry, 0);
  164. /* Don't bother trying to recreate '.' */
  165. if (strcmp(name, ".") == 0 || strcmp(name, "./") == 0)
  166. return (ARCHIVE_OK);
  167. break;
  168. case AE_IFIFO:
  169. case AE_IFCHR:
  170. case AE_IFBLK:
  171. /* All other file types have zero size in the archive. */
  172. archive_entry_set_size(entry, 0);
  173. break;
  174. default:
  175. archive_entry_set_size(entry, 0);
  176. if (archive_entry_hardlink(entry) == NULL &&
  177. archive_entry_symlink(entry) == NULL) {
  178. __archive_write_entry_filetype_unsupported(
  179. &a->archive, entry, "shar");
  180. return (ARCHIVE_WARN);
  181. }
  182. }
  183. archive_string_empty(&shar->quoted_name);
  184. shar_quote(&shar->quoted_name, name, 1);
  185. /* Stock preparation for all file types. */
  186. archive_string_sprintf(&shar->work, "echo x %s\n", shar->quoted_name.s);
  187. if (archive_entry_filetype(entry) != AE_IFDIR) {
  188. /* Try to create the dir. */
  189. p = strdup(name);
  190. if (p == NULL) {
  191. archive_set_error(&a->archive, ENOMEM, "Out of memory");
  192. return (ARCHIVE_FATAL);
  193. }
  194. pp = strrchr(p, '/');
  195. /* If there is a / character, try to create the dir. */
  196. if (pp != NULL) {
  197. *pp = '\0';
  198. /* Try to avoid a lot of redundant mkdir commands. */
  199. if (strcmp(p, ".") == 0) {
  200. /* Don't try to "mkdir ." */
  201. free(p);
  202. } else if (shar->last_dir == NULL) {
  203. archive_strcat(&shar->work, "mkdir -p ");
  204. shar_quote(&shar->work, p, 1);
  205. archive_strcat(&shar->work,
  206. " > /dev/null 2>&1\n");
  207. shar->last_dir = p;
  208. } else if (strcmp(p, shar->last_dir) == 0) {
  209. /* We've already created this exact dir. */
  210. free(p);
  211. } else if (strlen(p) < strlen(shar->last_dir) &&
  212. strncmp(p, shar->last_dir, strlen(p)) == 0) {
  213. /* We've already created a subdir. */
  214. free(p);
  215. } else {
  216. archive_strcat(&shar->work, "mkdir -p ");
  217. shar_quote(&shar->work, p, 1);
  218. archive_strcat(&shar->work,
  219. " > /dev/null 2>&1\n");
  220. shar->last_dir = p;
  221. }
  222. } else {
  223. free(p);
  224. }
  225. }
  226. /* Handle file-type specific issues. */
  227. shar->has_data = 0;
  228. if ((linkname = archive_entry_hardlink(entry)) != NULL) {
  229. archive_strcat(&shar->work, "ln -f ");
  230. shar_quote(&shar->work, linkname, 1);
  231. archive_string_sprintf(&shar->work, " %s\n",
  232. shar->quoted_name.s);
  233. } else if ((linkname = archive_entry_symlink(entry)) != NULL) {
  234. archive_strcat(&shar->work, "ln -fs ");
  235. shar_quote(&shar->work, linkname, 1);
  236. archive_string_sprintf(&shar->work, " %s\n",
  237. shar->quoted_name.s);
  238. } else {
  239. switch(archive_entry_filetype(entry)) {
  240. case AE_IFREG:
  241. if (archive_entry_size(entry) == 0) {
  242. /* More portable than "touch." */
  243. archive_string_sprintf(&shar->work,
  244. "test -e \"%s\" || :> \"%s\"\n",
  245. shar->quoted_name.s, shar->quoted_name.s);
  246. } else {
  247. if (shar->dump) {
  248. unsigned int mode = archive_entry_mode(entry) & 0777;
  249. archive_string_sprintf(&shar->work,
  250. "uudecode -p > %s << 'SHAR_END'\n",
  251. shar->quoted_name.s);
  252. archive_string_sprintf(&shar->work,
  253. "begin %o ", mode);
  254. shar_quote(&shar->work, name, 0);
  255. archive_strcat(&shar->work, "\n");
  256. } else {
  257. archive_string_sprintf(&shar->work,
  258. "sed 's/^X//' > %s << 'SHAR_END'\n",
  259. shar->quoted_name.s);
  260. }
  261. shar->has_data = 1;
  262. shar->end_of_line = 1;
  263. shar->outpos = 0;
  264. }
  265. break;
  266. case AE_IFDIR:
  267. archive_string_sprintf(&shar->work,
  268. "mkdir -p %s > /dev/null 2>&1\n",
  269. shar->quoted_name.s);
  270. /* Record that we just created this directory. */
  271. free(shar->last_dir);
  272. shar->last_dir = strdup(name);
  273. if (shar->last_dir == NULL) {
  274. archive_set_error(&a->archive, ENOMEM, "Out of memory");
  275. return (ARCHIVE_FATAL);
  276. }
  277. /* Trim a trailing '/'. */
  278. pp = strrchr(shar->last_dir, '/');
  279. if (pp != NULL && pp[1] == '\0')
  280. *pp = '\0';
  281. /*
  282. * TODO: Put dir name/mode on a list to be fixed
  283. * up at end of archive.
  284. */
  285. break;
  286. case AE_IFIFO:
  287. archive_string_sprintf(&shar->work,
  288. "mkfifo %s\n", shar->quoted_name.s);
  289. break;
  290. case AE_IFCHR:
  291. archive_string_sprintf(&shar->work,
  292. "mknod %s c %ju %ju\n", shar->quoted_name.s,
  293. (uintmax_t)archive_entry_rdevmajor(entry),
  294. (uintmax_t)archive_entry_rdevminor(entry));
  295. break;
  296. case AE_IFBLK:
  297. archive_string_sprintf(&shar->work,
  298. "mknod %s b %ju %ju\n", shar->quoted_name.s,
  299. (uintmax_t)archive_entry_rdevmajor(entry),
  300. (uintmax_t)archive_entry_rdevminor(entry));
  301. break;
  302. default:
  303. return (ARCHIVE_WARN);
  304. }
  305. }
  306. return (ARCHIVE_OK);
  307. }
  308. static ssize_t
  309. archive_write_shar_data_sed(struct archive_write *a, const void *buff, size_t n)
  310. {
  311. static const size_t ensured = 65533;
  312. struct shar *shar;
  313. const char *src;
  314. char *buf, *buf_end;
  315. int ret;
  316. size_t written = n;
  317. shar = (struct shar *)a->format_data;
  318. if (!shar->has_data || n == 0)
  319. return (0);
  320. src = (const char *)buff;
  321. /*
  322. * ensure is the number of bytes in buffer before expanding the
  323. * current character. Each operation writes the current character
  324. * and optionally the start-of-new-line marker. This can happen
  325. * twice before entering the loop, so make sure three additional
  326. * bytes can be written.
  327. */
  328. if (archive_string_ensure(&shar->work, ensured + 3) == NULL) {
  329. archive_set_error(&a->archive, ENOMEM, "Out of memory");
  330. return (ARCHIVE_FATAL);
  331. }
  332. if (shar->work.length > ensured) {
  333. ret = __archive_write_output(a, shar->work.s,
  334. shar->work.length);
  335. if (ret != ARCHIVE_OK)
  336. return (ARCHIVE_FATAL);
  337. archive_string_empty(&shar->work);
  338. }
  339. buf = shar->work.s + shar->work.length;
  340. buf_end = shar->work.s + ensured;
  341. if (shar->end_of_line) {
  342. *buf++ = 'X';
  343. shar->end_of_line = 0;
  344. }
  345. while (n-- != 0) {
  346. if ((*buf++ = *src++) == '\n') {
  347. if (n == 0)
  348. shar->end_of_line = 1;
  349. else
  350. *buf++ = 'X';
  351. }
  352. if (buf >= buf_end) {
  353. shar->work.length = buf - shar->work.s;
  354. ret = __archive_write_output(a, shar->work.s,
  355. shar->work.length);
  356. if (ret != ARCHIVE_OK)
  357. return (ARCHIVE_FATAL);
  358. archive_string_empty(&shar->work);
  359. buf = shar->work.s;
  360. }
  361. }
  362. shar->work.length = buf - shar->work.s;
  363. return (written);
  364. }
  365. #define UUENC(c) (((c)!=0) ? ((c) & 077) + ' ': '`')
  366. static void
  367. uuencode_group(const char _in[3], char out[4])
  368. {
  369. const unsigned char *in = (const unsigned char *)_in;
  370. int t;
  371. t = (in[0] << 16) | (in[1] << 8) | in[2];
  372. out[0] = UUENC( 0x3f & (t >> 18) );
  373. out[1] = UUENC( 0x3f & (t >> 12) );
  374. out[2] = UUENC( 0x3f & (t >> 6) );
  375. out[3] = UUENC( 0x3f & t );
  376. }
  377. static int
  378. _uuencode_line(struct archive_write *a, struct shar *shar, const char *inbuf, size_t len)
  379. {
  380. char *buf;
  381. size_t alloc_len;
  382. /* len <= 45 -> expanded to 60 + len byte + new line */
  383. alloc_len = shar->work.length + 62;
  384. if (archive_string_ensure(&shar->work, alloc_len) == NULL) {
  385. archive_set_error(&a->archive, ENOMEM, "Out of memory");
  386. return (ARCHIVE_FATAL);
  387. }
  388. buf = shar->work.s + shar->work.length;
  389. *buf++ = UUENC(len);
  390. while (len >= 3) {
  391. uuencode_group(inbuf, buf);
  392. len -= 3;
  393. inbuf += 3;
  394. buf += 4;
  395. }
  396. if (len != 0) {
  397. char tmp_buf[3];
  398. tmp_buf[0] = inbuf[0];
  399. if (len == 1)
  400. tmp_buf[1] = '\0';
  401. else
  402. tmp_buf[1] = inbuf[1];
  403. tmp_buf[2] = '\0';
  404. uuencode_group(tmp_buf, buf);
  405. buf += 4;
  406. }
  407. *buf++ = '\n';
  408. if ((buf - shar->work.s) > (ptrdiff_t)(shar->work.length + 62)) {
  409. archive_set_error(&a->archive,
  410. ARCHIVE_ERRNO_MISC, "Buffer overflow");
  411. return (ARCHIVE_FATAL);
  412. }
  413. shar->work.length = buf - shar->work.s;
  414. return (ARCHIVE_OK);
  415. }
  416. #define uuencode_line(__a, __shar, __inbuf, __len) \
  417. do { \
  418. int r = _uuencode_line(__a, __shar, __inbuf, __len); \
  419. if (r != ARCHIVE_OK) \
  420. return (ARCHIVE_FATAL); \
  421. } while (0)
  422. static ssize_t
  423. archive_write_shar_data_uuencode(struct archive_write *a, const void *buff,
  424. size_t length)
  425. {
  426. struct shar *shar;
  427. const char *src;
  428. size_t n;
  429. int ret;
  430. shar = (struct shar *)a->format_data;
  431. if (!shar->has_data)
  432. return (ARCHIVE_OK);
  433. src = (const char *)buff;
  434. if (shar->outpos != 0) {
  435. n = 45 - shar->outpos;
  436. if (n > length)
  437. n = length;
  438. memcpy(shar->outbuff + shar->outpos, src, n);
  439. if (shar->outpos + n < 45) {
  440. shar->outpos += n;
  441. return length;
  442. }
  443. uuencode_line(a, shar, shar->outbuff, 45);
  444. src += n;
  445. n = length - n;
  446. } else {
  447. n = length;
  448. }
  449. while (n >= 45) {
  450. uuencode_line(a, shar, src, 45);
  451. src += 45;
  452. n -= 45;
  453. if (shar->work.length < 65536)
  454. continue;
  455. ret = __archive_write_output(a, shar->work.s,
  456. shar->work.length);
  457. if (ret != ARCHIVE_OK)
  458. return (ARCHIVE_FATAL);
  459. archive_string_empty(&shar->work);
  460. }
  461. if (n != 0) {
  462. memcpy(shar->outbuff, src, n);
  463. shar->outpos = n;
  464. }
  465. return (length);
  466. }
  467. static int
  468. archive_write_shar_finish_entry(struct archive_write *a)
  469. {
  470. const char *g, *p, *u;
  471. struct shar *shar;
  472. int ret;
  473. shar = (struct shar *)a->format_data;
  474. if (shar->entry == NULL)
  475. return (0);
  476. if (shar->dump) {
  477. /* Finish uuencoded data. */
  478. if (shar->has_data) {
  479. if (shar->outpos > 0)
  480. uuencode_line(a, shar, shar->outbuff,
  481. shar->outpos);
  482. archive_strcat(&shar->work, "`\nend\n");
  483. archive_strcat(&shar->work, "SHAR_END\n");
  484. }
  485. /* Restore file mode, owner, flags. */
  486. /*
  487. * TODO: Don't immediately restore mode for
  488. * directories; defer that to end of script.
  489. */
  490. archive_string_sprintf(&shar->work, "chmod %o ",
  491. (unsigned int)(archive_entry_mode(shar->entry) & 07777));
  492. shar_quote(&shar->work, archive_entry_pathname(shar->entry), 1);
  493. archive_strcat(&shar->work, "\n");
  494. u = archive_entry_uname(shar->entry);
  495. g = archive_entry_gname(shar->entry);
  496. if (u != NULL || g != NULL) {
  497. archive_strcat(&shar->work, "chown ");
  498. if (u != NULL)
  499. shar_quote(&shar->work, u, 1);
  500. if (g != NULL) {
  501. archive_strcat(&shar->work, ":");
  502. shar_quote(&shar->work, g, 1);
  503. }
  504. archive_strcat(&shar->work, " ");
  505. shar_quote(&shar->work,
  506. archive_entry_pathname(shar->entry), 1);
  507. archive_strcat(&shar->work, "\n");
  508. }
  509. if ((p = archive_entry_fflags_text(shar->entry)) != NULL) {
  510. archive_string_sprintf(&shar->work, "chflags %s ", p);
  511. shar_quote(&shar->work,
  512. archive_entry_pathname(shar->entry), 1);
  513. archive_strcat(&shar->work, "\n");
  514. }
  515. /* TODO: restore ACLs */
  516. } else {
  517. if (shar->has_data) {
  518. /* Finish sed-encoded data: ensure last line ends. */
  519. if (!shar->end_of_line)
  520. archive_strappend_char(&shar->work, '\n');
  521. archive_strcat(&shar->work, "SHAR_END\n");
  522. }
  523. }
  524. archive_entry_free(shar->entry);
  525. shar->entry = NULL;
  526. if (shar->work.length < 65536)
  527. return (ARCHIVE_OK);
  528. ret = __archive_write_output(a, shar->work.s, shar->work.length);
  529. if (ret != ARCHIVE_OK)
  530. return (ARCHIVE_FATAL);
  531. archive_string_empty(&shar->work);
  532. return (ARCHIVE_OK);
  533. }
  534. static int
  535. archive_write_shar_close(struct archive_write *a)
  536. {
  537. struct shar *shar;
  538. int ret;
  539. /*
  540. * TODO: Accumulate list of directory names/modes and
  541. * fix them all up at end-of-archive.
  542. */
  543. shar = (struct shar *)a->format_data;
  544. /*
  545. * Only write the end-of-archive markers if the archive was
  546. * actually started. This avoids problems if someone sets
  547. * shar format, then sets another format (which would invoke
  548. * shar_finish to free the format-specific data).
  549. */
  550. if (shar->wrote_header == 0)
  551. return (ARCHIVE_OK);
  552. archive_strcat(&shar->work, "exit\n");
  553. ret = __archive_write_output(a, shar->work.s, shar->work.length);
  554. if (ret != ARCHIVE_OK)
  555. return (ARCHIVE_FATAL);
  556. /* Shar output is never padded. */
  557. archive_write_set_bytes_in_last_block(&a->archive, 1);
  558. /*
  559. * TODO: shar should also suppress padding of
  560. * uncompressed data within gzip/bzip2 streams.
  561. */
  562. return (ARCHIVE_OK);
  563. }
  564. static int
  565. archive_write_shar_free(struct archive_write *a)
  566. {
  567. struct shar *shar;
  568. shar = (struct shar *)a->format_data;
  569. if (shar == NULL)
  570. return (ARCHIVE_OK);
  571. archive_entry_free(shar->entry);
  572. free(shar->last_dir);
  573. archive_string_free(&(shar->work));
  574. archive_string_free(&(shar->quoted_name));
  575. free(shar);
  576. a->format_data = NULL;
  577. return (ARCHIVE_OK);
  578. }