Lines Matching +full:non +full:- +full:safety
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2003-2007 Tim Kientzle
63 * Print a string, taking care with any non-printable characters.
65 * Note that we use a stack-allocated buffer to receive the formatted
70 * works), but mostly for safety (so we can use this to print messages
71 * about out-of-memory conditions).
89 /* Use a stack-allocated buffer if we can, for speed and safety. */ in safe_fprintf()
109 fmtbuff_heap[length-1] = '\0'; in safe_fprintf()
125 length = sizeof(fmtbuff_stack) - 1; in safe_fprintf()
132 if (mbtowc(NULL, NULL, 1) == -1) { /* Reset the shift state. */ in safe_fprintf()
147 if (try_wc && (n = mbtowc(&wc, p, length)) != -1) { in safe_fprintf()
148 length -= n; in safe_fprintf()
151 while (n-- > 0) in safe_fprintf()
155 while (n-- > 0) in safe_fprintf()
167 if (i > (sizeof(outbuff) - 128)) { in safe_fprintf()
176 /* If we allocated a heap-based formatting buffer, free it now. */ in safe_fprintf()
205 snprintf(buff + i, buffsize - i, "%03o", 0xFF & (int)c); in bsdtar_expand_char()
210 return (i - offset); in bsdtar_expand_char()
240 l = read(read_fd, buff, sizeof(buff) - 1); in yes()
270 /*-
271 * The logic here for -C <dir> attempts to avoid
273 * "-C /foo -C /bar file" needs chdir("/bar") but not chdir("/foo")
274 * "-C /foo -C bar file" needs chdir("/foo/bar")
275 * "-C /foo -C bar /file1" does not need chdir()
276 * "-C /foo -C bar /file1 file2" needs chdir("/foo/bar") before file2
280 * need to process a non-absolute file. set_chdir() adds the new dir
284 * about -C with non-existent directories; such requests will only
300 /* The -C /foo -C /bar case; dump first one. */
301 free(bsdtar->pending_chdir);
302 bsdtar->pending_chdir = NULL;
304 if (bsdtar->pending_chdir == NULL)
305 /* Easy case: no previously-saved dir. */
306 bsdtar->pending_chdir = strdup(newdir);
308 /* The -C /foo -C bar case; concatenate */
309 char *old_pending = bsdtar->pending_chdir;
312 bsdtar->pending_chdir = malloc(new_len);
313 if (old_pending[old_len - 1] == '/')
314 old_pending[old_len - 1] = '\0';
315 if (bsdtar->pending_chdir != NULL)
316 snprintf(bsdtar->pending_chdir, new_len, "%s/%s",
320 if (bsdtar->pending_chdir == NULL)
327 if (bsdtar->pending_chdir == NULL)
330 if (chdir(bsdtar->pending_chdir) != 0) {
332 bsdtar->pending_chdir);
334 free(bsdtar->pending_chdir);
335 bsdtar->pending_chdir = NULL;
348 elements--;
380 if (!bsdtar->warned_lead_slash) {
384 bsdtar->warned_lead_slash = 1;
391 if (!bsdtar->warned_lead_slash) {
395 bsdtar->warned_lead_slash = 1;
400 * Convert absolute path to non-absolute path by skipping leading
455 * Handle --strip-components and any future path-rewriting options.
456 * Returns non-zero if the pathname should not be extracted.
464 * TODO: Support pax-style regex path rewrites.
477 /* Apply user-specified substitution to pathname. */
479 if (r == -1) {
487 return -1;
494 /* Apply user-specified substitution to hardlink target. */
497 if (r == -1) {
509 /* Apply user-specified substitution to symlink body. */
512 if (r == -1) {
523 /* Strip leading dir names as per --strip-components option. */
524 if (bsdtar->strip_components > 0) {
525 name = strip_components(name, bsdtar->strip_components);
531 bsdtar->strip_components);
537 if ((bsdtar->flags & OPTFLAG_ABSOLUTE_PATHS) == 0) {
573 uint64_t n = n0 < 0 ? -n0 : n0;
576 *--p = '\0';
578 *--p = '0' + (int)(n % 10);
581 *--p = '-';
624 return (*(const unsigned char *)a - *(const unsigned char *)b);
634 if (bsdtar->ppbuff == NULL) {
635 bsdtar->ppbuff = malloc(PPBUFF_SIZE);
636 if (bsdtar->ppbuff == NULL)
640 bsdtar->ppbuff, PPBUFF_SIZE);
655 * The format here roughly duplicates the output of 'ls -l'.
658 * and 'pax -l' is documented as using the same format as 'ls -l'.
677 * just pre-compute the field widths. Instead, we start with guesses
681 if (!bsdtar->u_width) {
682 bsdtar->u_width = 6;
683 bsdtar->gs_width = 13;
699 if (w > bsdtar->u_width)
700 bsdtar->u_width = w;
701 fprintf(out, "%-*s ", (int)bsdtar->u_width, p);
716 * Print device number or file size, right-aligned so as to make
728 if (w + strlen(tmp) >= bsdtar->gs_width)
729 bsdtar->gs_width = w+strlen(tmp)+1;
730 fprintf(out, "%*s", (int)(bsdtar->gs_width - w), tmp);
732 /* Format the time using 'ls -l' conventions. */
740 if (tim < now - HALF_YEAR || tim > now + HALF_YEAR)
741 fmt = bsdtar->day_first ? DAY_FMT " %b %Y" : "%b " DAY_FMT " %Y";
743 fmt = bsdtar->day_first ? DAY_FMT " %b %H:%M" : "%b " DAY_FMT " %H:%M";
760 safe_fprintf(out, " -> %s", archive_entry_symlink(entry));