1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1985-2011 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                 Eclipse Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *          http://www.eclipse.org/org/documents/epl-v10.html           *
11 *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *                 Glenn Fowler <gsf@research.att.com>                  *
18 *                  David Korn <dgk@research.att.com>                   *
19 *                   Phong Vo <kpv@research.att.com>                    *
20 *                                                                      *
21 ***********************************************************************/
22 #pragma prototyped
23 /*
24  * Glenn Fowler
25  * AT&T Research
26  *
27  * convert path to native fs representation in <buf,siz>
28  * length of converted path returned
29  * if return length >= siz then buf is indeterminate, but another call
30  * with siz=length+1 would work
31  * if buf==0 then required size is returned
32  */
33 
34 #include <ast.h>
35 
36 #if _UWIN
37 
38 extern int	uwin_path(const char*, char*, int);
39 
40 size_t
pathnative(const char * path,char * buf,size_t siz)41 pathnative(const char* path, char* buf, size_t siz)
42 {
43 	return uwin_path(path, buf, siz);
44 }
45 
46 #else
47 
48 #if __CYGWIN__
49 
50 extern void	cygwin_conv_to_win32_path(const char*, char*);
51 
52 size_t
pathnative(const char * path,char * buf,size_t siz)53 pathnative(const char* path, char* buf, size_t siz)
54 {
55 	size_t		n;
56 
57 	if (!buf || siz < PATH_MAX)
58 	{
59 		char	tmp[PATH_MAX];
60 
61 		cygwin_conv_to_win32_path(path, tmp);
62 		if ((n = strlen(tmp)) < siz && buf)
63 			memcpy(buf, tmp, n + 1);
64 		return n;
65 	}
66 	cygwin_conv_to_win32_path(path, buf);
67 	return strlen(buf);
68 }
69 
70 #else
71 
72 #if __EMX__
73 
74 size_t
pathnative(const char * path,char * buf,size_t siz)75 pathnative(const char* path, char* buf, size_t siz)
76 {
77 	char*		s;
78 	size_t		n;
79 
80 	if (!_fullpath(buf, path, siz))
81 	{
82 		for (s = buf; *s; s++)
83 			if (*s == '/')
84 				*s = '\\';
85 	}
86 	else if ((n = strlen(path)) < siz && buf)
87 		memcpy(buf, path, n + 1);
88 	return n;
89 }
90 
91 #else
92 
93 #if __INTERIX
94 
95 #include <interix/interix.h>
96 
97 size_t
pathnative(const char * path,char * buf,size_t siz)98 pathnative(const char* path, char* buf, size_t siz)
99 {
100 	*buf = 0;
101 	if (path[1] == ':')
102 		strlcpy(buf, path, siz);
103 	else
104 		unixpath2win(path, 0, buf, siz);
105 	return strlen(buf);
106 }
107 
108 #else
109 
110 size_t
pathnative(const char * path,char * buf,size_t siz)111 pathnative(const char* path, char* buf, size_t siz)
112 {
113 	size_t		n;
114 
115 	if ((n = strlen(path)) < siz && buf)
116 		memcpy(buf, path, n + 1);
117 	return n;
118 }
119 
120 #endif
121 
122 #endif
123 
124 #endif
125 
126 #endif
127