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