/***********************************************************************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 path to native 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 _UWIN3637extern int uwin_path(const char*, char*, int);3839size_t40pathnative(const char* path, char* buf, size_t siz)41{42return uwin_path(path, buf, siz);43}4445#else4647#if __CYGWIN__4849extern void cygwin_conv_to_win32_path(const char*, char*);5051size_t52pathnative(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_win32_path(path, tmp);61if ((n = strlen(tmp)) < siz && buf)62memcpy(buf, tmp, n + 1);63return n;64}65cygwin_conv_to_win32_path(path, buf);66return strlen(buf);67}6869#else7071#if __EMX__7273size_t74pathnative(const char* path, char* buf, size_t siz)75{76char* s;77size_t n;7879if (!_fullpath(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_t97pathnative(const char* path, char* buf, size_t siz)98{99*buf = 0;100if (path[1] == ':')101strlcpy(buf, path, siz);102else103unixpath2win(path, 0, buf, siz);104return strlen(buf);105}106107#else108109size_t110pathnative(const char* path, char* buf, size_t siz)111{112size_t n;113114if ((n = strlen(path)) < siz && buf)115memcpy(buf, path, n + 1);116return n;117}118119#endif120121#endif122123#endif124125#endif126127128