xref: /onnv-gate/usr/src/lib/libast/common/path/pathnative.c (revision 12068:08a39a083754)
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 path to native 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 extern int	uwin_path(const char*, char*, int);
394887Schin 
404887Schin size_t
pathnative(const char * path,char * buf,size_t siz)414887Schin pathnative(const char* path, char* buf, size_t siz)
424887Schin {
434887Schin 	return uwin_path(path, buf, siz);
444887Schin }
454887Schin 
464887Schin #else
474887Schin 
484887Schin #if __CYGWIN__
494887Schin 
504887Schin extern void	cygwin_conv_to_win32_path(const char*, char*);
514887Schin 
524887Schin size_t
pathnative(const char * path,char * buf,size_t siz)534887Schin pathnative(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_win32_path(path, tmp);
624887Schin 		if ((n = strlen(tmp)) < siz && buf)
634887Schin 			memcpy(buf, tmp, n + 1);
644887Schin 		return n;
654887Schin 	}
664887Schin 	cygwin_conv_to_win32_path(path, buf);
674887Schin 	return strlen(buf);
684887Schin }
694887Schin 
704887Schin #else
714887Schin 
724887Schin #if __EMX__
734887Schin 
744887Schin size_t
pathnative(const char * path,char * buf,size_t siz)754887Schin pathnative(const char* path, char* buf, size_t siz)
764887Schin {
774887Schin 	char*		s;
784887Schin 	size_t		n;
794887Schin 
804887Schin 	if (!_fullpath(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
pathnative(const char * path,char * buf,size_t siz)984887Schin pathnative(const char* path, char* buf, size_t siz)
994887Schin {
1004887Schin 	*buf = 0;
1014887Schin 	if (path[1] == ':')
1024887Schin 		strlcpy(buf, path, siz);
1034887Schin 	else
1044887Schin 		unixpath2win(path, 0, buf, siz);
1054887Schin 	return strlen(buf);
1064887Schin }
1074887Schin 
1084887Schin #else
1094887Schin 
1104887Schin size_t
pathnative(const char * path,char * buf,size_t siz)1114887Schin pathnative(const char* path, char* buf, size_t siz)
1124887Schin {
1134887Schin 	size_t		n;
1144887Schin 
1154887Schin 	if ((n = strlen(path)) < siz && buf)
1164887Schin 		memcpy(buf, path, n + 1);
1174887Schin 	return n;
1184887Schin }
1194887Schin 
1204887Schin #endif
1214887Schin 
1224887Schin #endif
1234887Schin 
1244887Schin #endif
1254887Schin 
1264887Schin #endif
127