Lines Matching +full:stdout +full:- +full:path

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
5 * Copyright (c) 2007-2008 Dag-Erling Smørgrav
58 /* command-line options */
60 static int C_opt; /* match case-insensitively */
61 static int c_opt; /* extract to stdout */
69 static int p_opt; /* extract to stdout, quiet */
119 fprintf(stdout, "\n");
120 fflush(stdout);
136 fprintf(stdout, "\n");
137 fflush(stdout);
146 /* non-fatal error message + errno */
153 fprintf(stdout, "\n");
154 fflush(stdout);
162 /* non-fatal error message, no errno */
169 fprintf(stdout, "\n");
170 fflush(stdout);
178 /* informational message (if not -q) */
187 vfprintf(stdout, fmt, ap);
189 fflush(stdout);
194 noeol = fmt[strlen(fmt) - 1] != '\n';
213 noeol = fmt[strlen(fmt) - 1] != '\n';
216 /* duplicate a path name, possibly converting to lower case */
218 pathdup(const char *path)
223 if (path == NULL || path[0] == '\0')
226 len = strlen(path);
227 while (len && path[len - 1] == '/')
228 len--;
235 str[i] = tolower((unsigned char)path[i]);
237 memcpy(str, path, len);
244 /* concatenate two path names */
246 pathcat(const char *prefix, const char *path)
252 len = strlen(path) + 1;
259 str[prelen - 1] = '/'; /* splat zero */
261 memcpy(str + prelen, path, len); /* includes zero */
293 memcpy(entry->pattern, pattern, len + 1);
307 if (fnmatch(entry->pattern, str, C_opt ? FNM_CASEFOLD : 0) == 0)
336 make_dir(const char *path, int mode)
340 if (lstat(path, &sb) == 0) {
345 * the non-directory of the same name as a directory we
346 * wish to create, or respect the -n or -o command-line
348 * even compromise (if this non-directory happens to be a
356 (void)unlink(path);
358 if (mkdir(path, mode) != 0 && errno != EEXIST)
359 error("mkdir('%s')", path);
364 * specified path exist.
366 * XXX inefficient + modifies the file in-place
369 make_parent(char *path)
374 sep = strrchr(path, '/');
375 if (sep == NULL || sep == path)
378 if (lstat(path, &sb) == 0) {
383 unlink(path);
385 make_parent(path);
386 mkdir(path, 0755);
390 for (sep = path; (sep = strchr(sep, '/')) != NULL; sep++) {
392 if (sep == path)
395 make_dir(path, 0755);
405 extract_dir(struct archive *a, struct archive_entry *e, const char *path)
413 if (*path == '\0')
436 info(" creating: %s/\n", path);
437 make_dir(path, mode);
442 static char spinner[] = { '|', '/', '-', '\\' };
445 handle_existing_file(char **path)
454 *path);
463 (void)unlink(*path);
469 return -1;
473 fflush(stdout);
474 free(*path);
475 *path = NULL;
477 len = getline(path, &alen, stdin);
480 if ((*path)[len - 1] == '\n')
481 (*path)[len - 1] = '\0';
492 return -1;
499 * one white-listed byte has to be found.
501 * Black-listed: 0..6, 14..25, 28..31
503 * White-listed: 9..10, 13, >= 32
515 for (rv = 1; len--; ++buf) {
569 * guess by looking for non-ASCII characters in the
603 if (write(fd, p, q - p) != q - p)
615 extract_file(struct archive *a, struct archive_entry *e, char **path)
638 if (lstat(*path, &sb) == 0) {
640 /* check if up-to-date */
663 (void)unlink(*path);
666 (void)unlink(*path);
671 check = handle_existing_file(path);
674 if (check == -1)
690 times[0].tv_usec = -1;
698 if (symlink(linkname, *path) != 0)
699 error("symlink('%s')", *path);
700 info(" extracting: %s -> %s\n", *path, linkname);
702 if (lchmod(*path, mode) != 0)
703 warning("Cannot set mode for '%s'", *path);
707 if (utimensat(AT_FDCWD, *path, ts, AT_SYMLINK_NOFOLLOW) != 0)
708 warning("utimensat('%s')", *path);
711 if (lutimes(*path, times) != 0)
712 warning("lutimes('%s')", *path);
717 if ((fd = open(*path, O_RDWR|O_CREAT|O_TRUNC, mode)) < 0)
718 error("open('%s')", *path);
720 info(" extracting: %s", *path);
722 text = extract2fd(a, *path, fd);
733 error("futimens('%s')", *path);
737 error("futimes('%s')", *path);
740 error("close('%s')", *path);
745 * that it is either a directory or a regular file and that the path is
750 * manipulate the path name. Case conversion (if requested by the -L
752 * to the full converted path name, before the directory part of the path
753 * is removed in accordance with the -j option. Sanity checks are
784 warningx("skipping non-regular entry '%s'", pathname);
790 /* skip directories in -j case */
804 /* apply -j and -d */
841 warningx("skipping non-regular entry '%s'", pathname);
847 /* skip directories in -j case */
870 * Print the name of an entry to stdout.
882 strftime(buf, sizeof(buf), "%m-%d-%G %R", tm);
884 strftime(buf, sizeof(buf), "%m-%d-%g %R", tm);
998 printf(" -------- %s---- ---- ----\n", y_str);
1000 printf(" Length Method Size Ratio %sDate Time CRC-32 Name\n", y_str);
1001 printf("-------- ------ ------- ----- %s---- ---- ------ ----\n", y_str);
1033 printf(" -------- %s-------\n", y_str);
1037 printf("-------- ------- --- %s-------\n", y_str);
1067 "Usage: unzip [-aCcfjLlnopqtuvyZ1] [{-O|-I} encoding] [-d dir] [-x pattern] [-P password] zipfile\n"
1075 printf("bsdunzip %s - %s \n",
1091 bsdunzip->argv = argv;
1092 bsdunzip->argc = argc;
1094 while ((opt = bsdunzip_getopt(bsdunzip)) != -1) {
1107 d_arg = bsdunzip->argument;
1114 O_arg = bsdunzip->argument;
1137 P_arg = bsdunzip->argument;
1152 add_pattern(&exclude, bsdunzip->argument);
1160 if (bsdunzip->argument != NULL &&
1161 strcmp(bsdunzip->argument, "1") == 0) {
1198 debug("%s%c", argv[i], (i < argc - 1) ? ' ' : '\n');
1205 * Info-ZIP's unzip(1) expects certain options to come before the
1206 * zipfile name, and others to come after - though it does not
1228 if (strcmp(zipfile, "-") == 0)
1233 while (nopts < argc && *argv[nopts] != '-')
1236 nopts--; /* fake argv[0] */
1237 nopts += getopts(argc - nopts, argv + nopts);
1240 * For compatibility with Info-ZIP's unzip(1) we need to treat
1241 * non-option arguments following an -x after the zipfile as
1245 while (nopts < argc && *argv[nopts] != '-')
1247 nopts--; /* fake argv[0] */
1248 nopts += getopts(argc - nopts, argv + nopts);
1251 /* There may be residual arguments if we encountered -- */
1256 errorx("-n, -o and -u are contradictory");