1N/A/***********************************************************************
1N/A* *
1N/A* This software is part of the ast package *
1N/A* Copyright (c) 1985-2011 AT&T Intellectual Property *
1N/A* and is licensed under the *
1N/A* Common Public License, Version 1.0 *
1N/A* by AT&T Intellectual Property *
1N/A* *
1N/A* A copy of the License is available at *
1N/A* http://www.opensource.org/licenses/cpl1.0.txt *
1N/A* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
1N/A* *
1N/A* Information and Software Systems Research *
1N/A* AT&T Research *
1N/A* Florham Park NJ *
1N/A* *
1N/A* Glenn Fowler <gsf@research.att.com> *
1N/A* David Korn <dgk@research.att.com> *
1N/A* Phong Vo <kpv@research.att.com> *
1N/A* *
1N/A***********************************************************************/
1N/A#pragma prototyped
1N/A/*
1N/A* Glenn Fowler
1N/A* AT&T Bell Laboratories
1N/A*/
1N/A
1N/A#include "univlib.h"
1N/A
1N/A#ifdef UNIV_MAX
1N/A
1N/A#include <ctype.h>
1N/A
1N/A#endif
1N/A
1N/A/*
1N/A * return external representation for symbolic link text of name in buf
1N/A * the link text string length is returned
1N/A */
1N/A
1N/Aint
1N/Apathgetlink(const char* name, char* buf, int siz)
1N/A{
1N/A int n;
1N/A
1N/A if ((n = readlink(name, buf, siz)) < 0) return(-1);
1N/A if (n >= siz)
1N/A {
1N/A errno = EINVAL;
1N/A return(-1);
1N/A }
1N/A buf[n] = 0;
1N/A#ifdef UNIV_MAX
1N/A if (isspace(*buf))
1N/A {
1N/A register char* s;
1N/A register char* t;
1N/A register char* u;
1N/A register char* v;
1N/A int match = 0;
1N/A char tmp[PATH_MAX];
1N/A
1N/A s = buf;
1N/A t = tmp;
1N/A while (isalnum(*++s) || *s == '_' || *s == '.');
1N/A if (*s++)
1N/A {
1N/A for (;;)
1N/A {
1N/A if (!*s || isspace(*s))
1N/A {
1N/A if (match)
1N/A {
1N/A *t = 0;
1N/A n = t - tmp;
1N/A strcpy(buf, tmp);
1N/A }
1N/A break;
1N/A }
1N/A if (t >= &tmp[sizeof(tmp)]) break;
1N/A *t++ = *s++;
1N/A if (!match && t < &tmp[sizeof(tmp) - univ_size + 1]) for (n = 0; n < UNIV_MAX; n++)
1N/A {
1N/A if (*(v = s - 1) == *(u = univ_name[n]))
1N/A {
1N/A while (*u && *v++ == *u) u++;
1N/A if (!*u)
1N/A {
1N/A match = 1;
1N/A strcpy(t - 1, univ_cond);
1N/A t += univ_size - 1;
1N/A s = v;
1N/A break;
1N/A }
1N/A }
1N/A }
1N/A }
1N/A }
1N/A }
1N/A#endif
1N/A return(n);
1N/A}