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