14887Schin /***********************************************************************
24887Schin * *
34887Schin * This software is part of the ast package *
4*12068SRoger.Faulkner@Oracle.COM * Copyright (c) 1985-2010 AT&T Intellectual Property *
54887Schin * and is licensed under the *
64887Schin * Common Public License, Version 1.0 *
78462SApril.Chin@Sun.COM * by AT&T Intellectual Property *
84887Schin * *
94887Schin * A copy of the License is available at *
104887Schin * http://www.opensource.org/licenses/cpl1.0.txt *
114887Schin * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
124887Schin * *
134887Schin * Information and Software Systems Research *
144887Schin * AT&T Research *
154887Schin * Florham Park NJ *
164887Schin * *
174887Schin * Glenn Fowler <gsf@research.att.com> *
184887Schin * David Korn <dgk@research.att.com> *
194887Schin * Phong Vo <kpv@research.att.com> *
204887Schin * *
214887Schin ***********************************************************************/
224887Schin #pragma prototyped
234887Schin /*
244887Schin * Glenn Fowler
254887Schin * AT&T Research
264887Schin *
274887Schin * convert native path to posix fs representation in <buf,siz>
284887Schin * length of converted path returned
294887Schin * if return length >= siz then buf is indeterminate, but another call
304887Schin * with siz=length+1 would work
314887Schin * if buf==0 then required size is returned
324887Schin */
334887Schin
344887Schin #include <ast.h>
354887Schin
364887Schin #if _UWIN
374887Schin
384887Schin #include <uwin.h>
394887Schin
404887Schin size_t
pathposix(const char * path,char * buf,size_t siz)414887Schin pathposix(const char* path, char* buf, size_t siz)
424887Schin {
434887Schin return uwin_unpath(path, buf, siz);
444887Schin }
454887Schin
464887Schin #else
474887Schin
484887Schin #if __CYGWIN__
494887Schin
504887Schin extern void cygwin_conv_to_posix_path(const char*, char*);
514887Schin
524887Schin size_t
pathposix(const char * path,char * buf,size_t siz)534887Schin pathposix(const char* path, char* buf, size_t siz)
544887Schin {
554887Schin size_t n;
564887Schin
574887Schin if (!buf || siz < PATH_MAX)
584887Schin {
594887Schin char tmp[PATH_MAX];
604887Schin
614887Schin cygwin_conv_to_posix_path(path, tmp);
624887Schin if ((n = strlen(tmp)) < siz && buf)
634887Schin memcpy(buf, tmp, n + 1);
644887Schin return n;
654887Schin }
664887Schin cygwin_conv_to_posix_path(path, buf);
674887Schin return strlen(buf);
684887Schin }
694887Schin
704887Schin #else
714887Schin
724887Schin #if __EMX__ && 0 /* show me the docs */
734887Schin
744887Schin size_t
pathposix(const char * path,char * buf,size_t siz)754887Schin pathposix(const char* path, char* buf, size_t siz)
764887Schin {
774887Schin char* s;
784887Schin size_t n;
794887Schin
804887Schin if (!_posixpath(buf, path, siz))
814887Schin {
824887Schin for (s = buf; *s; s++)
834887Schin if (*s == '/')
844887Schin *s = '\\';
854887Schin }
864887Schin else if ((n = strlen(path)) < siz && buf)
874887Schin memcpy(buf, path, n + 1);
884887Schin return n;
894887Schin }
904887Schin
914887Schin #else
924887Schin
934887Schin #if __INTERIX
944887Schin
954887Schin #include <interix/interix.h>
964887Schin
974887Schin size_t
pathposix(const char * path,char * buf,size_t siz)984887Schin pathposix(const char* path, char *buf, size_t siz)
994887Schin {
1004887Schin static const char pfx[] = "/dev/fs";
1014887Schin
1024887Schin *buf = 0;
1034887Schin if (!strncasecmp(path, pfx, sizeof(pfx) - 1))
1044887Schin strlcpy(buf, path, siz);
1054887Schin else
1064887Schin winpath2unix(path, PATH_NONSTRICT, buf, siz);
1074887Schin return strlen(buf);
1084887Schin }
1094887Schin
1104887Schin #else
1114887Schin
1124887Schin size_t
pathposix(const char * path,char * buf,size_t siz)1134887Schin pathposix(const char* path, char* buf, size_t siz)
1144887Schin {
1154887Schin size_t n;
1164887Schin
1174887Schin if ((n = strlen(path)) < siz && buf)
1184887Schin memcpy(buf, path, n + 1);
1194887Schin return n;
1204887Schin }
1214887Schin
1224887Schin #endif
1234887Schin
1244887Schin #endif
1254887Schin
1264887Schin #endif
1274887Schin
1284887Schin #endif
129