getopt_allopts.c 535 B

123456789101112131415161718192021222324252627
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Copyright (C) 2017 Denys Vlasenko
  4. *
  5. * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  6. */
  7. #include "libbb.h"
  8. //kbuild:lib-y += getopt_allopts.o
  9. void FAST_FUNC make_all_argv_opts(char **argv)
  10. {
  11. /* Note: we skip argv[0] */
  12. while (*++argv) {
  13. char *p;
  14. if (argv[0][0] == '-')
  15. continue;
  16. /* Neither top nor ps care if "" arg turns into "-" */
  17. /*if (argv[0][0] == '\0')
  18. continue;*/
  19. p = xmalloc(strlen(*argv) + 2);
  20. *p = '-';
  21. strcpy(p + 1, *argv);
  22. *argv = p;
  23. }
  24. }