|
Lines 56-62
Link Here
|
| 56 |
int argc; |
56 |
int argc; |
| 57 |
char **argv; |
57 |
char **argv; |
| 58 |
{ |
58 |
{ |
| 59 |
char *p, *q; |
59 |
char *p; |
| 60 |
int ch; |
60 |
int ch; |
| 61 |
|
61 |
|
| 62 |
while ((ch = getopt(argc, argv, "")) != -1) |
62 |
while ((ch = getopt(argc, argv, "")) != -1) |
|
Lines 73-80
Link Here
|
| 73 |
|
73 |
|
| 74 |
if ((p = basename(argv[0])) == NULL) |
74 |
if ((p = basename(argv[0])) == NULL) |
| 75 |
err(1, "%s", argv[0]); |
75 |
err(1, "%s", argv[0]); |
| 76 |
if (*++argv && (q = strstr(p, *argv)) && strcmp(q, *argv) == 0) |
76 |
|
| 77 |
*q = '\0'; |
77 |
/* |
|
|
78 |
* If the suffix operand is present, is not identical to the |
| 79 |
* characters remaining in string, and is identical to a suffix |
| 80 |
* of the characters remaining in string, the suffix |
| 81 |
* shall be removed from string. |
| 82 |
*/ |
| 83 |
if (*++argv) { |
| 84 |
int suffixlen, stringlen, off; |
| 85 |
|
| 86 |
suffixlen = strlen(*argv); |
| 87 |
stringlen = strlen(p); |
| 88 |
|
| 89 |
if (suffixlen < stringlen) { |
| 90 |
off = stringlen - suffixlen; |
| 91 |
if (!strcmp(p + off, *argv)) |
| 92 |
p[off] = '\0'; |
| 93 |
} |
| 94 |
} |
| 78 |
(void)printf("%s\n", p); |
95 |
(void)printf("%s\n", p); |
| 79 |
exit(0); |
96 |
exit(0); |
| 80 |
} |
97 |
} |