ar.c (38911b3c2c7dbb9a097b44856472ebbbedde71fc) | ar.c (d20e9e02db3dde383c3de1ce8cec3a8c35b3eee6) |
---|---|
1/*- 2 * SPDX-License-Identifier: BSD-3-Clause 3 * 4 * Copyright (c) 2007 Kai Wang 5 * Copyright (c) 2007 Tim Kientzle 6 * Copyright (c) 2007 Joseph Koshy 7 * All rights reserved. 8 * --- 137 unchanged lines hidden (view full) --- 146 if (*argv == NULL) 147 ranlib_usage(); 148 149 /* Enable determinstic mode unless -U is set. */ 150 if (Uflag == 0) 151 bsdar->options |= AR_D; 152 bsdar->options |= AR_S; 153 while ((bsdar->filename = *argv++) != NULL) | 1/*- 2 * SPDX-License-Identifier: BSD-3-Clause 3 * 4 * Copyright (c) 2007 Kai Wang 5 * Copyright (c) 2007 Tim Kientzle 6 * Copyright (c) 2007 Joseph Koshy 7 * All rights reserved. 8 * --- 137 unchanged lines hidden (view full) --- 146 if (*argv == NULL) 147 ranlib_usage(); 148 149 /* Enable determinstic mode unless -U is set. */ 150 if (Uflag == 0) 151 bsdar->options |= AR_D; 152 bsdar->options |= AR_S; 153 while ((bsdar->filename = *argv++) != NULL) |
154 if (ar_mode_s(bsdar)) | 154 if (ar_read_archive(bsdar, 's')) |
155 exitcode = EXIT_FAILURE; 156 157 exit(exitcode); 158 } else { 159 if (argc < 2) 160 bsdar_usage(); 161 162 if (*argv[1] != '-') { 163 len = strlen(argv[1]) + 2; 164 if ((p = malloc(len)) == NULL) | 155 exitcode = EXIT_FAILURE; 156 157 exit(exitcode); 158 } else { 159 if (argc < 2) 160 bsdar_usage(); 161 162 if (*argv[1] != '-') { 163 len = strlen(argv[1]) + 2; 164 if ((p = malloc(len)) == NULL) |
165 bsdar_errc(bsdar, EXIT_FAILURE, errno, 166 "malloc failed"); | 165 bsdar_errc(bsdar, errno, "malloc failed"); |
167 *p = '-'; 168 (void)strlcpy(p + 1, argv[1], len - 1); 169 argv[1] = p; 170 } 171 } 172 173 while ((opt = getopt_long(argc, argv, "abCcdDfijlMmopqrSsTtUuVvxz", 174 longopts, NULL)) != -1) { --- 83 unchanged lines hidden (view full) --- 258 259 argv += optind; 260 argc -= optind; 261 262 if (*argv == NULL && bsdar->mode != 'M') 263 bsdar_usage(); 264 265 if (bsdar->options & AR_A && bsdar->options & AR_B) | 166 *p = '-'; 167 (void)strlcpy(p + 1, argv[1], len - 1); 168 argv[1] = p; 169 } 170 } 171 172 while ((opt = getopt_long(argc, argv, "abCcdDfijlMmopqrSsTtUuVvxz", 173 longopts, NULL)) != -1) { --- 83 unchanged lines hidden (view full) --- 257 258 argv += optind; 259 argc -= optind; 260 261 if (*argv == NULL && bsdar->mode != 'M') 262 bsdar_usage(); 263 264 if (bsdar->options & AR_A && bsdar->options & AR_B) |
266 bsdar_errc(bsdar, EXIT_FAILURE, 0, | 265 bsdar_errc(bsdar, 0, |
267 "only one of -a and -[bi] options allowed"); 268 269 if (bsdar->options & AR_J && bsdar->options & AR_Z) | 266 "only one of -a and -[bi] options allowed"); 267 268 if (bsdar->options & AR_J && bsdar->options & AR_Z) |
270 bsdar_errc(bsdar, EXIT_FAILURE, 0, 271 "only one of -j and -z options allowed"); | 269 bsdar_errc(bsdar, 0, "only one of -j and -z options allowed"); |
272 273 if (bsdar->options & AR_S && bsdar->options & AR_SS) | 270 271 if (bsdar->options & AR_S && bsdar->options & AR_SS) |
274 bsdar_errc(bsdar, EXIT_FAILURE, 0, 275 "only one of -s and -S options allowed"); | 272 bsdar_errc(bsdar, 0, "only one of -s and -S options allowed"); |
276 277 if (bsdar->options & (AR_A | AR_B)) { 278 if (*argv == NULL) | 273 274 if (bsdar->options & (AR_A | AR_B)) { 275 if (*argv == NULL) |
279 bsdar_errc(bsdar, EXIT_FAILURE, 0, 280 "no position operand specified"); | 276 bsdar_errc(bsdar, 0, "no position operand specified"); |
281 if ((bsdar->posarg = basename(*argv)) == NULL) | 277 if ((bsdar->posarg = basename(*argv)) == NULL) |
282 bsdar_errc(bsdar, EXIT_FAILURE, errno, 283 "basename failed"); | 278 bsdar_errc(bsdar, errno, "basename failed"); |
284 argc--; 285 argv++; 286 } 287 288 /* Set determinstic mode for -D, and by default without -U. */ 289 if (Dflag || (Uflag == 0 && (bsdar->mode == 'q' || bsdar->mode == 'r' || 290 (bsdar->mode == '\0' && bsdar->options & AR_S)))) 291 bsdar->options |= AR_D; --- 25 unchanged lines hidden (view full) --- 317 if ((bsdar->filename = *argv) == NULL) 318 bsdar_usage(); 319 320 bsdar->argc = --argc; 321 bsdar->argv = ++argv; 322 323 if ((!bsdar->mode || strchr("ptx", bsdar->mode)) && 324 bsdar->options & AR_S) { | 279 argc--; 280 argv++; 281 } 282 283 /* Set determinstic mode for -D, and by default without -U. */ 284 if (Dflag || (Uflag == 0 && (bsdar->mode == 'q' || bsdar->mode == 'r' || 285 (bsdar->mode == '\0' && bsdar->options & AR_S)))) 286 bsdar->options |= AR_D; --- 25 unchanged lines hidden (view full) --- 312 if ((bsdar->filename = *argv) == NULL) 313 bsdar_usage(); 314 315 bsdar->argc = --argc; 316 bsdar->argv = ++argv; 317 318 if ((!bsdar->mode || strchr("ptx", bsdar->mode)) && 319 bsdar->options & AR_S) { |
325 exitcode = ar_mode_s(bsdar); | 320 exitcode = ar_write_archive(bsdar, 's'); |
326 if (!bsdar->mode) 327 exit(exitcode); 328 } 329 330 switch(bsdar->mode) { | 321 if (!bsdar->mode) 322 exit(exitcode); 323 } 324 325 switch(bsdar->mode) { |
331 case 'd': 332 exitcode = ar_mode_d(bsdar); | 326 case 'd': case 'm': case 'q': case 'r': 327 exitcode = ar_write_archive(bsdar, bsdar->mode); |
333 break; | 328 break; |
334 case 'm': 335 exitcode = ar_mode_m(bsdar); | 329 case 'p': case 't': case 'x': 330 exitcode = ar_read_archive(bsdar, bsdar->mode); |
336 break; | 331 break; |
337 case 'p': 338 exitcode = ar_mode_p(bsdar); 339 break; 340 case 'q': 341 exitcode = ar_mode_q(bsdar); 342 break; 343 case 'r': 344 exitcode = ar_mode_r(bsdar); 345 break; 346 case 't': 347 exitcode = ar_mode_t(bsdar); 348 break; 349 case 'x': 350 exitcode = ar_mode_x(bsdar); 351 break; | |
352 default: 353 bsdar_usage(); 354 /* NOTREACHED */ 355 } 356 357 for (i = 0; i < bsdar->argc; i++) { 358 if (bsdar->argv[i] != NULL) { 359 bsdar_warnc(bsdar, 0, "%s: not found in archive", --- 5 unchanged lines hidden (view full) --- 365 exit(exitcode); 366} 367 368static void 369set_mode(struct bsdar *bsdar, char opt) 370{ 371 372 if (bsdar->mode != '\0' && bsdar->mode != opt) | 332 default: 333 bsdar_usage(); 334 /* NOTREACHED */ 335 } 336 337 for (i = 0; i < bsdar->argc; i++) { 338 if (bsdar->argv[i] != NULL) { 339 bsdar_warnc(bsdar, 0, "%s: not found in archive", --- 5 unchanged lines hidden (view full) --- 345 exit(exitcode); 346} 347 348static void 349set_mode(struct bsdar *bsdar, char opt) 350{ 351 352 if (bsdar->mode != '\0' && bsdar->mode != opt) |
373 bsdar_errc(bsdar, EXIT_FAILURE, 0, 374 "Can't specify both -%c and -%c", opt, bsdar->mode); | 353 bsdar_errc(bsdar, 0, "Can't specify both -%c and -%c", 354 opt, bsdar->mode); |
375 bsdar->mode = opt; 376} 377 378static void 379only_mode(struct bsdar *bsdar, const char *opt, const char *valid_modes) 380{ 381 382 if (strchr(valid_modes, bsdar->mode) == NULL) | 355 bsdar->mode = opt; 356} 357 358static void 359only_mode(struct bsdar *bsdar, const char *opt, const char *valid_modes) 360{ 361 362 if (strchr(valid_modes, bsdar->mode) == NULL) |
383 bsdar_errc(bsdar, EXIT_FAILURE, 0, 384 "Option %s is not permitted in mode -%c", opt, bsdar->mode); | 363 bsdar_errc(bsdar, 0, "Option %s is not permitted in mode -%c", 364 opt, bsdar->mode); |
385} 386 387static void 388bsdar_usage(void) 389{ 390 391 (void)fprintf(stderr, "usage: ar -d [-Tjsvz] archive file ...\n"); 392 (void)fprintf(stderr, "\tar -m [-Tjsvz] archive file ...\n"); --- 34 unchanged lines hidden --- | 365} 366 367static void 368bsdar_usage(void) 369{ 370 371 (void)fprintf(stderr, "usage: ar -d [-Tjsvz] archive file ...\n"); 372 (void)fprintf(stderr, "\tar -m [-Tjsvz] archive file ...\n"); --- 34 unchanged lines hidden --- |