OSDN Git Service

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