dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / libast / common / path / pathgetlink.c
bloba2fbd41d477d6e4477309547dea804c7168395a6
1 /***********************************************************************
2 * *
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
8 * *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
12 * *
13 * Information and Software Systems Research *
14 * AT&T Research *
15 * Florham Park NJ *
16 * *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
20 * *
21 ***********************************************************************/
22 #pragma prototyped
24 * Glenn Fowler
25 * AT&T Bell Laboratories
28 #include "univlib.h"
30 #ifdef UNIV_MAX
32 #include <ctype.h>
34 #endif
37 * return external representation for symbolic link text of name in buf
38 * the link text string length is returned
41 int
42 pathgetlink(const char* name, char* buf, int siz)
44 int n;
46 if ((n = readlink(name, buf, siz)) < 0) return(-1);
47 if (n >= siz)
49 errno = EINVAL;
50 return(-1);
52 buf[n] = 0;
53 #ifdef UNIV_MAX
54 if (isspace(*buf))
56 register char* s;
57 register char* t;
58 register char* u;
59 register char* v;
60 int match = 0;
61 char tmp[PATH_MAX];
63 s = buf;
64 t = tmp;
65 while (isalnum(*++s) || *s == '_' || *s == '.');
66 if (*s++)
68 for (;;)
70 if (!*s || isspace(*s))
72 if (match)
74 *t = 0;
75 n = t - tmp;
76 strcpy(buf, tmp);
78 break;
80 if (t >= &tmp[sizeof(tmp)]) break;
81 *t++ = *s++;
82 if (!match && t < &tmp[sizeof(tmp) - univ_size + 1]) for (n = 0; n < UNIV_MAX; n++)
84 if (*(v = s - 1) == *(u = univ_name[n]))
86 while (*u && *v++ == *u) u++;
87 if (!*u)
89 match = 1;
90 strcpy(t - 1, univ_cond);
91 t += univ_size - 1;
92 s = v;
93 break;
100 #endif
101 return(n);