Lines Matching +full:short +full:- +full:circuit

1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2003-2007 Tim Kientzle
32 * Short options for cpio. Please keep this sorted.
42 int equivalent; /* Equivalent short option. */
61 { "make-directories", 0, 'd' },
62 { "no-preserve-owner", 0, OPTION_NO_PRESERVE_OWNER },
64 { "numeric-uid-gid", 0, 'n' },
67 { "pass-through", 0, 'p' },
68 { "preserve-modification-time", 0, 'm' },
69 { "preserve-owner", 0, OPTION_PRESERVE_OWNER },
82 * I used to try to select platform-provided getopt() or
86 * overuse of the -W hack in the test harness, which made it rough to
88 * test harness here against GNU cpio as a sanity-check. Yes,
107 long_prefix = "--"; in cpio_getopt()
110 cpio->argument = NULL; in cpio_getopt()
115 ++cpio->argv; in cpio_getopt()
116 --cpio->argc; in cpio_getopt()
125 if (cpio->argv[0] == NULL) in cpio_getopt()
126 return (-1); in cpio_getopt()
127 /* Doesn't start with '-', so no more options. */ in cpio_getopt()
128 if (cpio->argv[0][0] != '-') in cpio_getopt()
129 return (-1); in cpio_getopt()
130 /* "--" marks end of options; consume it and return. */ in cpio_getopt()
131 if (strcmp(cpio->argv[0], "--") == 0) { in cpio_getopt()
132 ++cpio->argv; in cpio_getopt()
133 --cpio->argc; in cpio_getopt()
134 return (-1); in cpio_getopt()
137 opt_word = *cpio->argv++; in cpio_getopt()
138 --cpio->argc; in cpio_getopt()
139 if (opt_word[1] == '-') { in cpio_getopt()
142 opt_word += 2; /* Skip leading '--' */ in cpio_getopt()
144 /* Set up short option parser. */ in cpio_getopt()
146 ++opt_word; /* Skip leading '-' */ in cpio_getopt()
151 * We're parsing a group of POSIX-style single-character options. in cpio_getopt()
154 /* Peel next option off of a group of short options. */ in cpio_getopt()
171 /* If arg is run-in, opt_word already points to it. */ in cpio_getopt()
174 opt_word = *cpio->argv; in cpio_getopt()
177 "Option -%c requires an argument", in cpio_getopt()
181 ++cpio->argv; in cpio_getopt()
182 --cpio->argc; in cpio_getopt()
186 long_prefix = "-W "; /* For clearer errors. */ in cpio_getopt()
189 cpio->argument = opt_word; in cpio_getopt()
194 /* We're reading a long option, including -W long=arg convention. */ in cpio_getopt()
202 optlength = (size_t)(p - opt_word); in cpio_getopt()
203 cpio->argument = (char *)(uintptr_t)(p + 1); in cpio_getopt()
209 for (popt = cpio_longopts; popt->name != NULL; popt++) { in cpio_getopt()
210 /* Short-circuit if first chars don't match. */ in cpio_getopt()
211 if (popt->name[0] != opt_word[0]) in cpio_getopt()
214 if (strncmp(opt_word, popt->name, optlength) == 0) { in cpio_getopt()
218 if (strlen(popt->name) == optlength) { in cpio_getopt()
234 "Ambiguous option %s%s (matches --%s and --%s)", in cpio_getopt()
235 long_prefix, opt_word, match->name, match2->name); in cpio_getopt()
240 if (match->required) { in cpio_getopt()
242 if (cpio->argument == NULL) { in cpio_getopt()
243 cpio->argument = *cpio->argv; in cpio_getopt()
244 if (cpio->argument == NULL) { in cpio_getopt()
247 long_prefix, match->name); in cpio_getopt()
250 ++cpio->argv; in cpio_getopt()
251 --cpio->argc; in cpio_getopt()
255 if (cpio->argument != NULL) { in cpio_getopt()
258 long_prefix, match->name); in cpio_getopt()
262 return (match->equivalent); in cpio_getopt()
270 * Parse the argument to the -R or --owner flag.
273 * <username|uid> - Override user but not group
274 * <username>: - Override both, group is user's default group
275 * <uid>: - Override user but not group
276 * <username|uid>:<groupname|gid> - Override both
277 * :<groupname|gid> - Override group but not user
285 * Sets uid/gid return as appropriate, -1 indicates uid/gid not specified.
298 owner->uid = -1; in owner_parse()
299 owner->gid = -1; in owner_parse()
301 owner->uname = NULL; in owner_parse()
302 owner->gname = NULL; in owner_parse()
306 return (-1); in owner_parse()
311 * u -> first char of username, NULL if no username in owner_parse()
312 * ue -> first char after username (colon, period, or \0) in owner_parse()
313 * g -> first char of group name in owner_parse()
334 user = malloc(ue - u + 1); in owner_parse()
337 memcpy(user, u, ue - u); in owner_parse()
338 user[ue - u] = '\0'; in owner_parse()
340 owner->uid = pwent->pw_uid; in owner_parse()
341 owner->uname = strdup(pwent->pw_name); in owner_parse()
342 if (owner->uname == NULL) { in owner_parse()
347 owner->gid = pwent->pw_gid; in owner_parse()
351 owner->uid = (int)strtoul(user, &end, 10); in owner_parse()
355 errbuff[sizeof(errbuff) - 1] = '\0'; in owner_parse()
358 return (-1); in owner_parse()
367 owner->gid = grp->gr_gid; in owner_parse()
368 owner->gname = strdup(grp->gr_name); in owner_parse()
369 if (owner->gname == NULL) { in owner_parse()
370 free(owner->uname); in owner_parse()
371 owner->uname = NULL; in owner_parse()
377 owner->gid = (int)strtoul(g, &end, 10); in owner_parse()
381 errbuff[sizeof(errbuff) - 1] = '\0'; in owner_parse()
383 return (-1); in owner_parse()
390 return (-1); in owner_parse()