1
0

inststr.c 1020 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. * $Id: inststr.c,v 1.2 2004/04/22 10:48:16 quozl Exp $
  9. */
  10. #ifdef HAVE_CONFIG_H
  11. #include "config.h"
  12. #endif
  13. #ifndef HAVE_SETPROCTITLE
  14. #include "inststr.h"
  15. #include "compat.h"
  16. #include <string.h>
  17. void inststr(int argc, char **argv, char *src)
  18. {
  19. if (strlen(src) <= strlen(argv[0])) {
  20. char *ptr, **pptr;
  21. for (ptr = argv[0]; *ptr; *(ptr++) = '\0')
  22. ;
  23. strcpy(argv[0], src);
  24. for (pptr = argv + 1; *pptr; pptr++)
  25. for (ptr = *pptr; *ptr; *(ptr++) = '\0')
  26. ;
  27. } else {
  28. /* Originally from the source to perl 4.036 (assigning to $0) */
  29. char *ptr, *ptr2;
  30. int count;
  31. ptr = argv[0] + strlen(argv[0]);
  32. for (count = 1; count < argc; count++) {
  33. if (argv[count] == ptr + 1) {
  34. ptr++;
  35. ptr += strlen(ptr);
  36. }
  37. }
  38. count = 0;
  39. for (ptr2 = argv[0]; ptr2 <= ptr; ptr2++) {
  40. *ptr2 = '\0';
  41. count++;
  42. }
  43. strlcpy(argv[0], src, count);
  44. }
  45. }
  46. #endif /* !HAVE_SETPROCTITLE */