3 Copyright © 1995-2010, The AROS Development Team. All rights reserved.
6 Desc: utility internal function __path_u2a()
10 #include "__arosc_privdata.h"
16 static const char *__path_devstuff_u2a(const char *path
);
17 static void __path_normalstuff_u2a(const char *path
, char *buf
);
20 static int __doupath
= 1;
21 static char *__apathbuf
;
22 # define realloc_nocopy realloc
25 /*****************************************************************************
31 const char *__path_u2a(
37 Translates an unix-style path into an AmigaDOS one.
40 upath - Unix-style path to translate into an AmigaDOS-style equivalent.
43 A pointer to a string containing the AmigaDOS-style path, or NULL in
46 The pointer is valid only until next call to this function, so if
47 you need to call this function recursively, you must save the string
48 pointed to by the pointer before calling this function again.
51 This function is for private usage by system code. Do not use it
58 ******************************************************************************/
62 /* Does the path really need to be converted? */
73 /* Some scripts (config.guess) try to access /.attbin
74 which is MacOS-specific thing. Block it. */
75 if (!strncmp(upath
, "/.attbin", 8))
82 First see whether the path is in the /dev/#? form and,
83 if so, if it's handled internally
85 newpath
= __path_devstuff_u2a(upath
);
88 /* Else, convert it normally */
89 newpath
= realloc_nocopy(__apathbuf
, strlen(upath
) + 1);
97 __apathbuf
= (char *)newpath
;
98 __path_normalstuff_u2a(upath
, __apathbuf
);
104 /*****************************************************************************
110 const char *__path_a2u(
116 Translates an AmigaDOS-style path into an unix one.
119 apath - AmigaDOS-style path to translate into an unix-style equivalent.
122 A pointer to a string containing the unix-style path, or NULL in
125 The pointer is valid only until next call to this function, so if
126 you need to call this function recursively, you must save the string
127 pointed to by the pointer before calling this function again.
130 This function is for private usage by system code. Do not use it
137 ******************************************************************************/
139 const char *old_apath
= apath
;
140 char ch
, *upath
, *old_upath
;
163 while ((ch
= *apath
++))
174 old_upath
= realloc_nocopy(__apathbuf
, 1 + size
+ 1);
175 if (old_upath
== NULL
)
181 __apathbuf
= old_upath
;
189 register char ch
= apath
[0];
220 (--old_upath
)[0] = '/';
240 upath
[0] = '.'; upath
[1] = '.'; upath
[2] = '/'; upath
+= 3;
260 static const char *__path_devstuff_u2a(const char *path
)
263 Translate the various /dev/#? most used files into the AROS equivalent.
264 Use a tree-like handmade search to speed things up
267 if (path
[0] == '/' && path
[1] == 'd' && path
[2] == 'e' && path
[3] == 'v')
271 if (path
[5] == 'n' && path
[6] == 'u' && path
[7] == 'l' && path
[8] == 'l' && path
[9] == '\0')
274 if (path
[5] == 'z' && path
[6] == 'e' && path
[7] == 'r' && path
[8] == 'o' && path
[9] == '\0')
277 if (path
[5] == 's' && path
[6] == 't' && path
[7] == 'd')
279 if (path
[8] == 'i' && path
[9] == 'n' && path
[10] == '\0')
282 if (path
[8] == 'o' && path
[9] == 'u' && path
[10] == 't' && path
[11] == '\0')
285 if (path
[8] == 'e' && path
[9] == 'r' && path
[10] == 'r' && path
[11] == '\0')
300 static void __path_normalstuff_u2a(const char *path
, char *buf
)
302 register char dir_sep
= '\0';
303 register int makevol
= 0;
315 while (path
[0] == '/')
323 register char ch
= path
[0];
379 if (ch
== '/' || ch
== '\0')
429 int main(int argc
, char *argv
[])
434 printf("%s\n", __path_u2a(argv
[1]));
435 printf("%s\n", __path_a2u(argv
[2]));