8354 sync regcomp(3C) with upstream (fix make catalog)
[unleashed/tickless.git] / usr / src / lib / libast / common / path / pathposix.c
blobfcfb053adc48674fbaf97a28c90a28d79735021c
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 native path to posix 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 #include <uwin.h>
40 size_t
41 pathposix(const char* path, char* buf, size_t siz)
43 return uwin_unpath(path, buf, siz);
46 #else
48 #if __CYGWIN__
50 extern void cygwin_conv_to_posix_path(const char*, char*);
52 size_t
53 pathposix(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_posix_path(path, tmp);
62 if ((n = strlen(tmp)) < siz && buf)
63 memcpy(buf, tmp, n + 1);
64 return n;
66 cygwin_conv_to_posix_path(path, buf);
67 return strlen(buf);
70 #else
72 #if __EMX__ && 0 /* show me the docs */
74 size_t
75 pathposix(const char* path, char* buf, size_t siz)
77 char* s;
78 size_t n;
80 if (!_posixpath(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 pathposix(const char* path, char *buf, size_t siz)
100 static const char pfx[] = "/dev/fs";
102 *buf = 0;
103 if (!strncasecmp(path, pfx, sizeof(pfx) - 1))
104 strlcpy(buf, path, siz);
105 else
106 winpath2unix(path, PATH_NONSTRICT, buf, siz);
107 return strlen(buf);
110 #else
112 size_t
113 pathposix(const char* path, char* buf, size_t siz)
115 size_t n;
117 if ((n = strlen(path)) < siz && buf)
118 memcpy(buf, path, n + 1);
119 return n;
122 #endif
124 #endif
126 #endif
128 #endif