Blame


1 70bcc780 2004-03-25 devnull #include <u.h>
2 70bcc780 2004-03-25 devnull #include <libc.h>
3 70bcc780 2004-03-25 devnull
4 70bcc780 2004-03-25 devnull /*
5 70bcc780 2004-03-25 devnull * I don't want too many of these,
6 fa325e9b 2020-01-10 cross * but the ones we have are just too useful.
7 70bcc780 2004-03-25 devnull */
8 70bcc780 2004-03-25 devnull static struct {
9 70bcc780 2004-03-25 devnull char *old;
10 70bcc780 2004-03-25 devnull char *new;
11 70bcc780 2004-03-25 devnull } replace[] = {
12 70bcc780 2004-03-25 devnull "#9", nil, /* must be first */
13 70bcc780 2004-03-25 devnull "#d", "/dev/fd",
14 70bcc780 2004-03-25 devnull };
15 70bcc780 2004-03-25 devnull
16 70bcc780 2004-03-25 devnull char*
17 70bcc780 2004-03-25 devnull unsharp(char *old)
18 70bcc780 2004-03-25 devnull {
19 70bcc780 2004-03-25 devnull char *new;
20 70bcc780 2004-03-25 devnull int i, olen, nlen, len;
21 70bcc780 2004-03-25 devnull
22 70bcc780 2004-03-25 devnull if(replace[0].new == nil)
23 70bcc780 2004-03-25 devnull replace[0].new = get9root();
24 70bcc780 2004-03-25 devnull
25 70bcc780 2004-03-25 devnull for(i=0; i<nelem(replace); i++){
26 70bcc780 2004-03-25 devnull if(!replace[i].new)
27 70bcc780 2004-03-25 devnull continue;
28 70bcc780 2004-03-25 devnull olen = strlen(replace[i].old);
29 70bcc780 2004-03-25 devnull if(strncmp(old, replace[i].old, olen) != 0
30 70bcc780 2004-03-25 devnull || (old[olen] != '\0' && old[olen] != '/'))
31 70bcc780 2004-03-25 devnull continue;
32 70bcc780 2004-03-25 devnull nlen = strlen(replace[i].new);
33 70bcc780 2004-03-25 devnull len = strlen(old)+nlen-olen;
34 70bcc780 2004-03-25 devnull new = malloc(len+1);
35 70bcc780 2004-03-25 devnull if(new == nil)
36 70bcc780 2004-03-25 devnull /* Most callers won't check the return value... */
37 70bcc780 2004-03-25 devnull sysfatal("out of memory translating %s to %s%s", old, replace[i].new, old+olen);
38 70bcc780 2004-03-25 devnull strcpy(new, replace[i].new);
39 70bcc780 2004-03-25 devnull strcpy(new+nlen, old+olen);
40 70bcc780 2004-03-25 devnull assert(strlen(new) == len);
41 70bcc780 2004-03-25 devnull return new;
42 70bcc780 2004-03-25 devnull }
43 70bcc780 2004-03-25 devnull return old;
44 70bcc780 2004-03-25 devnull }