Deleted Added
full compact
main.c (299529) main.c (302075)
1/*
2 * Copyright (c) 2003-2009 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

--- 46 unchanged lines hidden (view full) ---

55
56/*
57 * This same file is used pretty much verbatim for all test harnesses.
58 *
59 * The next few lines are the only differences.
60 * TODO: Move this into a separate configuration header, have all test
61 * suites share one copy of this file.
62 */
1/*
2 * Copyright (c) 2003-2009 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

--- 46 unchanged lines hidden (view full) ---

55
56/*
57 * This same file is used pretty much verbatim for all test harnesses.
58 *
59 * The next few lines are the only differences.
60 * TODO: Move this into a separate configuration header, have all test
61 * suites share one copy of this file.
62 */
63__FBSDID("$FreeBSD: head/contrib/libarchive/tar/test/main.c 299529 2016-05-12 10:16:16Z mm $");
63__FBSDID("$FreeBSD: head/contrib/libarchive/tar/test/main.c 302075 2016-06-22 07:49:59Z mm $");
64#define KNOWNREF "test_patterns_2.tar.uu"
65#define ENVBASE "BSDTAR" /* Prefix for environment variables. */
66#define PROGRAM "bsdtar" /* Name of program being tested. */
67#define PROGRAM_ALIAS "tar" /* Generic alias for program */
68#undef LIBRARY /* Not testing a library. */
69#undef EXTRA_DUMP /* How to dump extra data */
70#undef EXTRA_ERRNO /* How to dump errno */
71/* How to generate extra version info. */

--- 2458 unchanged lines hidden (view full) ---

2530 for (i = 0; i < limit; i++)
2531 printf(" %d: %s\n", i, tests[i].name);
2532 exit(1);
2533}
2534
2535static char *
2536get_refdir(const char *d)
2537{
64#define KNOWNREF "test_patterns_2.tar.uu"
65#define ENVBASE "BSDTAR" /* Prefix for environment variables. */
66#define PROGRAM "bsdtar" /* Name of program being tested. */
67#define PROGRAM_ALIAS "tar" /* Generic alias for program */
68#undef LIBRARY /* Not testing a library. */
69#undef EXTRA_DUMP /* How to dump extra data */
70#undef EXTRA_ERRNO /* How to dump errno */
71/* How to generate extra version info. */

--- 2458 unchanged lines hidden (view full) ---

2530 for (i = 0; i < limit; i++)
2531 printf(" %d: %s\n", i, tests[i].name);
2532 exit(1);
2533}
2534
2535static char *
2536get_refdir(const char *d)
2537{
2538 char tried[512] = { '\0' };
2539 char buff[128];
2540 char *pwd, *p;
2538 size_t tried_size, buff_size;
2539 char *buff, *tried, *pwd = NULL, *p = NULL;
2541
2540
2541#ifdef PATH_MAX
2542 buff_size = PATH_MAX;
2543#else
2544 buff_size = 8192;
2545#endif
2546 buff = calloc(buff_size, 1);
2547 if (buff == NULL) {
2548 fprintf(stderr, "Unable to allocate memory\n");
2549 exit(1);
2550 }
2551
2552 /* Allocate a buffer to hold the various directories we checked. */
2553 tried_size = buff_size * 2;
2554 tried = calloc(tried_size, 1);
2555 if (tried == NULL) {
2556 fprintf(stderr, "Unable to allocate memory\n");
2557 exit(1);
2558 }
2559
2542 /* If a dir was specified, try that */
2543 if (d != NULL) {
2544 pwd = NULL;
2560 /* If a dir was specified, try that */
2561 if (d != NULL) {
2562 pwd = NULL;
2545 snprintf(buff, sizeof(buff), "%s", d);
2563 snprintf(buff, buff_size, "%s", d);
2546 p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
2547 if (p != NULL) goto success;
2564 p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
2565 if (p != NULL) goto success;
2548 strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
2549 strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
2566 strncat(tried, buff, tried_size - strlen(tried) - 1);
2567 strncat(tried, "\n", tried_size - strlen(tried) - 1);
2550 goto failure;
2551 }
2552
2553 /* Get the current dir. */
2554#ifdef PATH_MAX
2555 pwd = getcwd(NULL, PATH_MAX);/* Solaris getcwd needs the size. */
2556#else
2557 pwd = getcwd(NULL, 0);
2558#endif
2559 while (pwd[strlen(pwd) - 1] == '\n')
2560 pwd[strlen(pwd) - 1] = '\0';
2561
2562 /* Look for a known file. */
2568 goto failure;
2569 }
2570
2571 /* Get the current dir. */
2572#ifdef PATH_MAX
2573 pwd = getcwd(NULL, PATH_MAX);/* Solaris getcwd needs the size. */
2574#else
2575 pwd = getcwd(NULL, 0);
2576#endif
2577 while (pwd[strlen(pwd) - 1] == '\n')
2578 pwd[strlen(pwd) - 1] = '\0';
2579
2580 /* Look for a known file. */
2563 snprintf(buff, sizeof(buff), "%s", pwd);
2581 snprintf(buff, buff_size, "%s", pwd);
2564 p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
2565 if (p != NULL) goto success;
2582 p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
2583 if (p != NULL) goto success;
2566 strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
2567 strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
2584 strncat(tried, buff, tried_size - strlen(tried) - 1);
2585 strncat(tried, "\n", tried_size - strlen(tried) - 1);
2568
2586
2569 snprintf(buff, sizeof(buff), "%s/test", pwd);
2587 snprintf(buff, buff_size, "%s/test", pwd);
2570 p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
2571 if (p != NULL) goto success;
2588 p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
2589 if (p != NULL) goto success;
2572 strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
2573 strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
2590 strncat(tried, buff, tried_size - strlen(tried) - 1);
2591 strncat(tried, "\n", tried_size - strlen(tried) - 1);
2574
2575#if defined(LIBRARY)
2592
2593#if defined(LIBRARY)
2576 snprintf(buff, sizeof(buff), "%s/%s/test", pwd, LIBRARY);
2594 snprintf(buff, buff_size, "%s/%s/test", pwd, LIBRARY);
2577#else
2595#else
2578 snprintf(buff, sizeof(buff), "%s/%s/test", pwd, PROGRAM);
2596 snprintf(buff, buff_size, "%s/%s/test", pwd, PROGRAM);
2579#endif
2580 p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
2581 if (p != NULL) goto success;
2597#endif
2598 p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
2599 if (p != NULL) goto success;
2582 strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
2583 strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
2600 strncat(tried, buff, tried_size - strlen(tried) - 1);
2601 strncat(tried, "\n", tried_size - strlen(tried) - 1);
2584
2585#if defined(PROGRAM_ALIAS)
2602
2603#if defined(PROGRAM_ALIAS)
2586 snprintf(buff, sizeof(buff), "%s/%s/test", pwd, PROGRAM_ALIAS);
2604 snprintf(buff, buff_size, "%s/%s/test", pwd, PROGRAM_ALIAS);
2587 p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
2588 if (p != NULL) goto success;
2605 p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
2606 if (p != NULL) goto success;
2589 strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
2590 strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
2607 strncat(tried, buff, tried_size - strlen(tried) - 1);
2608 strncat(tried, "\n", tried_size - strlen(tried) - 1);
2591#endif
2592
2593 if (memcmp(pwd, "/usr/obj", 8) == 0) {
2609#endif
2610
2611 if (memcmp(pwd, "/usr/obj", 8) == 0) {
2594 snprintf(buff, sizeof(buff), "%s", pwd + 8);
2612 snprintf(buff, buff_size, "%s", pwd + 8);
2595 p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
2596 if (p != NULL) goto success;
2613 p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
2614 if (p != NULL) goto success;
2597 strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
2598 strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
2615 strncat(tried, buff, tried_size - strlen(tried) - 1);
2616 strncat(tried, "\n", tried_size - strlen(tried) - 1);
2599
2617
2600 snprintf(buff, sizeof(buff), "%s/test", pwd + 8);
2618 snprintf(buff, buff_size, "%s/test", pwd + 8);
2601 p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
2602 if (p != NULL) goto success;
2619 p = slurpfile(NULL, "%s/%s", buff, KNOWNREF);
2620 if (p != NULL) goto success;
2603 strncat(tried, buff, sizeof(tried) - strlen(tried) - 1);
2604 strncat(tried, "\n", sizeof(tried) - strlen(tried) - 1);
2621 strncat(tried, buff, tried_size - strlen(tried) - 1);
2622 strncat(tried, "\n", tried_size - strlen(tried) - 1);
2605 }
2606
2607failure:
2608 printf("Unable to locate known reference file %s\n", KNOWNREF);
2609 printf(" Checked following directories:\n%s\n", tried);
2610 printf("Use -r option to specify full path to reference directory\n");
2611#if defined(_WIN32) && !defined(__CYGWIN__) && defined(_DEBUG)
2612 DebugBreak();
2613#endif
2614 exit(1);
2615
2616success:
2617 free(p);
2618 free(pwd);
2623 }
2624
2625failure:
2626 printf("Unable to locate known reference file %s\n", KNOWNREF);
2627 printf(" Checked following directories:\n%s\n", tried);
2628 printf("Use -r option to specify full path to reference directory\n");
2629#if defined(_WIN32) && !defined(__CYGWIN__) && defined(_DEBUG)
2630 DebugBreak();
2631#endif
2632 exit(1);
2633
2634success:
2635 free(p);
2636 free(pwd);
2619 return strdup(buff);
2637 free(tried);
2638
2639 /* Copy result into a fresh buffer to reduce memory usage. */
2640 p = strdup(buff);
2641 free(buff);
2642 return p;
2620}
2621
2622int
2623main(int argc, char **argv)
2624{
2625 static const int limit = sizeof(tests) / sizeof(tests[0]);
2626 int test_set[sizeof(tests) / sizeof(tests[0])];
2627 int i = 0, j = 0, tests_run = 0, tests_failed = 0, option;

--- 343 unchanged lines hidden ---
2643}
2644
2645int
2646main(int argc, char **argv)
2647{
2648 static const int limit = sizeof(tests) / sizeof(tests[0]);
2649 int test_set[sizeof(tests) / sizeof(tests[0])];
2650 int i = 0, j = 0, tests_run = 0, tests_failed = 0, option;

--- 343 unchanged lines hidden ---