Mercurial > dwindows
annotate gtk/rel2abs.c @ 848:543e591c69a3
Implemented dw_scrollbox_get_pos() and dw_scrollbox_get_range() on OS/2.
Also fixed an issue with the line scrolling (up/down/left/right arrows) on OS/2.
author | bsmith@81767d24-ef19-dc11-ae90-00e081727c95 |
---|---|
date | Thu, 31 Mar 2011 01:37:18 +0000 |
parents | a5deb87b26e4 |
children |
rev | line source |
---|---|
629
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
1 /* |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
2 * Copyright (c) 1997 Shigio Yamaguchi. All rights reserved. |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
3 * Copyright (c) 1999 Tama Communications Corporation. All rights reserved. |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
4 * |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
5 * Redistribution and use in source and binary forms, with or without |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
6 * modification, are permitted provided that the following conditions |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
7 * are met: |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
8 * 1. Redistributions of source code must retain the above copyright |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
9 * notice, this list of conditions and the following disclaimer. |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
10 * 2. Redistributions in binary form must reproduce the above copyright |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
11 * notice, this list of conditions and the following disclaimer in the |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
12 * documentation and/or other materials provided with the distribution. |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
13 * |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
24 * SUCH DAMAGE. |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
25 */ |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
26 #include <errno.h> |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
27 #include <stdlib.h> |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
28 #include <string.h> |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
29 /* |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
30 * rel2abs: convert an relative path name into absolute. |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
31 * |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
32 * i) path relative path |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
33 * i) base base directory (must be absolute path) |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
34 * o) result result buffer |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
35 * i) size size of result buffer |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
36 * r) != NULL: absolute path |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
37 * == NULL: error |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
38 */ |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
39 char * |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
40 rel2abs(path, base, result, size) |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
41 const char *path; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
42 const char *base; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
43 char *result; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
44 const size_t size; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
45 { |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
46 const char *pp, *bp; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
47 /* |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
48 * endp points the last position which is safe in the result buffer. |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
49 */ |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
50 const char *endp = result + size - 1; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
51 char *rp; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
52 int length; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
53 |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
54 if (*path == '/') { |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
55 if (strlen(path) >= size) |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
56 goto erange; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
57 strcpy(result, path); |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
58 goto finish; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
59 } else if (*base != '/' || !size) { |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
60 errno = EINVAL; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
61 return (NULL); |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
62 } else if (size == 1) |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
63 goto erange; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
64 |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
65 length = strlen(base); |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
66 |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
67 if (!strcmp(path, ".") || !strcmp(path, "./")) { |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
68 if (length >= size) |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
69 goto erange; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
70 strcpy(result, base); |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
71 /* |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
72 * rp points the last char. |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
73 */ |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
74 rp = result + length - 1; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
75 /* |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
76 * remove the last '/'. |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
77 */ |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
78 if (*rp == '/') { |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
79 if (length > 1) |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
80 *rp = 0; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
81 } else |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
82 rp++; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
83 /* rp point NULL char */ |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
84 if (*++path == '/') { |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
85 /* |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
86 * Append '/' to the tail of path name. |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
87 */ |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
88 *rp++ = '/'; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
89 if (rp > endp) |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
90 goto erange; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
91 *rp = 0; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
92 } |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
93 goto finish; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
94 } |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
95 bp = base + length; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
96 if (*(bp - 1) == '/') |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
97 --bp; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
98 /* |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
99 * up to root. |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
100 */ |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
101 for (pp = path; *pp && *pp == '.'; ) { |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
102 if (!strncmp(pp, "../", 3)) { |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
103 pp += 3; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
104 while (bp > base && *--bp != '/') |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
105 ; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
106 } else if (!strncmp(pp, "./", 2)) { |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
107 pp += 2; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
108 } else if (!strncmp(pp, "..\0", 3)) { |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
109 pp += 2; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
110 while (bp > base && *--bp != '/') |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
111 ; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
112 } else |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
113 break; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
114 } |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
115 /* |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
116 * down to leaf. |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
117 */ |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
118 length = bp - base; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
119 if (length >= size) |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
120 goto erange; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
121 strncpy(result, base, length); |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
122 rp = result + length; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
123 if (*pp || *(pp - 1) == '/' || length == 0) |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
124 *rp++ = '/'; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
125 if (rp + strlen(pp) > endp) |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
126 goto erange; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
127 strcpy(rp, pp); |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
128 finish: |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
129 return result; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
130 erange: |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
131 errno = ERANGE; |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
132 return (NULL); |
a5deb87b26e4
Add support for using initial directory in dw_file_browse()
mhessling@81767d24-ef19-dc11-ae90-00e081727c95
parents:
diff
changeset
|
133 } |