2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
5 Desc: PosixC internal functions for Amiga<>UNIX filename conversion
9 #include "__posixc_intbase.h"
16 #include <aros/debug.h>
18 static const char *__path_devstuff_u2a(const char *path
);
19 static void __path_normalstuff_u2a(const char *path
, char *buf
);
21 /*****************************************************************************
27 const char *__path_u2a(
33 Translates a unix-style path into an AmigaDOS one.
36 upath - Unix-style path to translate into an AmigaDOS-style equivalent.
39 A pointer to a string containing the AmigaDOS-style path, or NULL in
42 The pointer is valid only until next call to this function, so if
43 you need to call this function recursively, you must save the string
44 pointed to by the pointer before calling this function again.
47 This function is for private usage by system code. Do not use it
54 ******************************************************************************/
56 struct PosixCIntBase
*PosixCBase
=
57 (struct PosixCIntBase
*)__aros_getbase_PosixCBase();
60 D(bug("Entering __path_u2a(\"%s\")\n", upath
));
62 /* Does the path really need to be converted? */
63 if (!PosixCBase
->doupath
)
65 D(bug("__path_u2a: No conversion needed\n"));
77 /* Some scripts (config.guess) try to access /.attbin
78 which is MacOS-specific thing. Block it.
79 FIXME: Can we avod this hack ?
81 if (!strncmp(upath
, "/.attbin", 8))
88 First see whether the path is in the /dev/#? form and,
89 if so, if it's handled internally
91 newpath
= __path_devstuff_u2a(upath
);
94 D(bug("__path_u2a: No /dev stuff, doing normal conversion\n"));
96 /* Else, convert it normally */
97 newpath
= realloc_nocopy(PosixCBase
->upathbuf
, strlen(upath
) + 1);
105 PosixCBase
->upathbuf
= (char *)newpath
;
106 __path_normalstuff_u2a(upath
, PosixCBase
->upathbuf
);
109 D(bug("__path_u2a: converted path \"%s\"\n", newpath
));
114 /*****************************************************************************
120 const char *__path_a2u(
126 Translates an AmigaDOS-style path into an unix one.
129 apath - AmigaDOS-style path to translate into an unix-style equivalent.
132 A pointer to a string containing the unix-style path, or NULL in
135 The pointer is valid only until next call to this function, so if
136 you need to call this function recursively, you must save the string
137 pointed to by the pointer before calling this function again.
140 This function is for private usage by system code. Do not use it
147 ******************************************************************************/
149 struct PosixCIntBase
*PosixCBase
=
150 (struct PosixCIntBase
*)__aros_getbase_PosixCBase();
151 const char *old_apath
= apath
;
152 char ch
, *upath
, *old_upath
;
172 if (!PosixCBase
->doupath
)
175 while ((ch
= *apath
++))
186 old_upath
= realloc_nocopy(PosixCBase
->upathbuf
, 1 + size
+ 1);
187 if (old_upath
== NULL
)
193 PosixCBase
->upathbuf
= old_upath
;
201 register char ch
= apath
[0];
232 (--old_upath
)[0] = '/';
252 upath
[0] = '.'; upath
[1] = '.'; upath
[2] = '/'; upath
+= 3;
272 static const char *__path_devstuff_u2a(const char *path
)
275 Translate the various /dev/#? most used files into the AROS equivalent.
276 Use a tree-like handmade search to speed things up
279 if (path
[0] == '/' && path
[1] == 'd' && path
[2] == 'e' && path
[3] == 'v')
283 if (path
[5] == 'n' && path
[6] == 'u' && path
[7] == 'l' && path
[8] == 'l' && path
[9] == '\0')
286 if (path
[5] == 'z' && path
[6] == 'e' && path
[7] == 'r' && path
[8] == 'o' && path
[9] == '\0')
289 if (path
[5] == 's' && path
[6] == 't' && path
[7] == 'd')
291 if (path
[8] == 'i' && path
[9] == 'n' && path
[10] == '\0')
294 if (path
[8] == 'o' && path
[9] == 'u' && path
[10] == 't' && path
[11] == '\0')
297 if (path
[8] == 'e' && path
[9] == 'r' && path
[10] == 'r' && path
[11] == '\0')
312 static void __path_normalstuff_u2a(const char *path
, char *buf
)
314 register char dir_sep
= '\0';
315 register int makevol
= 0;
327 while (path
[0] == '/')
335 register char ch
= path
[0];
391 if (ch
== '/' || ch
== '\0')