options.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright 2018 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the OpenSSL license (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include "../testutil.h"
  10. #include "internal/nelem.h"
  11. #include "tu_local.h"
  12. #include "output.h"
  13. static int used[100] = { 0 };
  14. size_t test_get_argument_count(void)
  15. {
  16. return opt_num_rest();
  17. }
  18. char *test_get_argument(size_t n)
  19. {
  20. char **argv = opt_rest();
  21. OPENSSL_assert(n < sizeof(used));
  22. if ((int)n >= opt_num_rest() || argv == NULL)
  23. return NULL;
  24. used[n] = 1;
  25. return argv[n];
  26. }
  27. void opt_check_usage(void)
  28. {
  29. int i;
  30. char **argv = opt_rest();
  31. int n, arg_count = opt_num_rest();
  32. if (arg_count > (int)OSSL_NELEM(used))
  33. n = (int)OSSL_NELEM(used);
  34. else
  35. n = arg_count;
  36. for (i = 0; i < n; i++) {
  37. if (used[i] == 0)
  38. test_printf_stderr("Warning ignored command-line argument %d: %s\n",
  39. i, argv[i]);
  40. }
  41. if (i < arg_count)
  42. test_printf_stderr("Warning arguments %d and later unchecked\n", i);
  43. }
  44. int opt_printf_stderr(const char *fmt, ...)
  45. {
  46. va_list ap;
  47. int ret;
  48. va_start(ap, fmt);
  49. ret = test_vprintf_stderr(fmt, ap);
  50. va_end(ap);
  51. return ret;
  52. }