Portable build framework for OpenNTPD
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.2 KiB

  1. /*
  2. * Copyright (c) 1999-2004 Damien Miller <djm@mindrot.org>
  3. *
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #include <string.h>
  17. #ifndef HAVE___PROGNAME
  18. char *__progname;
  19. #endif
  20. /*
  21. * NB. duplicate __progname in case it is an alias for argv[0]
  22. * Otherwise it may get clobbered by setproctitle()
  23. */
  24. char *get_progname(char *argv0)
  25. {
  26. #ifdef HAVE___PROGNAME
  27. extern char *__progname;
  28. return strdup(__progname);
  29. #else
  30. char *p;
  31. if (argv0 == NULL)
  32. return ("unknown"); /* XXX */
  33. p = strrchr(argv0, '/');
  34. if (p == NULL)
  35. p = argv0;
  36. else
  37. p++;
  38. return (strdup(p));
  39. #endif
  40. }