/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1985-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* David Korn <[email protected]> *18* Phong Vo <[email protected]> *19* *20***********************************************************************/21#pragma prototyped22/*23* dirname(3) implementation24*/2526#include <ast_std.h>2728#if defined(__EXPORT__)29#define extern __EXPORT__30#endif3132extern char *dirname(register char *pathname)33{34register char *last;35/* go to end of path */36for(last=pathname; *last; last++);37/* back over trailing '/' */38while(last>pathname && *--last=='/');39/* back over non-slash chars */40for(;last>pathname && *last!='/';last--);41if(last==pathname)42{43/* all '/' or "" */44if(*last!='/')45*last = '.';46/* preserve // */47else if(last[1]=='/')48last++;49}50else51{52/* back over trailing '/' */53for(;*last=='/' && last > pathname; last--);54/* preserve // */55if(last==pathname && *pathname=='/' && pathname[1]=='/')56last++;57}58*(last + 1) = 0;59return(pathname);60}616263