1da2e3ebdSchin /*********************************************************************** 2da2e3ebdSchin * * 3da2e3ebdSchin * This software is part of the ast package * 4*3e14f97fSRoger A. Faulkner * Copyright (c) 1985-2010 AT&T Intellectual Property * 5da2e3ebdSchin * and is licensed under the * 6da2e3ebdSchin * Common Public License, Version 1.0 * 77c2fbfb3SApril Chin * by AT&T Intellectual Property * 8da2e3ebdSchin * * 9da2e3ebdSchin * A copy of the License is available at * 10da2e3ebdSchin * http://www.opensource.org/licenses/cpl1.0.txt * 11da2e3ebdSchin * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 12da2e3ebdSchin * * 13da2e3ebdSchin * Information and Software Systems Research * 14da2e3ebdSchin * AT&T Research * 15da2e3ebdSchin * Florham Park NJ * 16da2e3ebdSchin * * 17da2e3ebdSchin * Glenn Fowler <gsf@research.att.com> * 18da2e3ebdSchin * David Korn <dgk@research.att.com> * 19da2e3ebdSchin * Phong Vo <kpv@research.att.com> * 20da2e3ebdSchin * * 21da2e3ebdSchin ***********************************************************************/ 22da2e3ebdSchin #pragma prototyped 23da2e3ebdSchin /* 24da2e3ebdSchin * Glenn Fowler 25da2e3ebdSchin * AT&T Bell Laboratories 26da2e3ebdSchin */ 27da2e3ebdSchin 28da2e3ebdSchin #include "univlib.h" 29da2e3ebdSchin 30da2e3ebdSchin #ifdef UNIV_MAX 31da2e3ebdSchin 32da2e3ebdSchin #include <ctype.h> 33da2e3ebdSchin 34da2e3ebdSchin #endif 35da2e3ebdSchin 36da2e3ebdSchin /* 37da2e3ebdSchin * return external representation for symbolic link text of name in buf 38da2e3ebdSchin * the link text string length is returned 39da2e3ebdSchin */ 40da2e3ebdSchin 41da2e3ebdSchin int pathgetlink(const char * name,char * buf,int siz)42da2e3ebdSchinpathgetlink(const char* name, char* buf, int siz) 43da2e3ebdSchin { 44da2e3ebdSchin int n; 45da2e3ebdSchin 46da2e3ebdSchin if ((n = readlink(name, buf, siz)) < 0) return(-1); 47da2e3ebdSchin if (n >= siz) 48da2e3ebdSchin { 49da2e3ebdSchin errno = EINVAL; 50da2e3ebdSchin return(-1); 51da2e3ebdSchin } 52da2e3ebdSchin buf[n] = 0; 53da2e3ebdSchin #ifdef UNIV_MAX 54da2e3ebdSchin if (isspace(*buf)) 55da2e3ebdSchin { 56da2e3ebdSchin register char* s; 57da2e3ebdSchin register char* t; 58da2e3ebdSchin register char* u; 59da2e3ebdSchin register char* v; 60da2e3ebdSchin int match = 0; 61da2e3ebdSchin char tmp[PATH_MAX]; 62da2e3ebdSchin 63da2e3ebdSchin s = buf; 64da2e3ebdSchin t = tmp; 65da2e3ebdSchin while (isalnum(*++s) || *s == '_' || *s == '.'); 66da2e3ebdSchin if (*s++) 67da2e3ebdSchin { 68da2e3ebdSchin for (;;) 69da2e3ebdSchin { 70da2e3ebdSchin if (!*s || isspace(*s)) 71da2e3ebdSchin { 72da2e3ebdSchin if (match) 73da2e3ebdSchin { 74da2e3ebdSchin *t = 0; 75da2e3ebdSchin n = t - tmp; 76da2e3ebdSchin strcpy(buf, tmp); 77da2e3ebdSchin } 78da2e3ebdSchin break; 79da2e3ebdSchin } 80da2e3ebdSchin if (t >= &tmp[sizeof(tmp)]) break; 81da2e3ebdSchin *t++ = *s++; 82da2e3ebdSchin if (!match && t < &tmp[sizeof(tmp) - univ_size + 1]) for (n = 0; n < UNIV_MAX; n++) 83da2e3ebdSchin { 84da2e3ebdSchin if (*(v = s - 1) == *(u = univ_name[n])) 85da2e3ebdSchin { 86da2e3ebdSchin while (*u && *v++ == *u) u++; 87da2e3ebdSchin if (!*u) 88da2e3ebdSchin { 89da2e3ebdSchin match = 1; 90da2e3ebdSchin strcpy(t - 1, univ_cond); 91da2e3ebdSchin t += univ_size - 1; 92da2e3ebdSchin s = v; 93da2e3ebdSchin break; 94da2e3ebdSchin } 95da2e3ebdSchin } 96da2e3ebdSchin } 97da2e3ebdSchin } 98da2e3ebdSchin } 99da2e3ebdSchin } 100da2e3ebdSchin #endif 101da2e3ebdSchin return(n); 102da2e3ebdSchin } 103