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