1
0

inststr.c 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * inststr.c
  3. *
  4. * Little function to change the name of a process
  5. *
  6. * Originally from C. S. Ananian's pptpclient
  7. */
  8. #ifdef HAVE_CONFIG_H
  9. #include "config.h"
  10. #endif
  11. #ifndef HAVE_SETPROCTITLE
  12. #include "inststr.h"
  13. #include "compat.h"
  14. #include <string.h>
  15. void inststr(int argc, char **argv, char *src)
  16. {
  17. if (strlen(src) <= strlen(argv[0])) {
  18. char *ptr, **pptr;
  19. for (ptr = argv[0]; *ptr; *(ptr++) = '\0')
  20. ;
  21. strcpy(argv[0], src);
  22. for (pptr = argv + 1; *pptr; pptr++)
  23. for (ptr = *pptr; *ptr; *(ptr++) = '\0')
  24. ;
  25. } else {
  26. /* Originally from the source to perl 4.036 (assigning to $0) */
  27. char *ptr, *ptr2;
  28. int count;
  29. ptr = argv[0] + strlen(argv[0]);
  30. for (count = 1; count < argc; count++) {
  31. if (argv[count] == ptr + 1) {
  32. ptr++;
  33. ptr += strlen(ptr);
  34. }
  35. }
  36. count = 0;
  37. for (ptr2 = argv[0]; ptr2 <= ptr; ptr2++) {
  38. *ptr2 = '\0';
  39. count++;
  40. }
  41. strlcpy(argv[0], src, count);
  42. }
  43. }
  44. #endif /* !HAVE_SETPROCTITLE */