annotate src/mule-mcpath.c @ 440:8de8e3f6228a r21-2-28

Import from CVS: tag r21-2-28
author cvs
date Mon, 13 Aug 2007 11:33:38 +0200
parents 697ef44129c6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
1 /* Support for Non-ASCII Path Name
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
2 Copyright (C) 1985, 1986, 1992, 1993, 1995 Free Software Foundation, Inc.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
3 Copyright (C) 1995 Sun Microsystems, Inc.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
4
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
5 This file is part of XEmacs.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
6
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
10 later version.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
11
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
15 for more details.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
16
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
21
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
22 /* Synched up with: Mule 2.3. Not in FSF. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
23
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
24 /* mcpath.h should be included in config.h */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
25 #include <config.h>
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
26 #include "lisp.h"
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
27
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
28 #include "sysfile.h"
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
29 #include "buffer.h"
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
30 #include "mule.h"
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
31
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
32 Lisp_Object Qpathname_coding_system = 0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
33
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
34 static void
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 412
diff changeset
35 mcpath_encode_code (Lisp_Coding_System *cp)
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
36 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
37 Lisp_Object coding_system;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
38
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
39 coding_system = Fsymbol_value (Qpathname_coding_system);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
40
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
41 mule_encode_code (coding_system, cp);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
42 CODE_CNTL (cp) |= CC_END;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
43 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
44
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
45 static int
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
46 mule_encode_path_1 (unsigned char *src, unsigned int srcsize,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
47 unsigned char *dst, unsigned int dstsize)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
48 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 412
diff changeset
49 Lisp_Coding_System code;
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
50
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
51 mcpath_encode_code (&code);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
52 if (CODE_TYPE (&code) > MULE_AUTOCONV)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
53 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
54 unsigned char *buf;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
55
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
56 /* get_conversion_buffer () is not */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
57 /* re-entrant. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
58 buf = (unsigned char *) alloca (MULE_ENCODE_BUF_SIZE (srcsize, &code));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
59 if (buf)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
60 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
61 int len;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
62 Lisp_Object dummy = Qnil;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
63
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
64 len = mule_encode (&code, src, buf, srcsize, &dummy);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
65 if (!CODE_CHAR (&code) && len <= dstsize)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
66 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
67 memcpy (dst, buf, len);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
68 return len;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
69 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
70 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
71 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
72 return -1; /* use original */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
73 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
74
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
75 static unsigned char *
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
76 mule_decode_path_1 (unsigned char *src, unsigned char *dst,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
77 unsigned int dstsize)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
78 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 412
diff changeset
79 Lisp_Coding_System code;
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
80
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
81 mcpath_encode_code (&code);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
82 if (CODE_TYPE (&code) > MULE_AUTOCONV)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
83 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
84 int len;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
85 unsigned char *buf;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
86
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
87 len = strlen (src) + 1; /* + 1 for '\0' */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
88
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
89 /* get_conversion_buffer () is not */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
90 /* re-entrant. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
91 buf = (unsigned char *) alloca (MULE_DECODE_BUF_SIZE (len, &code));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
92 if (buf)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
93 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
94 CODE_CNTL (&code) |= CC_END;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
95 len = mule_decode (&code, src, buf, len);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
96 if (!CODE_CHAR (&code) && len <= dstsize)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
97 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
98 memcpy (dst, buf, len); /* len should include '\0' */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
99 return dst;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
100 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
101 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
102 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
103 return src;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
104 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
105
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
106 static unsigned char *
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
107 mule_decode_path (unsigned char *path, unsigned char ext_path[MC_MAXPATHLEN])
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
108 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
109 return
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
110 (Qpathname_coding_system
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
111 ? mule_decode_path_1 (path, ext_path, MC_MAXPATHLEN)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
112 : path); /* in case of before initialization */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
113 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
114
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
115 static unsigned char *
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
116 mule_encode_path (unsigned char *path, unsigned char *encode_buffer,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
117 unsigned int size)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
118 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
119 int len;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
120
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
121 len = mule_encode_path_1 (path, strlen (path), encode_buffer, size);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
122 if (len > 0)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
123 path = encode_buffer;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
124 #ifdef MSDOS
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
125 /* convert the MSDOS style path delimiter to the UNIX style. Note
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
126 that now the code is *internal*, so we can simply compare each
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
127 character with '\\'. And this operation will alter the contents
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
128 of Lisp Object, PATH. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
129 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
130 unsigned char *p = path;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
131
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
132 while (*p)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
133 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
134 if (*p == '\\')
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
135 *p = '/';
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
136 p++;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
137 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
138 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
139 #endif /* MSDOS */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
140 return path;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
141 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
142
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
143 #if 0 /* example of how they do it (similar junk deleted) ... */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
144
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
145 int
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
146 mc_creat (unsigned char *path, int mode)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
147 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
148 unsigned char buffer[MC_MAXPATHLEN];
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
149 return creat (mule_decode_path (path, buffer), mode);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
150 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
151
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
152 int
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
153 mc_readlink (unsigned char *path, unsigned char *buf, int size)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
154 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
155 unsigned char buffer[MC_MAXPATHLEN], buffer2[MAXPATHLEN];
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
156 int nread;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
157
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
158 nread = readlink (mule_decode_path (path, buffer), buffer2, MAXPATHLEN);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
159 if (nread > 0)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
160 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
161 int len;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
162 unsigned char *p;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
163
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
164 len = mule_encode_path_1 (buffer2, nread, buffer, sizeof (buffer));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
165 if (0 <= len && len <= size)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
166 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
167 memcpy (buf, buffer, len);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
168 return len;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
169 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
170 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
171 return -1;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
172 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
173
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
174 int
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
175 mc_chdir (unsigned char *path)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
176 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
177 unsigned char buffer[MC_MAXPATHLEN];
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
178
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
179 path = mule_decode_path (path, buffer);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
180
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
181 #ifdef MSDOS
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
182 if ((path[0] != 0) && (path[1] == ':'))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
183 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
184 int drive = (tolower (path[0]) - 'a');
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
185 if (getdisk () != drive)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
186 setdisk (drive);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
187 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
188
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
189 /* If path != "/" and path != "a:/" and path ends with slash, remove
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
190 it. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
191 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
192 int len = strlen (path);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
193
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
194 if (strcmp (path + 1, ":/") && (len > 1) && (path[len - 1] == '/'))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
195 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
196 if (path != buffer) /* It is not good to modify original path. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
197 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
198 memcpy (buffer, path, len - 1); /* no need to copy last /. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
199 path = buffer;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
200 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
201 path[len - 1] = 0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
202 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
203 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
204 #endif /* MSDOS */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
205
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
206 return chdir (path);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
207 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
208
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
209 #ifdef MSDOS
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
210 #ifndef HAVE_GETWD
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
211 unsigned char *
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
212 mc_getcwd (unsigned char *null, size_t size)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
213 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
214 unsigned char buffer[MAXPATHLEN];
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
215 unsigned char *path;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
216
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
217 path = (unsigned char *) getcwd ((char *)buffer, MAXPATHLEN);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
218 if (path)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
219 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
220 /* here, should be (path == buffer). */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
221 path = (unsigned char *) xmalloc (MC_MAXPATHLEN); /* MSDOS */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
222 if (path)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
223 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
224 int len;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
225 int buffer_length = strlen (buffer) + 1;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
226
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
227 len = mule_encode_path_1 (buffer, buffer_length, path, MC_MAXPATHLEN);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
228 if (len < 0)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
229 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
230 /* conversion failed. use value that is returned from system. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
231 memcpy (path, buffer, buffer_length);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
232 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
233 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
234 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
235 return path;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
236 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
237 #else /* HAVE_GETWD */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
238 unsigned char *
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
239 mc_getwd (unsigned char path[])
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
240 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
241 unsigned char *p;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 412
diff changeset
242
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
243 p = getwd (path);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
244 if (p)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
245 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
246 unsigned char buffer[MC_MAXPATHLEN];
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
247 int len;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 412
diff changeset
248
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
249 len = mule_encode_path_1 (path, strlen (path) + 1, buffer, sizeof buffer);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
250 if (len > 0)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
251 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
252 memcpy (path, buffer, len);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
253 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
254 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
255 return p;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
256 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
257 #endif /* HAVE_GETWD */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
258 #endif /* MSDOS */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
259
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
260 /* In callproc.c, execvp() is called like this:
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
261 * execvp (new_argv[0], new_argv);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
262 * following implement depends this.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
263 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
264 #ifndef NO_MC_EXECVP
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
265 void
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
266 mc_execvp (unsigned char *path, unsigned char *argv[])
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
267 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
268 unsigned char buffer[MC_MAXPATHLEN];
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
269 argv[0] = path = mule_decode_path (path, buffer);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
270 execvp (path, argv);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
271 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
272 #endif /* !NO_MC_EXECVP */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
273
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
274 static DIRENTRY mcpath_directory_entry;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
275 DIRENTRY *
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
276 mc_readdir (DIR *d)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
277 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
278 SYSTEM_DIRENTRY *sp;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
279 DIRENTRY *dp = &mcpath_directory_entry;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
280
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
281 sp = readdir (d);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
282 if (!sp) return 0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
283
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
284 #ifndef MSDOS
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
285 dp->d_ino = sp->d_ino;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
286 #endif /* MSDOS */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
287 { /* copy d_name with conversion. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
288 int len;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
289
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
290 len = mule_encode_path_1 (sp->d_name, NAMLEN (sp),
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
291 dp->d_name, sizeof (dp->d_name) - 1);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
292 if (len < 0)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
293 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
294 len = NAMLEN (sp);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
295 #ifdef MCPATH_ASSERT
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
296 assert (len < sizeof (dp->d_name));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
297 #endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
298 memcpy (dp->d_name, sp->d_name, len);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
299 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
300 dp->d_name[len] = 0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
301 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
302 return dp;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
303 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
304
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
305 #endif /* 0 */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents:
diff changeset
306