1765
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1765
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
1765
|
21 |
|
22 */ |
|
23 |
|
24 #ifdef HAVE_CONFIG_H |
|
25 #include <config.h> |
|
26 #endif |
|
27 |
|
28 #include <cerrno> |
1802
|
29 #include <cstdio> |
|
30 #include <cstdlib> |
1765
|
31 #include <cstring> |
|
32 |
3503
|
33 #include <iostream> |
4726
|
34 #include <vector> |
3040
|
35 |
2443
|
36 #ifdef HAVE_SYS_TYPES_H |
1765
|
37 #include <sys/types.h> |
2443
|
38 #endif |
2926
|
39 |
|
40 #ifdef HAVE_UNISTD_H |
1765
|
41 #include <unistd.h> |
|
42 #endif |
|
43 |
|
44 #include "file-ops.h" |
2926
|
45 #include "oct-env.h" |
2934
|
46 #include "oct-passwd.h" |
3710
|
47 #include "pathlen.h" |
1775
|
48 #include "statdefs.h" |
2926
|
49 #include "str-vec.h" |
1765
|
50 |
2937
|
51 #define NOT_SUPPORTED(nm) \ |
4062
|
52 nm ": not supported on this system" |
2937
|
53 |
4101
|
54 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \ |
|
55 && ! defined (OCTAVE_HAVE_POSIX_FILESYSTEM)) |
|
56 char file_ops::dir_sep_char = '\\'; |
|
57 std::string file_ops::dir_sep_str ("\\"); |
|
58 #else |
|
59 char file_ops::dir_sep_char = '/'; |
|
60 std::string file_ops::dir_sep_str ("/"); |
|
61 #endif |
|
62 |
|
63 #if (defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \ |
|
64 && defined (OCTAVE_HAVE_POSIX_FILESYSTEM)) |
|
65 std::string file_ops::dir_sep_chars ("/\\"); |
|
66 #else |
|
67 std::string file_ops::dir_sep_chars (file_ops::dir_sep_str); |
|
68 #endif |
|
69 |
2433
|
70 // We provide a replacement for mkdir(). |
|
71 |
1765
|
72 int |
3504
|
73 file_ops::mkdir (const std::string& name, mode_t mode) |
1765
|
74 { |
3504
|
75 std::string msg; |
2937
|
76 return mkdir (name, mode, msg); |
1765
|
77 } |
|
78 |
2668
|
79 int |
3504
|
80 file_ops::mkdir (const std::string& name, mode_t mode, std::string& msg) |
2668
|
81 { |
3504
|
82 msg = std::string (); |
2668
|
83 |
2937
|
84 int status = -1; |
|
85 |
|
86 #if defined (HAVE_MKDIR) |
4081
|
87 |
|
88 #if defined (MKDIR_TAKES_ONE_ARG) |
|
89 status = ::mkdir (name.c_str ()); |
|
90 #else |
2937
|
91 status = ::mkdir (name.c_str (), mode); |
4081
|
92 #endif |
2668
|
93 |
|
94 if (status < 0) |
3504
|
95 { |
|
96 using namespace std; |
|
97 msg = ::strerror (errno); |
|
98 } |
2937
|
99 #else |
|
100 msg = NOT_SUPPORTED ("mkdir"); |
|
101 #endif |
2668
|
102 |
|
103 return status; |
|
104 } |
|
105 |
2433
|
106 // I don't know how to emulate this on systems that don't provide it. |
|
107 |
1765
|
108 int |
3504
|
109 file_ops::mkfifo (const std::string& name, mode_t mode) |
1765
|
110 { |
3504
|
111 std::string msg; |
2937
|
112 return mkfifo (name, mode, msg); |
1765
|
113 } |
|
114 |
2668
|
115 int |
3504
|
116 file_ops::mkfifo (const std::string& name, mode_t mode, std::string& msg) |
2668
|
117 { |
3504
|
118 msg = std::string (); |
2668
|
119 |
2937
|
120 int status = -1; |
|
121 |
2668
|
122 #if defined (HAVE_MKFIFO) |
2937
|
123 status = ::mkfifo (name.c_str (), mode); |
2668
|
124 |
|
125 if (status < 0) |
3504
|
126 { |
|
127 using namespace std; |
|
128 msg = ::strerror (errno); |
|
129 } |
2937
|
130 #else |
|
131 msg = NOT_SUPPORTED ("mkfifo"); |
|
132 #endif |
2668
|
133 |
|
134 return status; |
|
135 } |
|
136 |
3710
|
137 // I don't know how to emulate this on systems that don't provide it. |
|
138 |
|
139 int |
|
140 file_ops::link (const std::string& old_name, const std::string& new_name) |
|
141 { |
|
142 std::string msg; |
|
143 return link (old_name, new_name, msg); |
|
144 } |
|
145 |
|
146 int |
|
147 file_ops::link (const std::string& old_name, |
|
148 const std::string& new_name, std::string& msg) |
|
149 { |
|
150 msg = std::string (); |
|
151 |
|
152 int status = -1; |
|
153 |
|
154 #if defined (HAVE_LINK) |
|
155 status = ::link (old_name.c_str (), new_name.c_str ()); |
|
156 |
|
157 if (status < 0) |
|
158 { |
|
159 using namespace std; |
|
160 msg = ::strerror (errno); |
|
161 } |
|
162 #else |
|
163 msg = NOT_SUPPORTED ("link"); |
|
164 #endif |
|
165 |
|
166 return status; |
|
167 } |
|
168 |
|
169 // I don't know how to emulate this on systems that don't provide it. |
|
170 |
|
171 int |
|
172 file_ops::symlink (const std::string& old_name, const std::string& new_name) |
|
173 { |
|
174 std::string msg; |
|
175 return symlink (old_name, new_name, msg); |
|
176 } |
|
177 |
|
178 int |
|
179 file_ops::symlink (const std::string& old_name, |
|
180 const std::string& new_name, std::string& msg) |
|
181 { |
|
182 msg = std::string (); |
|
183 |
|
184 int status = -1; |
|
185 |
|
186 #if defined (HAVE_SYMLINK) |
4577
|
187 |
|
188 OCTAVE_LOCAL_BUFFER (char, old_nm, old_name.length ()); |
|
189 OCTAVE_LOCAL_BUFFER (char, new_nm, new_name.length ()); |
|
190 |
|
191 strcpy (old_nm, old_name.c_str ()); |
|
192 strcpy (new_nm, new_name.c_str ()); |
|
193 |
|
194 status = ::symlink (old_nm, new_nm); |
3710
|
195 |
|
196 if (status < 0) |
|
197 { |
|
198 using namespace std; |
|
199 msg = ::strerror (errno); |
|
200 } |
|
201 #else |
|
202 msg = NOT_SUPPORTED ("symlink"); |
|
203 #endif |
|
204 |
|
205 return status; |
|
206 } |
|
207 |
|
208 // We provide a replacement for rename(). |
|
209 |
|
210 int |
|
211 file_ops::readlink (const std::string& path, std::string& result) |
|
212 { |
|
213 std::string msg; |
|
214 return readlink (path, result, msg); |
|
215 } |
|
216 |
|
217 int |
|
218 file_ops::readlink (const std::string& path, std::string& result, |
|
219 std::string& msg) |
|
220 { |
|
221 int status = -1; |
|
222 |
|
223 msg = std::string (); |
|
224 |
4066
|
225 #if defined (HAVE_READLINK) |
3710
|
226 char buf[MAXPATHLEN+1]; |
|
227 |
4577
|
228 OCTAVE_LOCAL_BUFFER (char, p, path.length ()); |
|
229 |
|
230 strcpy (p, path.c_str ()); |
|
231 |
|
232 status = ::readlink (p, buf, MAXPATHLEN); |
3710
|
233 |
|
234 if (status < 0) |
|
235 { |
|
236 using namespace std; |
|
237 msg = ::strerror (errno); |
|
238 } |
|
239 else |
|
240 { |
|
241 buf[status] = '\0'; |
3769
|
242 result = std::string (buf); |
3710
|
243 status = 0; |
|
244 } |
|
245 #else |
|
246 msg = NOT_SUPPORTED ("rename"); |
|
247 #endif |
|
248 |
|
249 return status; |
|
250 } |
|
251 |
2433
|
252 // We provide a replacement for rename(). |
|
253 |
1765
|
254 int |
3504
|
255 file_ops::rename (const std::string& from, const std::string& to) |
1765
|
256 { |
3504
|
257 std::string msg; |
2937
|
258 return rename (from, to, msg); |
1765
|
259 } |
|
260 |
2668
|
261 int |
3504
|
262 file_ops::rename (const std::string& from, const std::string& to, |
|
263 std::string& msg) |
2668
|
264 { |
2937
|
265 int status = -1; |
|
266 |
3504
|
267 msg = std::string (); |
2668
|
268 |
2937
|
269 #if defined (HAVE_RENAME) |
|
270 status = ::rename (from.c_str (), to.c_str ()); |
2668
|
271 |
|
272 if (status < 0) |
3504
|
273 { |
|
274 using namespace std; |
|
275 msg = ::strerror (errno); |
|
276 } |
2937
|
277 #else |
|
278 msg = NOT_SUPPORTED ("rename"); |
|
279 #endif |
2668
|
280 |
|
281 return status; |
|
282 } |
|
283 |
2433
|
284 // We provide a replacement for rmdir(). |
|
285 |
1765
|
286 int |
3504
|
287 file_ops::rmdir (const std::string& name) |
1765
|
288 { |
3504
|
289 std::string msg; |
2937
|
290 return rmdir (name, msg); |
1765
|
291 } |
|
292 |
2668
|
293 int |
3504
|
294 file_ops::rmdir (const std::string& name, std::string& msg) |
2668
|
295 { |
3504
|
296 msg = std::string (); |
2668
|
297 |
2937
|
298 int status = -1; |
|
299 |
|
300 #if defined (HAVE_RMDIR) |
|
301 status = ::rmdir (name.c_str ()); |
2668
|
302 |
|
303 if (status < 0) |
3504
|
304 { |
|
305 using namespace std; |
|
306 msg = ::strerror (errno); |
|
307 } |
2937
|
308 #else |
|
309 msg = NOT_SUPPORTED ("rmdir"); |
|
310 #endif |
2668
|
311 |
|
312 return status; |
|
313 } |
|
314 |
5138
|
315 std::string |
|
316 file_ops::canonicalize_file_name (const std::string& name) |
|
317 { |
|
318 std::string msg; |
|
319 return canonicalize_file_name (name, msg); |
|
320 } |
|
321 |
|
322 std::string |
|
323 file_ops::canonicalize_file_name (const std::string& name, std::string& msg) |
|
324 { |
|
325 msg = std::string (); |
|
326 |
|
327 std::string retval; |
|
328 |
|
329 #if defined (HAVE_CANONICALIZE_FILE_NAME) |
|
330 |
|
331 char *tmp = ::canonicalize_file_name (name.c_str ()); |
|
332 |
|
333 if (tmp) |
|
334 { |
|
335 retval = tmp; |
|
336 ::free (tmp); |
|
337 } |
|
338 |
|
339 #elif defined (HAVE_RESOLVEPATH) |
|
340 |
|
341 #if !defined (errno) |
|
342 extern int errno; |
|
343 #endif |
|
344 |
|
345 #if !defined (__set_errno) |
|
346 # define __set_errno(Val) errno = (Val) |
|
347 #endif |
|
348 |
|
349 if (name.empty ()) |
|
350 { |
|
351 __set_errno (ENOENT); |
|
352 return retval; |
|
353 } |
|
354 |
|
355 // All known hosts with resolvepath (e.g. Solaris 7) don't turn |
|
356 // relative names into absolute ones, so prepend the working |
|
357 // directory if the path is not absolute. |
|
358 |
5149
|
359 std::string absolute_name |
|
360 = octave_env::make_absolute (name, octave_env::getcwd ()); |
5138
|
361 |
5149
|
362 size_t resolved_size = absolute_name.length (); |
5138
|
363 |
|
364 while (1) |
|
365 { |
|
366 resolved_size = 2 * resolved_size + 1; |
|
367 |
|
368 OCTAVE_LOCAL_BUFFER (char, resolved, resolved_size); |
|
369 |
5149
|
370 int resolved_len |
|
371 = ::resolvepath (absolute_name.c_str (), resolved, resolved_size); |
5138
|
372 |
|
373 if (resolved_len < 0) |
|
374 break; |
|
375 |
|
376 if (resolved_len < resolved_size) |
|
377 { |
|
378 retval = resolved; |
|
379 break; |
|
380 } |
|
381 } |
|
382 |
|
383 #else |
|
384 |
|
385 // XXX FIXME XXX -- provide replacement here... |
|
386 retval = name; |
|
387 |
|
388 #endif |
|
389 |
|
390 if (retval.empty ()) |
|
391 { |
|
392 using namespace std; |
|
393 msg = ::strerror (errno); |
|
394 } |
|
395 |
|
396 return retval; |
|
397 } |
|
398 |
2433
|
399 // We provide a replacement for tempnam(). |
|
400 |
3504
|
401 std::string |
|
402 file_ops::tempnam (const std::string& dir, const std::string& pfx) |
1802
|
403 { |
3504
|
404 std::string msg; |
2937
|
405 return tempnam (dir, pfx, msg); |
|
406 } |
|
407 |
3504
|
408 std::string |
|
409 file_ops::tempnam (const std::string& dir, const std::string& pfx, |
|
410 std::string& msg) |
2937
|
411 { |
3504
|
412 msg = std::string (); |
2937
|
413 |
3504
|
414 std::string retval; |
2937
|
415 |
|
416 const char *pdir = dir.empty () ? 0 : dir.c_str (); |
1802
|
417 |
2937
|
418 const char *ppfx = pfx.empty () ? 0 : pfx.c_str (); |
|
419 |
|
420 char *tmp = ::tempnam (pdir, ppfx); |
1802
|
421 |
|
422 if (tmp) |
|
423 { |
|
424 retval = tmp; |
|
425 |
2937
|
426 ::free (tmp); |
1802
|
427 } |
|
428 else |
3504
|
429 { |
|
430 using namespace std; |
|
431 msg = ::strerror (errno); |
|
432 } |
1802
|
433 |
|
434 return retval; |
|
435 } |
|
436 |
3040
|
437 // The following tilde-expansion code was stolen and adapted from |
|
438 // readline. |
2926
|
439 |
3040
|
440 // The default value of tilde_additional_prefixes. This is set to |
|
441 // whitespace preceding a tilde so that simple programs which do not |
|
442 // perform any word separation get desired behaviour. |
|
443 static const char *default_prefixes[] = { " ~", "\t~", ":~", 0 }; |
|
444 |
|
445 // The default value of tilde_additional_suffixes. This is set to |
|
446 // whitespace or newline so that simple programs which do not perform |
|
447 // any word separation get desired behaviour. |
|
448 static const char *default_suffixes[] = { " ", "\n", ":", 0 }; |
|
449 |
|
450 // If non-null, this contains the address of a function that the |
|
451 // application wants called before trying the standard tilde |
|
452 // expansions. The function is called with the text sans tilde, and |
|
453 // returns a malloc()'ed string which is the expansion, or a NULL |
|
454 // pointer if the expansion fails. |
|
455 file_ops::tilde_expansion_hook file_ops::tilde_expansion_preexpansion_hook = 0; |
|
456 |
|
457 // If non-null, this contains the address of a function to call if the |
|
458 // standard meaning for expanding a tilde fails. The function is |
|
459 // called with the text (sans tilde, as in "foo"), and returns a |
|
460 // malloc()'ed string which is the expansion, or a NULL pointer if |
|
461 // there is no expansion. |
|
462 file_ops::tilde_expansion_hook file_ops::tilde_expansion_failure_hook = 0; |
|
463 |
|
464 // When non-null, this is a NULL terminated array of strings which are |
|
465 // duplicates for a tilde prefix. Bash uses this to expand `=~' and |
|
466 // `:~'. |
|
467 string_vector file_ops::tilde_additional_prefixes = default_prefixes; |
|
468 |
|
469 // When non-null, this is a NULL terminated array of strings which |
|
470 // match the end of a username, instead of just "/". Bash sets this |
|
471 // to `:' and `=~'. |
|
472 string_vector file_ops::tilde_additional_suffixes = default_suffixes; |
|
473 |
|
474 // Find the start of a tilde expansion in S, and return the index |
|
475 // of the tilde which starts the expansion. Place the length of the |
|
476 // text which identified this tilde starter in LEN, excluding the |
|
477 // tilde itself. |
|
478 |
|
479 static size_t |
3504
|
480 tilde_find_prefix (const std::string& s, size_t& len) |
3040
|
481 { |
|
482 len = 0; |
|
483 |
|
484 size_t s_len = s.length (); |
|
485 |
|
486 if (s_len == 0 || s[0] == '~') |
|
487 return 0; |
|
488 |
|
489 string_vector prefixes = file_ops::tilde_additional_prefixes; |
|
490 |
|
491 if (! prefixes.empty ()) |
|
492 { |
|
493 for (size_t i = 0; i < s_len; i++) |
|
494 { |
|
495 for (int j = 0; j < prefixes.length (); j++) |
|
496 { |
|
497 size_t pfx_len = prefixes[j].length (); |
|
498 |
|
499 if (prefixes[j].compare (s.substr (i, pfx_len)) == 0) |
|
500 { |
|
501 len = pfx_len - 1; |
|
502 return i + len; |
|
503 } |
|
504 } |
|
505 } |
|
506 } |
|
507 |
|
508 return s_len; |
|
509 } |
|
510 |
|
511 // Find the end of a tilde expansion in S, and return the index |
|
512 // of the character which ends the tilde definition. |
|
513 |
|
514 static size_t |
3504
|
515 tilde_find_suffix (const std::string& s) |
3040
|
516 { |
|
517 size_t s_len = s.length (); |
|
518 |
|
519 string_vector suffixes = file_ops::tilde_additional_suffixes; |
|
520 |
|
521 size_t i = 0; |
|
522 |
|
523 for ( ; i < s_len; i++) |
|
524 { |
4101
|
525 if (s[i] == file_ops::dir_sep_char) |
3040
|
526 break; |
|
527 |
|
528 if (! suffixes.empty ()) |
|
529 { |
|
530 for (int j = 0; j < suffixes.length (); j++) |
|
531 { |
|
532 size_t sfx_len = suffixes[j].length (); |
|
533 |
|
534 if (suffixes[j].compare (s.substr (i, sfx_len)) == 0) |
|
535 return i; |
|
536 } |
|
537 } |
|
538 } |
|
539 |
|
540 return i; |
|
541 } |
|
542 |
|
543 // Take FNAME and return the tilde prefix we want expanded. |
|
544 |
3504
|
545 static std::string |
|
546 isolate_tilde_prefix (const std::string& fname) |
3040
|
547 { |
|
548 size_t f_len = fname.length (); |
|
549 |
|
550 size_t len = 1; |
|
551 |
4101
|
552 while (len < f_len && fname[len] != file_ops::dir_sep_char) |
3040
|
553 len++; |
|
554 |
|
555 return fname.substr (1, len); |
|
556 } |
|
557 |
|
558 // Do the work of tilde expansion on FILENAME. FILENAME starts with a |
|
559 // tilde. |
|
560 |
3504
|
561 static std::string |
|
562 tilde_expand_word (const std::string& filename) |
3040
|
563 { |
|
564 size_t f_len = filename.length (); |
|
565 |
|
566 if (f_len == 0 || filename[0] != '~') |
|
567 return filename; |
|
568 |
|
569 // A leading `~/' or a bare `~' is *always* translated to the value |
|
570 // of $HOME or the home directory of the current user, regardless of |
|
571 // any preexpansion hook. |
|
572 |
4101
|
573 if (f_len == 1 || filename[1] == file_ops::dir_sep_char) |
3040
|
574 return octave_env::get_home_directory () + filename.substr (1); |
|
575 |
3504
|
576 std::string username = isolate_tilde_prefix (filename); |
3040
|
577 |
|
578 size_t user_len = username.length (); |
|
579 |
3504
|
580 std::string dirname; |
3040
|
581 |
|
582 if (file_ops::tilde_expansion_preexpansion_hook) |
|
583 { |
3504
|
584 std::string expansion |
3040
|
585 = file_ops::tilde_expansion_preexpansion_hook (username); |
|
586 |
|
587 if (! expansion.empty ()) |
3074
|
588 return expansion + filename.substr (user_len+1); |
3040
|
589 } |
|
590 |
|
591 // No preexpansion hook, or the preexpansion hook failed. Look in the |
|
592 // password database. |
|
593 |
|
594 octave_passwd pw = octave_passwd::getpwnam (username); |
|
595 |
|
596 if (! pw) |
|
597 { |
|
598 // If the calling program has a special syntax for expanding tildes, |
|
599 // and we couldn't find a standard expansion, then let them try. |
|
600 |
|
601 if (file_ops::tilde_expansion_failure_hook) |
|
602 { |
3504
|
603 std::string expansion |
3040
|
604 = file_ops::tilde_expansion_failure_hook (username); |
|
605 |
|
606 if (! expansion.empty ()) |
3074
|
607 dirname = expansion + filename.substr (user_len+1); |
3040
|
608 } |
|
609 |
|
610 // If we don't have a failure hook, or if the failure hook did not |
|
611 // expand the tilde, return a copy of what we were passed. |
|
612 |
|
613 if (dirname.length () == 0) |
|
614 dirname = filename; |
|
615 } |
|
616 else |
3074
|
617 dirname = pw.dir () + filename.substr (user_len+1); |
3040
|
618 |
|
619 return dirname; |
|
620 } |
|
621 |
|
622 // If NAME has a leading ~ or ~user, Unix-style, expand it to the |
|
623 // user's home directory. If no ~, or no <pwd.h>, just return NAME. |
|
624 |
3504
|
625 std::string |
|
626 file_ops::tilde_expand (const std::string& name) |
2926
|
627 { |
3504
|
628 std::string result; |
2926
|
629 |
3040
|
630 size_t name_len = name.length (); |
2926
|
631 |
3040
|
632 // Scan through S expanding tildes as we come to them. |
2926
|
633 |
3040
|
634 size_t pos = 0; |
2926
|
635 |
3040
|
636 while (1) |
|
637 { |
|
638 if (pos > name_len) |
|
639 break; |
2926
|
640 |
3040
|
641 size_t len; |
|
642 |
|
643 // Make START point to the tilde which starts the expansion. |
2926
|
644 |
3040
|
645 size_t start = tilde_find_prefix (name.substr (pos), len); |
|
646 |
|
647 result.append (name.substr (pos, start)); |
2926
|
648 |
3040
|
649 // Advance STRING to the starting tilde. |
|
650 |
|
651 pos += start; |
2926
|
652 |
3040
|
653 // Make FINI be the index of one after the last character of the |
|
654 // username. |
2926
|
655 |
3040
|
656 size_t fini = tilde_find_suffix (name.substr (pos)); |
2926
|
657 |
3040
|
658 // If both START and FINI are zero, we are all done. |
2926
|
659 |
3040
|
660 if (! (start || fini)) |
|
661 break; |
2926
|
662 |
3040
|
663 // Expand the entire tilde word, and copy it into RESULT. |
2947
|
664 |
3504
|
665 std::string tilde_word = name.substr (pos, fini); |
3040
|
666 |
|
667 pos += fini; |
2926
|
668 |
3504
|
669 std::string expansion = tilde_expand_word (tilde_word); |
3040
|
670 |
|
671 result.append (expansion); |
2926
|
672 } |
|
673 |
3040
|
674 return result; |
2926
|
675 } |
|
676 |
|
677 // A vector version of the above. |
|
678 |
|
679 string_vector |
|
680 file_ops::tilde_expand (const string_vector& names) |
|
681 { |
|
682 string_vector retval; |
|
683 |
|
684 int n = names.length (); |
|
685 |
|
686 retval.resize (n); |
|
687 |
|
688 for (int i = 0; i < n; i++) |
|
689 retval[i] = file_ops::tilde_expand (names[i]); |
|
690 |
|
691 return retval; |
|
692 } |
1802
|
693 |
1765
|
694 int |
2926
|
695 file_ops::umask (mode_t mode) |
1765
|
696 { |
|
697 #if defined (HAVE_UMASK) |
2926
|
698 return ::umask (mode); |
1765
|
699 #else |
|
700 return 0; |
|
701 #endif |
|
702 } |
|
703 |
1773
|
704 int |
3504
|
705 file_ops::unlink (const std::string& name) |
1773
|
706 { |
3504
|
707 std::string msg; |
2937
|
708 return unlink (name, msg); |
1773
|
709 } |
|
710 |
2668
|
711 int |
3504
|
712 file_ops::unlink (const std::string& name, std::string& msg) |
2668
|
713 { |
3504
|
714 msg = std::string (); |
2668
|
715 |
2937
|
716 int status = -1; |
|
717 |
|
718 #if defined (HAVE_UNLINK) |
|
719 status = ::unlink (name.c_str ()); |
2668
|
720 |
|
721 if (status < 0) |
3504
|
722 { |
|
723 using namespace std; |
|
724 msg = ::strerror (errno); |
|
725 } |
2937
|
726 #else |
|
727 msg = NOT_SUPPORTED ("unlink"); |
|
728 #endif |
2668
|
729 |
|
730 return status; |
|
731 } |
|
732 |
4097
|
733 bool |
|
734 file_ops::is_dir_sep (char c) |
|
735 { |
4101
|
736 return dir_sep_chars.find (c) != NPOS; |
4097
|
737 } |
|
738 |
1765
|
739 /* |
|
740 ;;; Local Variables: *** |
|
741 ;;; mode: C++ *** |
|
742 ;;; End: *** |
|
743 */ |