~ubuntu-branches/ubuntu/lucid/graphviz/lucid-security

« back to all changes in this revision

Viewing changes to tools/ast/pathgetlink.c

  • Committer: Bazaar Package Importer
  • Author(s): Stephen M Moraco
  • Date: 2002-02-05 18:52:12 UTC
  • Revision ID: james.westby@ubuntu.com-20020205185212-8i04c70te00rc40y
Tags: upstream-1.7.16
ImportĀ upstreamĀ versionĀ 1.7.16

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#pragma prototyped
 
2
/*
 
3
* Glenn Fowler
 
4
* AT&T Bell Laboratories
 
5
*/
 
6
 
 
7
/* #include "univlib.h" */
 
8
#include "errno.h"
 
9
 
 
10
#ifdef UNIV_MAX
 
11
 
 
12
#include <ctype.h>
 
13
 
 
14
#endif
 
15
 
 
16
/*
 
17
 * return external representation for symbolic link text of name in buf
 
18
 * the link text string length is returned
 
19
 */
 
20
 
 
21
int
 
22
pathgetlink(const char* name, char* buf, int siz)
 
23
{
 
24
        int     n;
 
25
 
 
26
        if ((n = readlink(name, buf, siz)) < 0) return(-1);
 
27
        if (n >= siz)
 
28
        {
 
29
                errno = EINVAL;
 
30
                return(-1);
 
31
        }
 
32
        buf[n] = 0;
 
33
#ifdef UNIV_MAX
 
34
        if (isspace(*buf))
 
35
        {
 
36
                register char*  s;
 
37
                register char*  t;
 
38
                register char*  u;
 
39
                register char*  v;
 
40
                int             match = 0;
 
41
                char            tmp[PATH_MAX];
 
42
 
 
43
                s = buf;
 
44
                t = tmp;
 
45
                while (isalnum(*++s) || *s == '_' || *s == '.');
 
46
                if (*s++)
 
47
                {
 
48
                        for (;;)
 
49
                        {
 
50
                                if (!*s || isspace(*s))
 
51
                                {
 
52
                                        if (match)
 
53
                                        {
 
54
                                                *t = 0;
 
55
                                                n = t - tmp;
 
56
                                                strcpy(buf, tmp);
 
57
                                        }
 
58
                                        break;
 
59
                                }
 
60
                                if (t >= &tmp[sizeof(tmp)]) break;
 
61
                                *t++ = *s++;
 
62
                                if (!match && t < &tmp[sizeof(tmp) - univ_size + 1]) for (n = 0; n < UNIV_MAX; n++)
 
63
                                {
 
64
                                        if (*(v = s - 1) == *(u = univ_name[n]))
 
65
                                        {
 
66
                                                while (*u && *v++ == *u) u++;
 
67
                                                if (!*u)
 
68
                                                {
 
69
                                                        match = 1;
 
70
                                                        strcpy(t - 1, univ_cond);
 
71
                                                        t += univ_size - 1;
 
72
                                                        s = v;
 
73
                                                        break;
 
74
                                                }
 
75
                                        }
 
76
                                }
 
77
                        }
 
78
                }
 
79
        }
 
80
#endif
 
81
        return(n);
 
82
}