]>
Commit | Line | Data |
---|---|---|
23c9e63c DD |
1 | /* |
2 | * Copyright (c) 2000, Red Hat, Inc. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or modify | |
5 | * it under the terms of the GNU General Public License as published by | |
6 | * the Free Software Foundation; either version 2 of the License, or | |
7 | * (at your option) any later version. | |
8 | * | |
9 | * A copy of the GNU General Public License can be found at | |
10 | * http://www.gnu.org/ | |
11 | * | |
12 | * Written by DJ Delorie <dj@cygnus.com> | |
13 | * | |
14 | */ | |
15 | ||
16 | /* See concat.h. Note that we canonicalize the result, this avoids | |
17 | multiple slashes being interpreted as UNCs. */ | |
18 | ||
19 | #include <stdarg.h> | |
20 | #include <stdlib.h> | |
21 | #include <string.h> | |
22 | ||
23 | char * | |
24 | concat (char *s, ...) | |
25 | { | |
ed3e8b9b | 26 | int len; |
23c9e63c DD |
27 | char *rv, *arg; |
28 | va_list v; | |
29 | ||
30 | if (!s) | |
31 | return 0; | |
32 | ||
ed3e8b9b DD |
33 | len = strlen (s); |
34 | ||
23c9e63c DD |
35 | va_start (v, s); |
36 | while (1) | |
37 | { | |
1fd6d0a2 | 38 | arg = va_arg (v, char *); |
23c9e63c DD |
39 | if (arg == 0) |
40 | break; | |
1fd6d0a2 | 41 | len += strlen (arg); |
23c9e63c | 42 | } |
1fd6d0a2 | 43 | va_end (v); |
23c9e63c DD |
44 | |
45 | rv = (char *) malloc (len+1); | |
1fd6d0a2 DD |
46 | strcpy (rv, s); |
47 | va_start (v, s); | |
23c9e63c DD |
48 | while (1) |
49 | { | |
1fd6d0a2 | 50 | arg = va_arg (v, char *); |
23c9e63c DD |
51 | if (arg == 0) |
52 | break; | |
1fd6d0a2 | 53 | strcat (rv, arg); |
23c9e63c | 54 | } |
1fd6d0a2 | 55 | va_end (v); |
23c9e63c DD |
56 | |
57 | /* concat is only used for urls and files, so we can safely | |
58 | canonicalize the results */ | |
59 | char *d; | |
60 | for (s=rv; *s; s++) | |
61 | if (*s == '\\') | |
62 | *s = '/'; | |
63 | for (s=d=rv; *s; s++) | |
64 | { | |
65 | *d++ = *s; | |
66 | /* special case for URLs */ | |
67 | if (*s == ':' && s[1] == '/' &&s[2] == '/') | |
68 | { | |
69 | *d++ = *++s; | |
70 | *d++ = *++s; | |
71 | } | |
72 | else if (*s == '/') | |
73 | while (s[1] == '/') | |
74 | s++; | |
75 | } | |
76 | *d = 0; | |
77 | ||
78 | return rv; | |
79 | } | |
f57c332f DD |
80 | |
81 | char * | |
82 | backslash (char *s) | |
83 | { | |
84 | for (char *t = s; *t; t++) | |
85 | if (*t == '/') | |
86 | *t = '\\'; | |
87 | return s; | |
88 | } |