/***********************************************************************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* Glenn Fowler24* AT&T Research25*26* convert native path to posix fs representation in <buf,siz>27* length of converted path returned28* if return length >= siz then buf is indeterminate, but another call29* with siz=length+1 would work30* if buf==0 then required size is returned31*/3233#include <ast.h>3435#if _UWIN3637#include <uwin.h>3839size_t40pathposix(const char* path, char* buf, size_t siz)41{42return uwin_unpath(path, buf, siz);43}4445#else4647#if __CYGWIN__4849extern void cygwin_conv_to_posix_path(const char*, char*);5051size_t52pathposix(const char* path, char* buf, size_t siz)53{54size_t n;5556if (!buf || siz < PATH_MAX)57{58char tmp[PATH_MAX];5960cygwin_conv_to_posix_path(path, tmp);61if ((n = strlen(tmp)) < siz && buf)62memcpy(buf, tmp, n + 1);63return n;64}65cygwin_conv_to_posix_path(path, buf);66return strlen(buf);67}6869#else7071#if __EMX__ && 0 /* show me the docs */7273size_t74pathposix(const char* path, char* buf, size_t siz)75{76char* s;77size_t n;7879if (!_posixpath(buf, path, siz))80{81for (s = buf; *s; s++)82if (*s == '/')83*s = '\\';84}85else if ((n = strlen(path)) < siz && buf)86memcpy(buf, path, n + 1);87return n;88}8990#else9192#if __INTERIX9394#include <interix/interix.h>9596size_t97pathposix(const char* path, char *buf, size_t siz)98{99static const char pfx[] = "/dev/fs";100101*buf = 0;102if (!strncasecmp(path, pfx, sizeof(pfx) - 1))103strlcpy(buf, path, siz);104else105winpath2unix(path, PATH_NONSTRICT, buf, siz);106return strlen(buf);107}108109#else110111size_t112pathposix(const char* path, char* buf, size_t siz)113{114size_t n;115116if ((n = strlen(path)) < siz && buf)117memcpy(buf, path, n + 1);118return n;119}120121#endif122123#endif124125#endif126127#endif128129130