archive_entry.c 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871
  1. /*-
  2. * Copyright (c) 2003-2007 Tim Kientzle
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
  15. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  16. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  17. * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
  18. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  19. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  21. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  23. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include "archive_platform.h"
  26. __FBSDID("$FreeBSD: head/lib/libarchive/archive_entry.c 201096 2009-12-28 02:41:27Z kientzle $");
  27. #ifdef HAVE_SYS_STAT_H
  28. #include <sys/stat.h>
  29. #endif
  30. #ifdef HAVE_SYS_TYPES_H
  31. #include <sys/types.h>
  32. #endif
  33. #if MAJOR_IN_MKDEV
  34. #include <sys/mkdev.h>
  35. #define HAVE_MAJOR
  36. #elif MAJOR_IN_SYSMACROS
  37. #include <sys/sysmacros.h>
  38. #define HAVE_MAJOR
  39. #endif
  40. #ifdef HAVE_ERRNO_H
  41. #include <errno.h>
  42. #endif
  43. #ifdef HAVE_LIMITS_H
  44. #include <limits.h>
  45. #endif
  46. #ifdef HAVE_LINUX_FS_H
  47. #include <linux/fs.h> /* for Linux file flags */
  48. #endif
  49. /*
  50. * Some Linux distributions have both linux/ext2_fs.h and ext2fs/ext2_fs.h.
  51. * As the include guards don't agree, the order of include is important.
  52. */
  53. #ifdef HAVE_LINUX_EXT2_FS_H
  54. #include <linux/ext2_fs.h> /* for Linux file flags */
  55. #endif
  56. #if defined(HAVE_EXT2FS_EXT2_FS_H) && !defined(__CYGWIN__)
  57. #include <ext2fs/ext2_fs.h> /* for Linux file flags */
  58. #endif
  59. #include <stddef.h>
  60. #include <stdio.h>
  61. #ifdef HAVE_STDLIB_H
  62. #include <stdlib.h>
  63. #endif
  64. #ifdef HAVE_STRING_H
  65. #include <string.h>
  66. #endif
  67. #ifdef HAVE_WCHAR_H
  68. #include <wchar.h>
  69. #endif
  70. #include "archive.h"
  71. #include "archive_acl_private.h"
  72. #include "archive_entry.h"
  73. #include "archive_entry_locale.h"
  74. #include "archive_private.h"
  75. #include "archive_entry_private.h"
  76. #if !defined(HAVE_MAJOR) && !defined(major)
  77. /* Replacement for major/minor/makedev. */
  78. #define major(x) ((int)(0x00ff & ((x) >> 8)))
  79. #define minor(x) ((int)(0xffff00ff & (x)))
  80. #define makedev(maj,min) ((0xff00 & ((maj)<<8)) | (0xffff00ff & (min)))
  81. #endif
  82. /* Play games to come up with a suitable makedev() definition. */
  83. #ifdef __QNXNTO__
  84. /* QNX. <sigh> */
  85. #include <sys/netmgr.h>
  86. #define ae_makedev(maj, min) makedev(ND_LOCAL_NODE, (maj), (min))
  87. #elif defined makedev
  88. /* There's a "makedev" macro. */
  89. #define ae_makedev(maj, min) makedev((maj), (min))
  90. #elif defined mkdev || ((defined _WIN32 || defined __WIN32__) && !defined(__CYGWIN__))
  91. /* Windows. <sigh> */
  92. #define ae_makedev(maj, min) mkdev((maj), (min))
  93. #else
  94. /* There's a "makedev" function. */
  95. #define ae_makedev(maj, min) makedev((maj), (min))
  96. #endif
  97. /*
  98. * This adjustment is needed to support the following idiom for adding
  99. * 1000ns to the stored time:
  100. * archive_entry_set_atime(archive_entry_atime(),
  101. * archive_entry_atime_nsec() + 1000)
  102. * The additional if() here compensates for ambiguity in the C standard,
  103. * which permits two possible interpretations of a % b when a is negative.
  104. */
  105. #define FIX_NS(t,ns) \
  106. do { \
  107. t += ns / 1000000000; \
  108. ns %= 1000000000; \
  109. if (ns < 0) { --t; ns += 1000000000; } \
  110. } while (0)
  111. static char * ae_fflagstostr(unsigned long bitset, unsigned long bitclear);
  112. static const wchar_t *ae_wcstofflags(const wchar_t *stringp,
  113. unsigned long *setp, unsigned long *clrp);
  114. static const char *ae_strtofflags(const char *stringp,
  115. unsigned long *setp, unsigned long *clrp);
  116. #ifndef HAVE_WCSCPY
  117. static wchar_t * wcscpy(wchar_t *s1, const wchar_t *s2)
  118. {
  119. wchar_t *dest = s1;
  120. while ((*s1 = *s2) != L'\0')
  121. ++s1, ++s2;
  122. return dest;
  123. }
  124. #endif
  125. #ifndef HAVE_WCSLEN
  126. static size_t wcslen(const wchar_t *s)
  127. {
  128. const wchar_t *p = s;
  129. while (*p != L'\0')
  130. ++p;
  131. return p - s;
  132. }
  133. #endif
  134. #ifndef HAVE_WMEMCMP
  135. /* Good enough for simple equality testing, but not for sorting. */
  136. #define wmemcmp(a,b,i) memcmp((a), (b), (i) * sizeof(wchar_t))
  137. #endif
  138. /****************************************************************************
  139. *
  140. * Public Interface
  141. *
  142. ****************************************************************************/
  143. struct archive_entry *
  144. archive_entry_clear(struct archive_entry *entry)
  145. {
  146. if (entry == NULL)
  147. return (NULL);
  148. archive_mstring_clean(&entry->ae_fflags_text);
  149. archive_mstring_clean(&entry->ae_gname);
  150. archive_mstring_clean(&entry->ae_hardlink);
  151. archive_mstring_clean(&entry->ae_pathname);
  152. archive_mstring_clean(&entry->ae_sourcepath);
  153. archive_mstring_clean(&entry->ae_symlink);
  154. archive_mstring_clean(&entry->ae_uname);
  155. archive_entry_copy_mac_metadata(entry, NULL, 0);
  156. archive_acl_clear(&entry->acl);
  157. archive_entry_xattr_clear(entry);
  158. archive_entry_sparse_clear(entry);
  159. free(entry->stat);
  160. memset(entry, 0, sizeof(*entry));
  161. return entry;
  162. }
  163. struct archive_entry *
  164. archive_entry_clone(struct archive_entry *entry)
  165. {
  166. struct archive_entry *entry2;
  167. struct ae_xattr *xp;
  168. struct ae_sparse *sp;
  169. size_t s;
  170. const void *p;
  171. /* Allocate new structure and copy over all of the fields. */
  172. /* TODO: Should we copy the archive over? Or require a new archive
  173. * as an argument? */
  174. entry2 = archive_entry_new2(entry->archive);
  175. if (entry2 == NULL)
  176. return (NULL);
  177. entry2->ae_stat = entry->ae_stat;
  178. entry2->ae_fflags_set = entry->ae_fflags_set;
  179. entry2->ae_fflags_clear = entry->ae_fflags_clear;
  180. /* TODO: XXX If clone can have a different archive, what do we do here if
  181. * character sets are different? XXX */
  182. archive_mstring_copy(&entry2->ae_fflags_text, &entry->ae_fflags_text);
  183. archive_mstring_copy(&entry2->ae_gname, &entry->ae_gname);
  184. archive_mstring_copy(&entry2->ae_hardlink, &entry->ae_hardlink);
  185. archive_mstring_copy(&entry2->ae_pathname, &entry->ae_pathname);
  186. archive_mstring_copy(&entry2->ae_sourcepath, &entry->ae_sourcepath);
  187. archive_mstring_copy(&entry2->ae_symlink, &entry->ae_symlink);
  188. entry2->ae_set = entry->ae_set;
  189. archive_mstring_copy(&entry2->ae_uname, &entry->ae_uname);
  190. /* Copy encryption status */
  191. entry2->encryption = entry->encryption;
  192. /* Copy ACL data over. */
  193. archive_acl_copy(&entry2->acl, &entry->acl);
  194. /* Copy Mac OS metadata. */
  195. p = archive_entry_mac_metadata(entry, &s);
  196. archive_entry_copy_mac_metadata(entry2, p, s);
  197. /* Copy xattr data over. */
  198. xp = entry->xattr_head;
  199. while (xp != NULL) {
  200. archive_entry_xattr_add_entry(entry2,
  201. xp->name, xp->value, xp->size);
  202. xp = xp->next;
  203. }
  204. /* Copy sparse data over. */
  205. sp = entry->sparse_head;
  206. while (sp != NULL) {
  207. archive_entry_sparse_add_entry(entry2,
  208. sp->offset, sp->length);
  209. sp = sp->next;
  210. }
  211. return (entry2);
  212. }
  213. void
  214. archive_entry_free(struct archive_entry *entry)
  215. {
  216. archive_entry_clear(entry);
  217. free(entry);
  218. }
  219. struct archive_entry *
  220. archive_entry_new(void)
  221. {
  222. return archive_entry_new2(NULL);
  223. }
  224. struct archive_entry *
  225. archive_entry_new2(struct archive *a)
  226. {
  227. struct archive_entry *entry;
  228. entry = (struct archive_entry *)malloc(sizeof(*entry));
  229. if (entry == NULL)
  230. return (NULL);
  231. memset(entry, 0, sizeof(*entry));
  232. entry->archive = a;
  233. return (entry);
  234. }
  235. /*
  236. * Functions for reading fields from an archive_entry.
  237. */
  238. time_t
  239. archive_entry_atime(struct archive_entry *entry)
  240. {
  241. return (entry->ae_stat.aest_atime);
  242. }
  243. long
  244. archive_entry_atime_nsec(struct archive_entry *entry)
  245. {
  246. return (entry->ae_stat.aest_atime_nsec);
  247. }
  248. int
  249. archive_entry_atime_is_set(struct archive_entry *entry)
  250. {
  251. return (entry->ae_set & AE_SET_ATIME);
  252. }
  253. time_t
  254. archive_entry_birthtime(struct archive_entry *entry)
  255. {
  256. return (entry->ae_stat.aest_birthtime);
  257. }
  258. long
  259. archive_entry_birthtime_nsec(struct archive_entry *entry)
  260. {
  261. return (entry->ae_stat.aest_birthtime_nsec);
  262. }
  263. int
  264. archive_entry_birthtime_is_set(struct archive_entry *entry)
  265. {
  266. return (entry->ae_set & AE_SET_BIRTHTIME);
  267. }
  268. time_t
  269. archive_entry_ctime(struct archive_entry *entry)
  270. {
  271. return (entry->ae_stat.aest_ctime);
  272. }
  273. int
  274. archive_entry_ctime_is_set(struct archive_entry *entry)
  275. {
  276. return (entry->ae_set & AE_SET_CTIME);
  277. }
  278. long
  279. archive_entry_ctime_nsec(struct archive_entry *entry)
  280. {
  281. return (entry->ae_stat.aest_ctime_nsec);
  282. }
  283. dev_t
  284. archive_entry_dev(struct archive_entry *entry)
  285. {
  286. if (entry->ae_stat.aest_dev_is_broken_down)
  287. return ae_makedev(entry->ae_stat.aest_devmajor,
  288. entry->ae_stat.aest_devminor);
  289. else
  290. return (entry->ae_stat.aest_dev);
  291. }
  292. int
  293. archive_entry_dev_is_set(struct archive_entry *entry)
  294. {
  295. return (entry->ae_set & AE_SET_DEV);
  296. }
  297. dev_t
  298. archive_entry_devmajor(struct archive_entry *entry)
  299. {
  300. if (entry->ae_stat.aest_dev_is_broken_down)
  301. return (entry->ae_stat.aest_devmajor);
  302. else
  303. return major(entry->ae_stat.aest_dev);
  304. }
  305. dev_t
  306. archive_entry_devminor(struct archive_entry *entry)
  307. {
  308. if (entry->ae_stat.aest_dev_is_broken_down)
  309. return (entry->ae_stat.aest_devminor);
  310. else
  311. return minor(entry->ae_stat.aest_dev);
  312. }
  313. mode_t
  314. archive_entry_filetype(struct archive_entry *entry)
  315. {
  316. return (AE_IFMT & entry->acl.mode);
  317. }
  318. void
  319. archive_entry_fflags(struct archive_entry *entry,
  320. unsigned long *set, unsigned long *clear)
  321. {
  322. *set = entry->ae_fflags_set;
  323. *clear = entry->ae_fflags_clear;
  324. }
  325. /*
  326. * Note: if text was provided, this just returns that text. If you
  327. * really need the text to be rebuilt in a canonical form, set the
  328. * text, ask for the bitmaps, then set the bitmaps. (Setting the
  329. * bitmaps clears any stored text.) This design is deliberate: if
  330. * we're editing archives, we don't want to discard flags just because
  331. * they aren't supported on the current system. The bitmap<->text
  332. * conversions are platform-specific (see below).
  333. */
  334. const char *
  335. archive_entry_fflags_text(struct archive_entry *entry)
  336. {
  337. const char *f;
  338. char *p;
  339. if (archive_mstring_get_mbs(entry->archive,
  340. &entry->ae_fflags_text, &f) == 0) {
  341. if (f != NULL)
  342. return (f);
  343. } else if (errno == ENOMEM)
  344. __archive_errx(1, "No memory");
  345. if (entry->ae_fflags_set == 0 && entry->ae_fflags_clear == 0)
  346. return (NULL);
  347. p = ae_fflagstostr(entry->ae_fflags_set, entry->ae_fflags_clear);
  348. if (p == NULL)
  349. return (NULL);
  350. archive_mstring_copy_mbs(&entry->ae_fflags_text, p);
  351. free(p);
  352. if (archive_mstring_get_mbs(entry->archive,
  353. &entry->ae_fflags_text, &f) == 0)
  354. return (f);
  355. if (errno == ENOMEM)
  356. __archive_errx(1, "No memory");
  357. return (NULL);
  358. }
  359. int64_t
  360. archive_entry_gid(struct archive_entry *entry)
  361. {
  362. return (entry->ae_stat.aest_gid);
  363. }
  364. const char *
  365. archive_entry_gname(struct archive_entry *entry)
  366. {
  367. const char *p;
  368. if (archive_mstring_get_mbs(entry->archive, &entry->ae_gname, &p) == 0)
  369. return (p);
  370. if (errno == ENOMEM)
  371. __archive_errx(1, "No memory");
  372. return (NULL);
  373. }
  374. const char *
  375. archive_entry_gname_utf8(struct archive_entry *entry)
  376. {
  377. const char *p;
  378. if (archive_mstring_get_utf8(entry->archive, &entry->ae_gname, &p) == 0)
  379. return (p);
  380. if (errno == ENOMEM)
  381. __archive_errx(1, "No memory");
  382. return (NULL);
  383. }
  384. const wchar_t *
  385. archive_entry_gname_w(struct archive_entry *entry)
  386. {
  387. const wchar_t *p;
  388. if (archive_mstring_get_wcs(entry->archive, &entry->ae_gname, &p) == 0)
  389. return (p);
  390. if (errno == ENOMEM)
  391. __archive_errx(1, "No memory");
  392. return (NULL);
  393. }
  394. int
  395. _archive_entry_gname_l(struct archive_entry *entry,
  396. const char **p, size_t *len, struct archive_string_conv *sc)
  397. {
  398. return (archive_mstring_get_mbs_l(&entry->ae_gname, p, len, sc));
  399. }
  400. const char *
  401. archive_entry_hardlink(struct archive_entry *entry)
  402. {
  403. const char *p;
  404. if ((entry->ae_set & AE_SET_HARDLINK) == 0)
  405. return (NULL);
  406. if (archive_mstring_get_mbs(
  407. entry->archive, &entry->ae_hardlink, &p) == 0)
  408. return (p);
  409. if (errno == ENOMEM)
  410. __archive_errx(1, "No memory");
  411. return (NULL);
  412. }
  413. const char *
  414. archive_entry_hardlink_utf8(struct archive_entry *entry)
  415. {
  416. const char *p;
  417. if ((entry->ae_set & AE_SET_HARDLINK) == 0)
  418. return (NULL);
  419. if (archive_mstring_get_utf8(
  420. entry->archive, &entry->ae_hardlink, &p) == 0)
  421. return (p);
  422. if (errno == ENOMEM)
  423. __archive_errx(1, "No memory");
  424. return (NULL);
  425. }
  426. const wchar_t *
  427. archive_entry_hardlink_w(struct archive_entry *entry)
  428. {
  429. const wchar_t *p;
  430. if ((entry->ae_set & AE_SET_HARDLINK) == 0)
  431. return (NULL);
  432. if (archive_mstring_get_wcs(
  433. entry->archive, &entry->ae_hardlink, &p) == 0)
  434. return (p);
  435. if (errno == ENOMEM)
  436. __archive_errx(1, "No memory");
  437. return (NULL);
  438. }
  439. int
  440. _archive_entry_hardlink_l(struct archive_entry *entry,
  441. const char **p, size_t *len, struct archive_string_conv *sc)
  442. {
  443. if ((entry->ae_set & AE_SET_HARDLINK) == 0) {
  444. *p = NULL;
  445. *len = 0;
  446. return (0);
  447. }
  448. return (archive_mstring_get_mbs_l(&entry->ae_hardlink, p, len, sc));
  449. }
  450. int64_t
  451. archive_entry_ino(struct archive_entry *entry)
  452. {
  453. return (entry->ae_stat.aest_ino);
  454. }
  455. int
  456. archive_entry_ino_is_set(struct archive_entry *entry)
  457. {
  458. return (entry->ae_set & AE_SET_INO);
  459. }
  460. int64_t
  461. archive_entry_ino64(struct archive_entry *entry)
  462. {
  463. return (entry->ae_stat.aest_ino);
  464. }
  465. mode_t
  466. archive_entry_mode(struct archive_entry *entry)
  467. {
  468. return (entry->acl.mode);
  469. }
  470. time_t
  471. archive_entry_mtime(struct archive_entry *entry)
  472. {
  473. return (entry->ae_stat.aest_mtime);
  474. }
  475. long
  476. archive_entry_mtime_nsec(struct archive_entry *entry)
  477. {
  478. return (entry->ae_stat.aest_mtime_nsec);
  479. }
  480. int
  481. archive_entry_mtime_is_set(struct archive_entry *entry)
  482. {
  483. return (entry->ae_set & AE_SET_MTIME);
  484. }
  485. unsigned int
  486. archive_entry_nlink(struct archive_entry *entry)
  487. {
  488. return (entry->ae_stat.aest_nlink);
  489. }
  490. const char *
  491. archive_entry_pathname(struct archive_entry *entry)
  492. {
  493. const char *p;
  494. if (archive_mstring_get_mbs(
  495. entry->archive, &entry->ae_pathname, &p) == 0)
  496. return (p);
  497. if (errno == ENOMEM)
  498. __archive_errx(1, "No memory");
  499. return (NULL);
  500. }
  501. const char *
  502. archive_entry_pathname_utf8(struct archive_entry *entry)
  503. {
  504. const char *p;
  505. if (archive_mstring_get_utf8(
  506. entry->archive, &entry->ae_pathname, &p) == 0)
  507. return (p);
  508. if (errno == ENOMEM)
  509. __archive_errx(1, "No memory");
  510. return (NULL);
  511. }
  512. const wchar_t *
  513. archive_entry_pathname_w(struct archive_entry *entry)
  514. {
  515. const wchar_t *p;
  516. if (archive_mstring_get_wcs(
  517. entry->archive, &entry->ae_pathname, &p) == 0)
  518. return (p);
  519. if (errno == ENOMEM)
  520. __archive_errx(1, "No memory");
  521. return (NULL);
  522. }
  523. int
  524. _archive_entry_pathname_l(struct archive_entry *entry,
  525. const char **p, size_t *len, struct archive_string_conv *sc)
  526. {
  527. return (archive_mstring_get_mbs_l(&entry->ae_pathname, p, len, sc));
  528. }
  529. mode_t
  530. archive_entry_perm(struct archive_entry *entry)
  531. {
  532. return (~AE_IFMT & entry->acl.mode);
  533. }
  534. dev_t
  535. archive_entry_rdev(struct archive_entry *entry)
  536. {
  537. if (entry->ae_stat.aest_rdev_is_broken_down)
  538. return ae_makedev(entry->ae_stat.aest_rdevmajor,
  539. entry->ae_stat.aest_rdevminor);
  540. else
  541. return (entry->ae_stat.aest_rdev);
  542. }
  543. dev_t
  544. archive_entry_rdevmajor(struct archive_entry *entry)
  545. {
  546. if (entry->ae_stat.aest_rdev_is_broken_down)
  547. return (entry->ae_stat.aest_rdevmajor);
  548. else
  549. return major(entry->ae_stat.aest_rdev);
  550. }
  551. dev_t
  552. archive_entry_rdevminor(struct archive_entry *entry)
  553. {
  554. if (entry->ae_stat.aest_rdev_is_broken_down)
  555. return (entry->ae_stat.aest_rdevminor);
  556. else
  557. return minor(entry->ae_stat.aest_rdev);
  558. }
  559. int64_t
  560. archive_entry_size(struct archive_entry *entry)
  561. {
  562. return (entry->ae_stat.aest_size);
  563. }
  564. int
  565. archive_entry_size_is_set(struct archive_entry *entry)
  566. {
  567. return (entry->ae_set & AE_SET_SIZE);
  568. }
  569. const char *
  570. archive_entry_sourcepath(struct archive_entry *entry)
  571. {
  572. const char *p;
  573. if (archive_mstring_get_mbs(
  574. entry->archive, &entry->ae_sourcepath, &p) == 0)
  575. return (p);
  576. if (errno == ENOMEM)
  577. __archive_errx(1, "No memory");
  578. return (NULL);
  579. }
  580. const wchar_t *
  581. archive_entry_sourcepath_w(struct archive_entry *entry)
  582. {
  583. const wchar_t *p;
  584. if (archive_mstring_get_wcs(
  585. entry->archive, &entry->ae_sourcepath, &p) == 0)
  586. return (p);
  587. return (NULL);
  588. }
  589. const char *
  590. archive_entry_symlink(struct archive_entry *entry)
  591. {
  592. const char *p;
  593. if ((entry->ae_set & AE_SET_SYMLINK) == 0)
  594. return (NULL);
  595. if (archive_mstring_get_mbs(
  596. entry->archive, &entry->ae_symlink, &p) == 0)
  597. return (p);
  598. if (errno == ENOMEM)
  599. __archive_errx(1, "No memory");
  600. return (NULL);
  601. }
  602. const char *
  603. archive_entry_symlink_utf8(struct archive_entry *entry)
  604. {
  605. const char *p;
  606. if ((entry->ae_set & AE_SET_SYMLINK) == 0)
  607. return (NULL);
  608. if (archive_mstring_get_utf8(
  609. entry->archive, &entry->ae_symlink, &p) == 0)
  610. return (p);
  611. if (errno == ENOMEM)
  612. __archive_errx(1, "No memory");
  613. return (NULL);
  614. }
  615. const wchar_t *
  616. archive_entry_symlink_w(struct archive_entry *entry)
  617. {
  618. const wchar_t *p;
  619. if ((entry->ae_set & AE_SET_SYMLINK) == 0)
  620. return (NULL);
  621. if (archive_mstring_get_wcs(
  622. entry->archive, &entry->ae_symlink, &p) == 0)
  623. return (p);
  624. if (errno == ENOMEM)
  625. __archive_errx(1, "No memory");
  626. return (NULL);
  627. }
  628. int
  629. _archive_entry_symlink_l(struct archive_entry *entry,
  630. const char **p, size_t *len, struct archive_string_conv *sc)
  631. {
  632. if ((entry->ae_set & AE_SET_SYMLINK) == 0) {
  633. *p = NULL;
  634. *len = 0;
  635. return (0);
  636. }
  637. return (archive_mstring_get_mbs_l( &entry->ae_symlink, p, len, sc));
  638. }
  639. int64_t
  640. archive_entry_uid(struct archive_entry *entry)
  641. {
  642. return (entry->ae_stat.aest_uid);
  643. }
  644. const char *
  645. archive_entry_uname(struct archive_entry *entry)
  646. {
  647. const char *p;
  648. if (archive_mstring_get_mbs(entry->archive, &entry->ae_uname, &p) == 0)
  649. return (p);
  650. if (errno == ENOMEM)
  651. __archive_errx(1, "No memory");
  652. return (NULL);
  653. }
  654. const char *
  655. archive_entry_uname_utf8(struct archive_entry *entry)
  656. {
  657. const char *p;
  658. if (archive_mstring_get_utf8(entry->archive, &entry->ae_uname, &p) == 0)
  659. return (p);
  660. if (errno == ENOMEM)
  661. __archive_errx(1, "No memory");
  662. return (NULL);
  663. }
  664. const wchar_t *
  665. archive_entry_uname_w(struct archive_entry *entry)
  666. {
  667. const wchar_t *p;
  668. if (archive_mstring_get_wcs(entry->archive, &entry->ae_uname, &p) == 0)
  669. return (p);
  670. if (errno == ENOMEM)
  671. __archive_errx(1, "No memory");
  672. return (NULL);
  673. }
  674. int
  675. _archive_entry_uname_l(struct archive_entry *entry,
  676. const char **p, size_t *len, struct archive_string_conv *sc)
  677. {
  678. return (archive_mstring_get_mbs_l(&entry->ae_uname, p, len, sc));
  679. }
  680. int
  681. archive_entry_is_data_encrypted(struct archive_entry *entry)
  682. {
  683. return ((entry->encryption & AE_ENCRYPTION_DATA) == AE_ENCRYPTION_DATA);
  684. }
  685. int
  686. archive_entry_is_metadata_encrypted(struct archive_entry *entry)
  687. {
  688. return ((entry->encryption & AE_ENCRYPTION_METADATA) == AE_ENCRYPTION_METADATA);
  689. }
  690. int
  691. archive_entry_is_encrypted(struct archive_entry *entry)
  692. {
  693. return (entry->encryption & (AE_ENCRYPTION_DATA|AE_ENCRYPTION_METADATA));
  694. }
  695. /*
  696. * Functions to set archive_entry properties.
  697. */
  698. void
  699. archive_entry_set_filetype(struct archive_entry *entry, unsigned int type)
  700. {
  701. entry->stat_valid = 0;
  702. entry->acl.mode &= ~AE_IFMT;
  703. entry->acl.mode |= AE_IFMT & type;
  704. }
  705. void
  706. archive_entry_set_fflags(struct archive_entry *entry,
  707. unsigned long set, unsigned long clear)
  708. {
  709. archive_mstring_clean(&entry->ae_fflags_text);
  710. entry->ae_fflags_set = set;
  711. entry->ae_fflags_clear = clear;
  712. }
  713. const char *
  714. archive_entry_copy_fflags_text(struct archive_entry *entry,
  715. const char *flags)
  716. {
  717. archive_mstring_copy_mbs(&entry->ae_fflags_text, flags);
  718. return (ae_strtofflags(flags,
  719. &entry->ae_fflags_set, &entry->ae_fflags_clear));
  720. }
  721. const wchar_t *
  722. archive_entry_copy_fflags_text_w(struct archive_entry *entry,
  723. const wchar_t *flags)
  724. {
  725. archive_mstring_copy_wcs(&entry->ae_fflags_text, flags);
  726. return (ae_wcstofflags(flags,
  727. &entry->ae_fflags_set, &entry->ae_fflags_clear));
  728. }
  729. void
  730. archive_entry_set_gid(struct archive_entry *entry, int64_t g)
  731. {
  732. entry->stat_valid = 0;
  733. entry->ae_stat.aest_gid = g;
  734. }
  735. void
  736. archive_entry_set_gname(struct archive_entry *entry, const char *name)
  737. {
  738. archive_mstring_copy_mbs(&entry->ae_gname, name);
  739. }
  740. void
  741. archive_entry_set_gname_utf8(struct archive_entry *entry, const char *name)
  742. {
  743. archive_mstring_copy_utf8(&entry->ae_gname, name);
  744. }
  745. void
  746. archive_entry_copy_gname(struct archive_entry *entry, const char *name)
  747. {
  748. archive_mstring_copy_mbs(&entry->ae_gname, name);
  749. }
  750. void
  751. archive_entry_copy_gname_w(struct archive_entry *entry, const wchar_t *name)
  752. {
  753. archive_mstring_copy_wcs(&entry->ae_gname, name);
  754. }
  755. int
  756. archive_entry_update_gname_utf8(struct archive_entry *entry, const char *name)
  757. {
  758. if (archive_mstring_update_utf8(entry->archive,
  759. &entry->ae_gname, name) == 0)
  760. return (1);
  761. if (errno == ENOMEM)
  762. __archive_errx(1, "No memory");
  763. return (0);
  764. }
  765. int
  766. _archive_entry_copy_gname_l(struct archive_entry *entry,
  767. const char *name, size_t len, struct archive_string_conv *sc)
  768. {
  769. return (archive_mstring_copy_mbs_len_l(&entry->ae_gname, name, len, sc));
  770. }
  771. void
  772. archive_entry_set_ino(struct archive_entry *entry, int64_t ino)
  773. {
  774. entry->stat_valid = 0;
  775. entry->ae_set |= AE_SET_INO;
  776. entry->ae_stat.aest_ino = ino;
  777. }
  778. void
  779. archive_entry_set_ino64(struct archive_entry *entry, int64_t ino)
  780. {
  781. entry->stat_valid = 0;
  782. entry->ae_set |= AE_SET_INO;
  783. entry->ae_stat.aest_ino = ino;
  784. }
  785. void
  786. archive_entry_set_hardlink(struct archive_entry *entry, const char *target)
  787. {
  788. archive_mstring_copy_mbs(&entry->ae_hardlink, target);
  789. if (target != NULL)
  790. entry->ae_set |= AE_SET_HARDLINK;
  791. else
  792. entry->ae_set &= ~AE_SET_HARDLINK;
  793. }
  794. void
  795. archive_entry_set_hardlink_utf8(struct archive_entry *entry, const char *target)
  796. {
  797. archive_mstring_copy_utf8(&entry->ae_hardlink, target);
  798. if (target != NULL)
  799. entry->ae_set |= AE_SET_HARDLINK;
  800. else
  801. entry->ae_set &= ~AE_SET_HARDLINK;
  802. }
  803. void
  804. archive_entry_copy_hardlink(struct archive_entry *entry, const char *target)
  805. {
  806. archive_mstring_copy_mbs(&entry->ae_hardlink, target);
  807. if (target != NULL)
  808. entry->ae_set |= AE_SET_HARDLINK;
  809. else
  810. entry->ae_set &= ~AE_SET_HARDLINK;
  811. }
  812. void
  813. archive_entry_copy_hardlink_w(struct archive_entry *entry, const wchar_t *target)
  814. {
  815. archive_mstring_copy_wcs(&entry->ae_hardlink, target);
  816. if (target != NULL)
  817. entry->ae_set |= AE_SET_HARDLINK;
  818. else
  819. entry->ae_set &= ~AE_SET_HARDLINK;
  820. }
  821. int
  822. archive_entry_update_hardlink_utf8(struct archive_entry *entry, const char *target)
  823. {
  824. if (target != NULL)
  825. entry->ae_set |= AE_SET_HARDLINK;
  826. else
  827. entry->ae_set &= ~AE_SET_HARDLINK;
  828. if (archive_mstring_update_utf8(entry->archive,
  829. &entry->ae_hardlink, target) == 0)
  830. return (1);
  831. if (errno == ENOMEM)
  832. __archive_errx(1, "No memory");
  833. return (0);
  834. }
  835. int
  836. _archive_entry_copy_hardlink_l(struct archive_entry *entry,
  837. const char *target, size_t len, struct archive_string_conv *sc)
  838. {
  839. int r;
  840. r = archive_mstring_copy_mbs_len_l(&entry->ae_hardlink,
  841. target, len, sc);
  842. if (target != NULL && r == 0)
  843. entry->ae_set |= AE_SET_HARDLINK;
  844. else
  845. entry->ae_set &= ~AE_SET_HARDLINK;
  846. return (r);
  847. }
  848. void
  849. archive_entry_set_atime(struct archive_entry *entry, time_t t, long ns)
  850. {
  851. FIX_NS(t, ns);
  852. entry->stat_valid = 0;
  853. entry->ae_set |= AE_SET_ATIME;
  854. entry->ae_stat.aest_atime = t;
  855. entry->ae_stat.aest_atime_nsec = ns;
  856. }
  857. void
  858. archive_entry_unset_atime(struct archive_entry *entry)
  859. {
  860. archive_entry_set_atime(entry, 0, 0);
  861. entry->ae_set &= ~AE_SET_ATIME;
  862. }
  863. void
  864. archive_entry_set_birthtime(struct archive_entry *entry, time_t t, long ns)
  865. {
  866. FIX_NS(t, ns);
  867. entry->stat_valid = 0;
  868. entry->ae_set |= AE_SET_BIRTHTIME;
  869. entry->ae_stat.aest_birthtime = t;
  870. entry->ae_stat.aest_birthtime_nsec = ns;
  871. }
  872. void
  873. archive_entry_unset_birthtime(struct archive_entry *entry)
  874. {
  875. archive_entry_set_birthtime(entry, 0, 0);
  876. entry->ae_set &= ~AE_SET_BIRTHTIME;
  877. }
  878. void
  879. archive_entry_set_ctime(struct archive_entry *entry, time_t t, long ns)
  880. {
  881. FIX_NS(t, ns);
  882. entry->stat_valid = 0;
  883. entry->ae_set |= AE_SET_CTIME;
  884. entry->ae_stat.aest_ctime = t;
  885. entry->ae_stat.aest_ctime_nsec = ns;
  886. }
  887. void
  888. archive_entry_unset_ctime(struct archive_entry *entry)
  889. {
  890. archive_entry_set_ctime(entry, 0, 0);
  891. entry->ae_set &= ~AE_SET_CTIME;
  892. }
  893. void
  894. archive_entry_set_dev(struct archive_entry *entry, dev_t d)
  895. {
  896. entry->stat_valid = 0;
  897. entry->ae_set |= AE_SET_DEV;
  898. entry->ae_stat.aest_dev_is_broken_down = 0;
  899. entry->ae_stat.aest_dev = d;
  900. }
  901. void
  902. archive_entry_set_devmajor(struct archive_entry *entry, dev_t m)
  903. {
  904. entry->stat_valid = 0;
  905. entry->ae_set |= AE_SET_DEV;
  906. entry->ae_stat.aest_dev_is_broken_down = 1;
  907. entry->ae_stat.aest_devmajor = m;
  908. }
  909. void
  910. archive_entry_set_devminor(struct archive_entry *entry, dev_t m)
  911. {
  912. entry->stat_valid = 0;
  913. entry->ae_set |= AE_SET_DEV;
  914. entry->ae_stat.aest_dev_is_broken_down = 1;
  915. entry->ae_stat.aest_devminor = m;
  916. }
  917. /* Set symlink if symlink is already set, else set hardlink. */
  918. void
  919. archive_entry_set_link(struct archive_entry *entry, const char *target)
  920. {
  921. if (entry->ae_set & AE_SET_SYMLINK)
  922. archive_mstring_copy_mbs(&entry->ae_symlink, target);
  923. else
  924. archive_mstring_copy_mbs(&entry->ae_hardlink, target);
  925. }
  926. void
  927. archive_entry_set_link_utf8(struct archive_entry *entry, const char *target)
  928. {
  929. if (entry->ae_set & AE_SET_SYMLINK)
  930. archive_mstring_copy_utf8(&entry->ae_symlink, target);
  931. else
  932. archive_mstring_copy_utf8(&entry->ae_hardlink, target);
  933. }
  934. /* Set symlink if symlink is already set, else set hardlink. */
  935. void
  936. archive_entry_copy_link(struct archive_entry *entry, const char *target)
  937. {
  938. if (entry->ae_set & AE_SET_SYMLINK)
  939. archive_mstring_copy_mbs(&entry->ae_symlink, target);
  940. else
  941. archive_mstring_copy_mbs(&entry->ae_hardlink, target);
  942. }
  943. /* Set symlink if symlink is already set, else set hardlink. */
  944. void
  945. archive_entry_copy_link_w(struct archive_entry *entry, const wchar_t *target)
  946. {
  947. if (entry->ae_set & AE_SET_SYMLINK)
  948. archive_mstring_copy_wcs(&entry->ae_symlink, target);
  949. else
  950. archive_mstring_copy_wcs(&entry->ae_hardlink, target);
  951. }
  952. int
  953. archive_entry_update_link_utf8(struct archive_entry *entry, const char *target)
  954. {
  955. int r;
  956. if (entry->ae_set & AE_SET_SYMLINK)
  957. r = archive_mstring_update_utf8(entry->archive,
  958. &entry->ae_symlink, target);
  959. else
  960. r = archive_mstring_update_utf8(entry->archive,
  961. &entry->ae_hardlink, target);
  962. if (r == 0)
  963. return (1);
  964. if (errno == ENOMEM)
  965. __archive_errx(1, "No memory");
  966. return (0);
  967. }
  968. int
  969. _archive_entry_copy_link_l(struct archive_entry *entry,
  970. const char *target, size_t len, struct archive_string_conv *sc)
  971. {
  972. int r;
  973. if (entry->ae_set & AE_SET_SYMLINK)
  974. r = archive_mstring_copy_mbs_len_l(&entry->ae_symlink,
  975. target, len, sc);
  976. else
  977. r = archive_mstring_copy_mbs_len_l(&entry->ae_hardlink,
  978. target, len, sc);
  979. return (r);
  980. }
  981. void
  982. archive_entry_set_mode(struct archive_entry *entry, mode_t m)
  983. {
  984. entry->stat_valid = 0;
  985. entry->acl.mode = m;
  986. }
  987. void
  988. archive_entry_set_mtime(struct archive_entry *entry, time_t t, long ns)
  989. {
  990. FIX_NS(t, ns);
  991. entry->stat_valid = 0;
  992. entry->ae_set |= AE_SET_MTIME;
  993. entry->ae_stat.aest_mtime = t;
  994. entry->ae_stat.aest_mtime_nsec = ns;
  995. }
  996. void
  997. archive_entry_unset_mtime(struct archive_entry *entry)
  998. {
  999. archive_entry_set_mtime(entry, 0, 0);
  1000. entry->ae_set &= ~AE_SET_MTIME;
  1001. }
  1002. void
  1003. archive_entry_set_nlink(struct archive_entry *entry, unsigned int nlink)
  1004. {
  1005. entry->stat_valid = 0;
  1006. entry->ae_stat.aest_nlink = nlink;
  1007. }
  1008. void
  1009. archive_entry_set_pathname(struct archive_entry *entry, const char *name)
  1010. {
  1011. archive_mstring_copy_mbs(&entry->ae_pathname, name);
  1012. }
  1013. void
  1014. archive_entry_set_pathname_utf8(struct archive_entry *entry, const char *name)
  1015. {
  1016. archive_mstring_copy_utf8(&entry->ae_pathname, name);
  1017. }
  1018. void
  1019. archive_entry_copy_pathname(struct archive_entry *entry, const char *name)
  1020. {
  1021. archive_mstring_copy_mbs(&entry->ae_pathname, name);
  1022. }
  1023. void
  1024. archive_entry_copy_pathname_w(struct archive_entry *entry, const wchar_t *name)
  1025. {
  1026. archive_mstring_copy_wcs(&entry->ae_pathname, name);
  1027. }
  1028. int
  1029. archive_entry_update_pathname_utf8(struct archive_entry *entry, const char *name)
  1030. {
  1031. if (archive_mstring_update_utf8(entry->archive,
  1032. &entry->ae_pathname, name) == 0)
  1033. return (1);
  1034. if (errno == ENOMEM)
  1035. __archive_errx(1, "No memory");
  1036. return (0);
  1037. }
  1038. int
  1039. _archive_entry_copy_pathname_l(struct archive_entry *entry,
  1040. const char *name, size_t len, struct archive_string_conv *sc)
  1041. {
  1042. return (archive_mstring_copy_mbs_len_l(&entry->ae_pathname,
  1043. name, len, sc));
  1044. }
  1045. void
  1046. archive_entry_set_perm(struct archive_entry *entry, mode_t p)
  1047. {
  1048. entry->stat_valid = 0;
  1049. entry->acl.mode &= AE_IFMT;
  1050. entry->acl.mode |= ~AE_IFMT & p;
  1051. }
  1052. void
  1053. archive_entry_set_rdev(struct archive_entry *entry, dev_t m)
  1054. {
  1055. entry->stat_valid = 0;
  1056. entry->ae_stat.aest_rdev = m;
  1057. entry->ae_stat.aest_rdev_is_broken_down = 0;
  1058. }
  1059. void
  1060. archive_entry_set_rdevmajor(struct archive_entry *entry, dev_t m)
  1061. {
  1062. entry->stat_valid = 0;
  1063. entry->ae_stat.aest_rdev_is_broken_down = 1;
  1064. entry->ae_stat.aest_rdevmajor = m;
  1065. }
  1066. void
  1067. archive_entry_set_rdevminor(struct archive_entry *entry, dev_t m)
  1068. {
  1069. entry->stat_valid = 0;
  1070. entry->ae_stat.aest_rdev_is_broken_down = 1;
  1071. entry->ae_stat.aest_rdevminor = m;
  1072. }
  1073. void
  1074. archive_entry_set_size(struct archive_entry *entry, int64_t s)
  1075. {
  1076. entry->stat_valid = 0;
  1077. entry->ae_stat.aest_size = s;
  1078. entry->ae_set |= AE_SET_SIZE;
  1079. }
  1080. void
  1081. archive_entry_unset_size(struct archive_entry *entry)
  1082. {
  1083. archive_entry_set_size(entry, 0);
  1084. entry->ae_set &= ~AE_SET_SIZE;
  1085. }
  1086. void
  1087. archive_entry_copy_sourcepath(struct archive_entry *entry, const char *path)
  1088. {
  1089. archive_mstring_copy_mbs(&entry->ae_sourcepath, path);
  1090. }
  1091. void
  1092. archive_entry_copy_sourcepath_w(struct archive_entry *entry, const wchar_t *path)
  1093. {
  1094. archive_mstring_copy_wcs(&entry->ae_sourcepath, path);
  1095. }
  1096. void
  1097. archive_entry_set_symlink(struct archive_entry *entry, const char *linkname)
  1098. {
  1099. archive_mstring_copy_mbs(&entry->ae_symlink, linkname);
  1100. if (linkname != NULL)
  1101. entry->ae_set |= AE_SET_SYMLINK;
  1102. else
  1103. entry->ae_set &= ~AE_SET_SYMLINK;
  1104. }
  1105. void
  1106. archive_entry_set_symlink_utf8(struct archive_entry *entry, const char *linkname)
  1107. {
  1108. archive_mstring_copy_utf8(&entry->ae_symlink, linkname);
  1109. if (linkname != NULL)
  1110. entry->ae_set |= AE_SET_SYMLINK;
  1111. else
  1112. entry->ae_set &= ~AE_SET_SYMLINK;
  1113. }
  1114. void
  1115. archive_entry_copy_symlink(struct archive_entry *entry, const char *linkname)
  1116. {
  1117. archive_mstring_copy_mbs(&entry->ae_symlink, linkname);
  1118. if (linkname != NULL)
  1119. entry->ae_set |= AE_SET_SYMLINK;
  1120. else
  1121. entry->ae_set &= ~AE_SET_SYMLINK;
  1122. }
  1123. void
  1124. archive_entry_copy_symlink_w(struct archive_entry *entry, const wchar_t *linkname)
  1125. {
  1126. archive_mstring_copy_wcs(&entry->ae_symlink, linkname);
  1127. if (linkname != NULL)
  1128. entry->ae_set |= AE_SET_SYMLINK;
  1129. else
  1130. entry->ae_set &= ~AE_SET_SYMLINK;
  1131. }
  1132. int
  1133. archive_entry_update_symlink_utf8(struct archive_entry *entry, const char *linkname)
  1134. {
  1135. if (linkname != NULL)
  1136. entry->ae_set |= AE_SET_SYMLINK;
  1137. else
  1138. entry->ae_set &= ~AE_SET_SYMLINK;
  1139. if (archive_mstring_update_utf8(entry->archive,
  1140. &entry->ae_symlink, linkname) == 0)
  1141. return (1);
  1142. if (errno == ENOMEM)
  1143. __archive_errx(1, "No memory");
  1144. return (0);
  1145. }
  1146. int
  1147. _archive_entry_copy_symlink_l(struct archive_entry *entry,
  1148. const char *linkname, size_t len, struct archive_string_conv *sc)
  1149. {
  1150. int r;
  1151. r = archive_mstring_copy_mbs_len_l(&entry->ae_symlink,
  1152. linkname, len, sc);
  1153. if (linkname != NULL && r == 0)
  1154. entry->ae_set |= AE_SET_SYMLINK;
  1155. else
  1156. entry->ae_set &= ~AE_SET_SYMLINK;
  1157. return (r);
  1158. }
  1159. void
  1160. archive_entry_set_uid(struct archive_entry *entry, int64_t u)
  1161. {
  1162. entry->stat_valid = 0;
  1163. entry->ae_stat.aest_uid = u;
  1164. }
  1165. void
  1166. archive_entry_set_uname(struct archive_entry *entry, const char *name)
  1167. {
  1168. archive_mstring_copy_mbs(&entry->ae_uname, name);
  1169. }
  1170. void
  1171. archive_entry_set_uname_utf8(struct archive_entry *entry, const char *name)
  1172. {
  1173. archive_mstring_copy_utf8(&entry->ae_uname, name);
  1174. }
  1175. void
  1176. archive_entry_copy_uname(struct archive_entry *entry, const char *name)
  1177. {
  1178. archive_mstring_copy_mbs(&entry->ae_uname, name);
  1179. }
  1180. void
  1181. archive_entry_copy_uname_w(struct archive_entry *entry, const wchar_t *name)
  1182. {
  1183. archive_mstring_copy_wcs(&entry->ae_uname, name);
  1184. }
  1185. int
  1186. archive_entry_update_uname_utf8(struct archive_entry *entry, const char *name)
  1187. {
  1188. if (archive_mstring_update_utf8(entry->archive,
  1189. &entry->ae_uname, name) == 0)
  1190. return (1);
  1191. if (errno == ENOMEM)
  1192. __archive_errx(1, "No memory");
  1193. return (0);
  1194. }
  1195. void
  1196. archive_entry_set_is_data_encrypted(struct archive_entry *entry, char is_encrypted)
  1197. {
  1198. if (is_encrypted) {
  1199. entry->encryption |= AE_ENCRYPTION_DATA;
  1200. } else {
  1201. entry->encryption &= ~AE_ENCRYPTION_DATA;
  1202. }
  1203. }
  1204. void
  1205. archive_entry_set_is_metadata_encrypted(struct archive_entry *entry, char is_encrypted)
  1206. {
  1207. if (is_encrypted) {
  1208. entry->encryption |= AE_ENCRYPTION_METADATA;
  1209. } else {
  1210. entry->encryption &= ~AE_ENCRYPTION_METADATA;
  1211. }
  1212. }
  1213. int
  1214. _archive_entry_copy_uname_l(struct archive_entry *entry,
  1215. const char *name, size_t len, struct archive_string_conv *sc)
  1216. {
  1217. return (archive_mstring_copy_mbs_len_l(&entry->ae_uname,
  1218. name, len, sc));
  1219. }
  1220. const void *
  1221. archive_entry_mac_metadata(struct archive_entry *entry, size_t *s)
  1222. {
  1223. *s = entry->mac_metadata_size;
  1224. return entry->mac_metadata;
  1225. }
  1226. void
  1227. archive_entry_copy_mac_metadata(struct archive_entry *entry,
  1228. const void *p, size_t s)
  1229. {
  1230. free(entry->mac_metadata);
  1231. if (p == NULL || s == 0) {
  1232. entry->mac_metadata = NULL;
  1233. entry->mac_metadata_size = 0;
  1234. } else {
  1235. entry->mac_metadata_size = s;
  1236. entry->mac_metadata = malloc(s);
  1237. if (entry->mac_metadata == NULL)
  1238. abort();
  1239. memcpy(entry->mac_metadata, p, s);
  1240. }
  1241. }
  1242. /*
  1243. * ACL management. The following would, of course, be a lot simpler
  1244. * if: 1) the last draft of POSIX.1e were a really thorough and
  1245. * complete standard that addressed the needs of ACL archiving and 2)
  1246. * everyone followed it faithfully. Alas, neither is true, so the
  1247. * following is a lot more complex than might seem necessary to the
  1248. * uninitiated.
  1249. */
  1250. struct archive_acl *
  1251. archive_entry_acl(struct archive_entry *entry)
  1252. {
  1253. return &entry->acl;
  1254. }
  1255. void
  1256. archive_entry_acl_clear(struct archive_entry *entry)
  1257. {
  1258. archive_acl_clear(&entry->acl);
  1259. }
  1260. /*
  1261. * Add a single ACL entry to the internal list of ACL data.
  1262. */
  1263. int
  1264. archive_entry_acl_add_entry(struct archive_entry *entry,
  1265. int type, int permset, int tag, int id, const char *name)
  1266. {
  1267. return archive_acl_add_entry(&entry->acl, type, permset, tag, id, name);
  1268. }
  1269. /*
  1270. * As above, but with a wide-character name.
  1271. */
  1272. int
  1273. archive_entry_acl_add_entry_w(struct archive_entry *entry,
  1274. int type, int permset, int tag, int id, const wchar_t *name)
  1275. {
  1276. return archive_acl_add_entry_w_len(&entry->acl,
  1277. type, permset, tag, id, name, wcslen(name));
  1278. }
  1279. /*
  1280. * Return a count of entries matching "want_type".
  1281. */
  1282. int
  1283. archive_entry_acl_count(struct archive_entry *entry, int want_type)
  1284. {
  1285. return archive_acl_count(&entry->acl, want_type);
  1286. }
  1287. /*
  1288. * Prepare for reading entries from the ACL data. Returns a count
  1289. * of entries matching "want_type", or zero if there are no
  1290. * non-extended ACL entries of that type.
  1291. */
  1292. int
  1293. archive_entry_acl_reset(struct archive_entry *entry, int want_type)
  1294. {
  1295. return archive_acl_reset(&entry->acl, want_type);
  1296. }
  1297. /*
  1298. * Return the next ACL entry in the list. Fake entries for the
  1299. * standard permissions and include them in the returned list.
  1300. */
  1301. int
  1302. archive_entry_acl_next(struct archive_entry *entry, int want_type, int *type,
  1303. int *permset, int *tag, int *id, const char **name)
  1304. {
  1305. int r;
  1306. r = archive_acl_next(entry->archive, &entry->acl, want_type, type,
  1307. permset, tag, id, name);
  1308. if (r == ARCHIVE_FATAL && errno == ENOMEM)
  1309. __archive_errx(1, "No memory");
  1310. return (r);
  1311. }
  1312. /*
  1313. * Generate a text version of the ACL. The flags parameter controls
  1314. * the style of the generated ACL.
  1315. */
  1316. const wchar_t *
  1317. archive_entry_acl_text_w(struct archive_entry *entry, int flags)
  1318. {
  1319. const wchar_t *r;
  1320. r = archive_acl_text_w(entry->archive, &entry->acl, flags);
  1321. if (r == NULL && errno == ENOMEM)
  1322. __archive_errx(1, "No memory");
  1323. return (r);
  1324. }
  1325. const char *
  1326. archive_entry_acl_text(struct archive_entry *entry, int flags)
  1327. {
  1328. const char *p;
  1329. if (archive_acl_text_l(&entry->acl, flags, &p, NULL, NULL) != 0
  1330. && errno == ENOMEM)
  1331. __archive_errx(1, "No memory");
  1332. return (p);
  1333. }
  1334. int
  1335. _archive_entry_acl_text_l(struct archive_entry *entry, int flags,
  1336. const char **acl_text, size_t *len, struct archive_string_conv *sc)
  1337. {
  1338. return (archive_acl_text_l(&entry->acl, flags, acl_text, len, sc));
  1339. }
  1340. /*
  1341. * Following code is modified from UC Berkeley sources, and
  1342. * is subject to the following copyright notice.
  1343. */
  1344. /*-
  1345. * Copyright (c) 1993
  1346. * The Regents of the University of California. All rights reserved.
  1347. *
  1348. * Redistribution and use in source and binary forms, with or without
  1349. * modification, are permitted provided that the following conditions
  1350. * are met:
  1351. * 1. Redistributions of source code must retain the above copyright
  1352. * notice, this list of conditions and the following disclaimer.
  1353. * 2. Redistributions in binary form must reproduce the above copyright
  1354. * notice, this list of conditions and the following disclaimer in the
  1355. * documentation and/or other materials provided with the distribution.
  1356. * 4. Neither the name of the University nor the names of its contributors
  1357. * may be used to endorse or promote products derived from this software
  1358. * without specific prior written permission.
  1359. *
  1360. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  1361. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  1362. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  1363. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  1364. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  1365. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  1366. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  1367. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  1368. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  1369. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  1370. * SUCH DAMAGE.
  1371. */
  1372. static struct flag {
  1373. const char *name;
  1374. const wchar_t *wname;
  1375. unsigned long set;
  1376. unsigned long clear;
  1377. } flags[] = {
  1378. /* Preferred (shorter) names per flag first, all prefixed by "no" */
  1379. #ifdef SF_APPEND
  1380. { "nosappnd", L"nosappnd", SF_APPEND, 0 },
  1381. { "nosappend", L"nosappend", SF_APPEND, 0 },
  1382. #endif
  1383. #ifdef EXT2_APPEND_FL /* 'a' */
  1384. { "nosappnd", L"nosappnd", EXT2_APPEND_FL, 0 },
  1385. { "nosappend", L"nosappend", EXT2_APPEND_FL, 0 },
  1386. #endif
  1387. #ifdef SF_ARCHIVED
  1388. { "noarch", L"noarch", SF_ARCHIVED, 0 },
  1389. { "noarchived", L"noarchived", SF_ARCHIVED, 0 },
  1390. #endif
  1391. #ifdef SF_IMMUTABLE
  1392. { "noschg", L"noschg", SF_IMMUTABLE, 0 },
  1393. { "noschange", L"noschange", SF_IMMUTABLE, 0 },
  1394. { "nosimmutable", L"nosimmutable", SF_IMMUTABLE, 0 },
  1395. #endif
  1396. #ifdef EXT2_IMMUTABLE_FL /* 'i' */
  1397. { "noschg", L"noschg", EXT2_IMMUTABLE_FL, 0 },
  1398. { "noschange", L"noschange", EXT2_IMMUTABLE_FL, 0 },
  1399. { "nosimmutable", L"nosimmutable", EXT2_IMMUTABLE_FL, 0 },
  1400. #endif
  1401. #ifdef SF_NOUNLINK
  1402. { "nosunlnk", L"nosunlnk", SF_NOUNLINK, 0 },
  1403. { "nosunlink", L"nosunlink", SF_NOUNLINK, 0 },
  1404. #endif
  1405. #ifdef SF_SNAPSHOT
  1406. { "nosnapshot", L"nosnapshot", SF_SNAPSHOT, 0 },
  1407. #endif
  1408. #ifdef UF_APPEND
  1409. { "nouappnd", L"nouappnd", UF_APPEND, 0 },
  1410. { "nouappend", L"nouappend", UF_APPEND, 0 },
  1411. #endif
  1412. #ifdef UF_IMMUTABLE
  1413. { "nouchg", L"nouchg", UF_IMMUTABLE, 0 },
  1414. { "nouchange", L"nouchange", UF_IMMUTABLE, 0 },
  1415. { "nouimmutable", L"nouimmutable", UF_IMMUTABLE, 0 },
  1416. #endif
  1417. #ifdef UF_NODUMP
  1418. { "nodump", L"nodump", 0, UF_NODUMP},
  1419. #endif
  1420. #ifdef EXT2_NODUMP_FL /* 'd' */
  1421. { "nodump", L"nodump", 0, EXT2_NODUMP_FL},
  1422. #endif
  1423. #ifdef UF_OPAQUE
  1424. { "noopaque", L"noopaque", UF_OPAQUE, 0 },
  1425. #endif
  1426. #ifdef UF_NOUNLINK
  1427. { "nouunlnk", L"nouunlnk", UF_NOUNLINK, 0 },
  1428. { "nouunlink", L"nouunlink", UF_NOUNLINK, 0 },
  1429. #endif
  1430. #ifdef UF_COMPRESSED
  1431. { "nocompressed",L"nocompressed", UF_COMPRESSED, 0 },
  1432. #endif
  1433. #ifdef EXT2_UNRM_FL
  1434. { "nouunlink", L"nouunlink", EXT2_UNRM_FL, 0},
  1435. #endif
  1436. #ifdef EXT2_BTREE_FL
  1437. { "nobtree", L"nobtree", EXT2_BTREE_FL, 0 },
  1438. #endif
  1439. #ifdef EXT2_ECOMPR_FL
  1440. { "nocomperr", L"nocomperr", EXT2_ECOMPR_FL, 0 },
  1441. #endif
  1442. #ifdef EXT2_COMPR_FL /* 'c' */
  1443. { "nocompress", L"nocompress", EXT2_COMPR_FL, 0 },
  1444. #endif
  1445. #ifdef EXT2_NOATIME_FL /* 'A' */
  1446. { "noatime", L"noatime", 0, EXT2_NOATIME_FL},
  1447. #endif
  1448. #ifdef EXT2_DIRTY_FL
  1449. { "nocompdirty",L"nocompdirty", EXT2_DIRTY_FL, 0},
  1450. #endif
  1451. #ifdef EXT2_COMPRBLK_FL
  1452. #ifdef EXT2_NOCOMPR_FL
  1453. { "nocomprblk", L"nocomprblk", EXT2_COMPRBLK_FL, EXT2_NOCOMPR_FL},
  1454. #else
  1455. { "nocomprblk", L"nocomprblk", EXT2_COMPRBLK_FL, 0},
  1456. #endif
  1457. #endif
  1458. #ifdef EXT2_DIRSYNC_FL
  1459. { "nodirsync", L"nodirsync", EXT2_DIRSYNC_FL, 0},
  1460. #endif
  1461. #ifdef EXT2_INDEX_FL
  1462. { "nohashidx", L"nohashidx", EXT2_INDEX_FL, 0},
  1463. #endif
  1464. #ifdef EXT2_IMAGIC_FL
  1465. { "noimagic", L"noimagic", EXT2_IMAGIC_FL, 0},
  1466. #endif
  1467. #ifdef EXT3_JOURNAL_DATA_FL
  1468. { "nojournal", L"nojournal", EXT3_JOURNAL_DATA_FL, 0},
  1469. #endif
  1470. #ifdef EXT2_SECRM_FL
  1471. { "nosecuredeletion",L"nosecuredeletion",EXT2_SECRM_FL, 0},
  1472. #endif
  1473. #ifdef EXT2_SYNC_FL
  1474. { "nosync", L"nosync", EXT2_SYNC_FL, 0},
  1475. #endif
  1476. #ifdef EXT2_NOTAIL_FL
  1477. { "notail", L"notail", 0, EXT2_NOTAIL_FL},
  1478. #endif
  1479. #ifdef EXT2_TOPDIR_FL
  1480. { "notopdir", L"notopdir", EXT2_TOPDIR_FL, 0},
  1481. #endif
  1482. #ifdef EXT2_RESERVED_FL
  1483. { "noreserved", L"noreserved", EXT2_RESERVED_FL, 0},
  1484. #endif
  1485. { NULL, NULL, 0, 0 }
  1486. };
  1487. /*
  1488. * fflagstostr --
  1489. * Convert file flags to a comma-separated string. If no flags
  1490. * are set, return the empty string.
  1491. */
  1492. static char *
  1493. ae_fflagstostr(unsigned long bitset, unsigned long bitclear)
  1494. {
  1495. char *string, *dp;
  1496. const char *sp;
  1497. unsigned long bits;
  1498. struct flag *flag;
  1499. size_t length;
  1500. bits = bitset | bitclear;
  1501. length = 0;
  1502. for (flag = flags; flag->name != NULL; flag++)
  1503. if (bits & (flag->set | flag->clear)) {
  1504. length += strlen(flag->name) + 1;
  1505. bits &= ~(flag->set | flag->clear);
  1506. }
  1507. if (length == 0)
  1508. return (NULL);
  1509. string = (char *)malloc(length);
  1510. if (string == NULL)
  1511. return (NULL);
  1512. dp = string;
  1513. for (flag = flags; flag->name != NULL; flag++) {
  1514. if (bitset & flag->set || bitclear & flag->clear) {
  1515. sp = flag->name + 2;
  1516. } else if (bitset & flag->clear || bitclear & flag->set) {
  1517. sp = flag->name;
  1518. } else
  1519. continue;
  1520. bitset &= ~(flag->set | flag->clear);
  1521. bitclear &= ~(flag->set | flag->clear);
  1522. if (dp > string)
  1523. *dp++ = ',';
  1524. while ((*dp++ = *sp++) != '\0')
  1525. ;
  1526. dp--;
  1527. }
  1528. *dp = '\0';
  1529. return (string);
  1530. }
  1531. /*
  1532. * strtofflags --
  1533. * Take string of arguments and return file flags. This
  1534. * version works a little differently than strtofflags(3).
  1535. * In particular, it always tests every token, skipping any
  1536. * unrecognized tokens. It returns a pointer to the first
  1537. * unrecognized token, or NULL if every token was recognized.
  1538. * This version is also const-correct and does not modify the
  1539. * provided string.
  1540. */
  1541. static const char *
  1542. ae_strtofflags(const char *s, unsigned long *setp, unsigned long *clrp)
  1543. {
  1544. const char *start, *end;
  1545. struct flag *flag;
  1546. unsigned long set, clear;
  1547. const char *failed;
  1548. set = clear = 0;
  1549. start = s;
  1550. failed = NULL;
  1551. /* Find start of first token. */
  1552. while (*start == '\t' || *start == ' ' || *start == ',')
  1553. start++;
  1554. while (*start != '\0') {
  1555. size_t length;
  1556. /* Locate end of token. */
  1557. end = start;
  1558. while (*end != '\0' && *end != '\t' &&
  1559. *end != ' ' && *end != ',')
  1560. end++;
  1561. length = end - start;
  1562. for (flag = flags; flag->name != NULL; flag++) {
  1563. size_t flag_length = strlen(flag->name);
  1564. if (length == flag_length
  1565. && memcmp(start, flag->name, length) == 0) {
  1566. /* Matched "noXXXX", so reverse the sense. */
  1567. clear |= flag->set;
  1568. set |= flag->clear;
  1569. break;
  1570. } else if (length == flag_length - 2
  1571. && memcmp(start, flag->name + 2, length) == 0) {
  1572. /* Matched "XXXX", so don't reverse. */
  1573. set |= flag->set;
  1574. clear |= flag->clear;
  1575. break;
  1576. }
  1577. }
  1578. /* Ignore unknown flag names. */
  1579. if (flag->name == NULL && failed == NULL)
  1580. failed = start;
  1581. /* Find start of next token. */
  1582. start = end;
  1583. while (*start == '\t' || *start == ' ' || *start == ',')
  1584. start++;
  1585. }
  1586. if (setp)
  1587. *setp = set;
  1588. if (clrp)
  1589. *clrp = clear;
  1590. /* Return location of first failure. */
  1591. return (failed);
  1592. }
  1593. /*
  1594. * wcstofflags --
  1595. * Take string of arguments and return file flags. This
  1596. * version works a little differently than strtofflags(3).
  1597. * In particular, it always tests every token, skipping any
  1598. * unrecognized tokens. It returns a pointer to the first
  1599. * unrecognized token, or NULL if every token was recognized.
  1600. * This version is also const-correct and does not modify the
  1601. * provided string.
  1602. */
  1603. static const wchar_t *
  1604. ae_wcstofflags(const wchar_t *s, unsigned long *setp, unsigned long *clrp)
  1605. {
  1606. const wchar_t *start, *end;
  1607. struct flag *flag;
  1608. unsigned long set, clear;
  1609. const wchar_t *failed;
  1610. set = clear = 0;
  1611. start = s;
  1612. failed = NULL;
  1613. /* Find start of first token. */
  1614. while (*start == L'\t' || *start == L' ' || *start == L',')
  1615. start++;
  1616. while (*start != L'\0') {
  1617. size_t length;
  1618. /* Locate end of token. */
  1619. end = start;
  1620. while (*end != L'\0' && *end != L'\t' &&
  1621. *end != L' ' && *end != L',')
  1622. end++;
  1623. length = end - start;
  1624. for (flag = flags; flag->wname != NULL; flag++) {
  1625. size_t flag_length = wcslen(flag->wname);
  1626. if (length == flag_length
  1627. && wmemcmp(start, flag->wname, length) == 0) {
  1628. /* Matched "noXXXX", so reverse the sense. */
  1629. clear |= flag->set;
  1630. set |= flag->clear;
  1631. break;
  1632. } else if (length == flag_length - 2
  1633. && wmemcmp(start, flag->wname + 2, length) == 0) {
  1634. /* Matched "XXXX", so don't reverse. */
  1635. set |= flag->set;
  1636. clear |= flag->clear;
  1637. break;
  1638. }
  1639. }
  1640. /* Ignore unknown flag names. */
  1641. if (flag->wname == NULL && failed == NULL)
  1642. failed = start;
  1643. /* Find start of next token. */
  1644. start = end;
  1645. while (*start == L'\t' || *start == L' ' || *start == L',')
  1646. start++;
  1647. }
  1648. if (setp)
  1649. *setp = set;
  1650. if (clrp)
  1651. *clrp = clear;
  1652. /* Return location of first failure. */
  1653. return (failed);
  1654. }
  1655. #ifdef TEST
  1656. #include <stdio.h>
  1657. int
  1658. main(int argc, char **argv)
  1659. {
  1660. struct archive_entry *entry = archive_entry_new();
  1661. unsigned long set, clear;
  1662. const wchar_t *remainder;
  1663. remainder = archive_entry_copy_fflags_text_w(entry, L"nosappnd dump archive,,,,,,,");
  1664. archive_entry_fflags(entry, &set, &clear);
  1665. wprintf(L"set=0x%lX clear=0x%lX remainder='%ls'\n", set, clear, remainder);
  1666. wprintf(L"new flags='%s'\n", archive_entry_fflags_text(entry));
  1667. return (0);
  1668. }
  1669. #endif