import less(1)
[unleashed/tickless.git] / usr / src / lib / libast / common / path / pathnative.c
blob1f3eedb0e5a44161d2dd016ce7ef06b0de40d2c3
1 /***********************************************************************
2 * *
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
8 * *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
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
24 * Glenn Fowler
25 * AT&T Research
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
34 #include <ast.h>
36 #if _UWIN
38 extern int uwin_path(const char*, char*, int);
40 size_t
41 pathnative(const char* path, char* buf, size_t siz)
43 return uwin_path(path, buf, siz);
46 #else
48 #if __CYGWIN__
50 extern void cygwin_conv_to_win32_path(const char*, char*);
52 size_t
53 pathnative(const char* path, char* buf, size_t siz)
55 size_t n;
57 if (!buf || siz < PATH_MAX)
59 char tmp[PATH_MAX];
61 cygwin_conv_to_win32_path(path, tmp);
62 if ((n = strlen(tmp)) < siz && buf)
63 memcpy(buf, tmp, n + 1);
64 return n;
66 cygwin_conv_to_win32_path(path, buf);
67 return strlen(buf);
70 #else
72 #if __EMX__
74 size_t
75 pathnative(const char* path, char* buf, size_t siz)
77 char* s;
78 size_t n;
80 if (!_fullpath(buf, path, siz))
82 for (s = buf; *s; s++)
83 if (*s == '/')
84 *s = '\\';
86 else if ((n = strlen(path)) < siz && buf)
87 memcpy(buf, path, n + 1);
88 return n;
91 #else
93 #if __INTERIX
95 #include <interix/interix.h>
97 size_t
98 pathnative(const char* path, char* buf, size_t siz)
100 *buf = 0;
101 if (path[1] == ':')
102 strlcpy(buf, path, siz);
103 else
104 unixpath2win(path, 0, buf, siz);
105 return strlen(buf);
108 #else
110 size_t
111 pathnative(const char* path, char* buf, size_t siz)
113 size_t n;
115 if ((n = strlen(path)) < siz && buf)
116 memcpy(buf, path, n + 1);
117 return n;
120 #endif
122 #endif
124 #endif
126 #endif