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 |
|
358 name = octave_env::make_absolute (name); |
|
359 |
|
360 size_t resolved_size = name.length (); |
|
361 |
|
362 while (1) |
|
363 { |
|
364 resolved_size = 2 * resolved_size + 1; |
|
365 |
|
366 OCTAVE_LOCAL_BUFFER (char, resolved, resolved_size); |
|
367 |
|
368 resolved_len = ::resolvepath (name, resolved, resolved_size); |
|
369 |
|
370 if (resolved_len < 0) |
|
371 break; |
|
372 |
|
373 if (resolved_len < resolved_size) |
|
374 { |
|
375 retval = resolved; |
|
376 break; |
|
377 } |
|
378 } |
|
379 |
|
380 #else |
|
381 |
|
382 // XXX FIXME XXX -- provide replacement here... |
|
383 retval = name; |
|
384 |
|
385 #endif |
|
386 |
|
387 if (retval.empty ()) |
|
388 { |
|
389 using namespace std; |
|
390 msg = ::strerror (errno); |
|
391 } |
|
392 |
|
393 return retval; |
|
394 } |
|
395 |
2433
|
396 // We provide a replacement for tempnam(). |
|
397 |
3504
|
398 std::string |
|
399 file_ops::tempnam (const std::string& dir, const std::string& pfx) |
1802
|
400 { |
3504
|
401 std::string msg; |
2937
|
402 return tempnam (dir, pfx, msg); |
|
403 } |
|
404 |
3504
|
405 std::string |
|
406 file_ops::tempnam (const std::string& dir, const std::string& pfx, |
|
407 std::string& msg) |
2937
|
408 { |
3504
|
409 msg = std::string (); |
2937
|
410 |
3504
|
411 std::string retval; |
2937
|
412 |
|
413 const char *pdir = dir.empty () ? 0 : dir.c_str (); |
1802
|
414 |
2937
|
415 const char *ppfx = pfx.empty () ? 0 : pfx.c_str (); |
|
416 |
|
417 char *tmp = ::tempnam (pdir, ppfx); |
1802
|
418 |
|
419 if (tmp) |
|
420 { |
|
421 retval = tmp; |
|
422 |
2937
|
423 ::free (tmp); |
1802
|
424 } |
|
425 else |
3504
|
426 { |
|
427 using namespace std; |
|
428 msg = ::strerror (errno); |
|
429 } |
1802
|
430 |
|
431 return retval; |
|
432 } |
|
433 |
3040
|
434 // The following tilde-expansion code was stolen and adapted from |
|
435 // readline. |
2926
|
436 |
3040
|
437 // The default value of tilde_additional_prefixes. This is set to |
|
438 // whitespace preceding a tilde so that simple programs which do not |
|
439 // perform any word separation get desired behaviour. |
|
440 static const char *default_prefixes[] = { " ~", "\t~", ":~", 0 }; |
|
441 |
|
442 // The default value of tilde_additional_suffixes. This is set to |
|
443 // whitespace or newline so that simple programs which do not perform |
|
444 // any word separation get desired behaviour. |
|
445 static const char *default_suffixes[] = { " ", "\n", ":", 0 }; |
|
446 |
|
447 // If non-null, this contains the address of a function that the |
|
448 // application wants called before trying the standard tilde |
|
449 // expansions. The function is called with the text sans tilde, and |
|
450 // returns a malloc()'ed string which is the expansion, or a NULL |
|
451 // pointer if the expansion fails. |
|
452 file_ops::tilde_expansion_hook file_ops::tilde_expansion_preexpansion_hook = 0; |
|
453 |
|
454 // If non-null, this contains the address of a function to call if the |
|
455 // standard meaning for expanding a tilde fails. The function is |
|
456 // called with the text (sans tilde, as in "foo"), and returns a |
|
457 // malloc()'ed string which is the expansion, or a NULL pointer if |
|
458 // there is no expansion. |
|
459 file_ops::tilde_expansion_hook file_ops::tilde_expansion_failure_hook = 0; |
|
460 |
|
461 // When non-null, this is a NULL terminated array of strings which are |
|
462 // duplicates for a tilde prefix. Bash uses this to expand `=~' and |
|
463 // `:~'. |
|
464 string_vector file_ops::tilde_additional_prefixes = default_prefixes; |
|
465 |
|
466 // When non-null, this is a NULL terminated array of strings which |
|
467 // match the end of a username, instead of just "/". Bash sets this |
|
468 // to `:' and `=~'. |
|
469 string_vector file_ops::tilde_additional_suffixes = default_suffixes; |
|
470 |
|
471 // Find the start of a tilde expansion in S, and return the index |
|
472 // of the tilde which starts the expansion. Place the length of the |
|
473 // text which identified this tilde starter in LEN, excluding the |
|
474 // tilde itself. |
|
475 |
|
476 static size_t |
3504
|
477 tilde_find_prefix (const std::string& s, size_t& len) |
3040
|
478 { |
|
479 len = 0; |
|
480 |
|
481 size_t s_len = s.length (); |
|
482 |
|
483 if (s_len == 0 || s[0] == '~') |
|
484 return 0; |
|
485 |
|
486 string_vector prefixes = file_ops::tilde_additional_prefixes; |
|
487 |
|
488 if (! prefixes.empty ()) |
|
489 { |
|
490 for (size_t i = 0; i < s_len; i++) |
|
491 { |
|
492 for (int j = 0; j < prefixes.length (); j++) |
|
493 { |
|
494 size_t pfx_len = prefixes[j].length (); |
|
495 |
|
496 if (prefixes[j].compare (s.substr (i, pfx_len)) == 0) |
|
497 { |
|
498 len = pfx_len - 1; |
|
499 return i + len; |
|
500 } |
|
501 } |
|
502 } |
|
503 } |
|
504 |
|
505 return s_len; |
|
506 } |
|
507 |
|
508 // Find the end of a tilde expansion in S, and return the index |
|
509 // of the character which ends the tilde definition. |
|
510 |
|
511 static size_t |
3504
|
512 tilde_find_suffix (const std::string& s) |
3040
|
513 { |
|
514 size_t s_len = s.length (); |
|
515 |
|
516 string_vector suffixes = file_ops::tilde_additional_suffixes; |
|
517 |
|
518 size_t i = 0; |
|
519 |
|
520 for ( ; i < s_len; i++) |
|
521 { |
4101
|
522 if (s[i] == file_ops::dir_sep_char) |
3040
|
523 break; |
|
524 |
|
525 if (! suffixes.empty ()) |
|
526 { |
|
527 for (int j = 0; j < suffixes.length (); j++) |
|
528 { |
|
529 size_t sfx_len = suffixes[j].length (); |
|
530 |
|
531 if (suffixes[j].compare (s.substr (i, sfx_len)) == 0) |
|
532 return i; |
|
533 } |
|
534 } |
|
535 } |
|
536 |
|
537 return i; |
|
538 } |
|
539 |
|
540 // Take FNAME and return the tilde prefix we want expanded. |
|
541 |
3504
|
542 static std::string |
|
543 isolate_tilde_prefix (const std::string& fname) |
3040
|
544 { |
|
545 size_t f_len = fname.length (); |
|
546 |
|
547 size_t len = 1; |
|
548 |
4101
|
549 while (len < f_len && fname[len] != file_ops::dir_sep_char) |
3040
|
550 len++; |
|
551 |
|
552 return fname.substr (1, len); |
|
553 } |
|
554 |
|
555 // Do the work of tilde expansion on FILENAME. FILENAME starts with a |
|
556 // tilde. |
|
557 |
3504
|
558 static std::string |
|
559 tilde_expand_word (const std::string& filename) |
3040
|
560 { |
|
561 size_t f_len = filename.length (); |
|
562 |
|
563 if (f_len == 0 || filename[0] != '~') |
|
564 return filename; |
|
565 |
|
566 // A leading `~/' or a bare `~' is *always* translated to the value |
|
567 // of $HOME or the home directory of the current user, regardless of |
|
568 // any preexpansion hook. |
|
569 |
4101
|
570 if (f_len == 1 || filename[1] == file_ops::dir_sep_char) |
3040
|
571 return octave_env::get_home_directory () + filename.substr (1); |
|
572 |
3504
|
573 std::string username = isolate_tilde_prefix (filename); |
3040
|
574 |
|
575 size_t user_len = username.length (); |
|
576 |
3504
|
577 std::string dirname; |
3040
|
578 |
|
579 if (file_ops::tilde_expansion_preexpansion_hook) |
|
580 { |
3504
|
581 std::string expansion |
3040
|
582 = file_ops::tilde_expansion_preexpansion_hook (username); |
|
583 |
|
584 if (! expansion.empty ()) |
3074
|
585 return expansion + filename.substr (user_len+1); |
3040
|
586 } |
|
587 |
|
588 // No preexpansion hook, or the preexpansion hook failed. Look in the |
|
589 // password database. |
|
590 |
|
591 octave_passwd pw = octave_passwd::getpwnam (username); |
|
592 |
|
593 if (! pw) |
|
594 { |
|
595 // If the calling program has a special syntax for expanding tildes, |
|
596 // and we couldn't find a standard expansion, then let them try. |
|
597 |
|
598 if (file_ops::tilde_expansion_failure_hook) |
|
599 { |
3504
|
600 std::string expansion |
3040
|
601 = file_ops::tilde_expansion_failure_hook (username); |
|
602 |
|
603 if (! expansion.empty ()) |
3074
|
604 dirname = expansion + filename.substr (user_len+1); |
3040
|
605 } |
|
606 |
|
607 // If we don't have a failure hook, or if the failure hook did not |
|
608 // expand the tilde, return a copy of what we were passed. |
|
609 |
|
610 if (dirname.length () == 0) |
|
611 dirname = filename; |
|
612 } |
|
613 else |
3074
|
614 dirname = pw.dir () + filename.substr (user_len+1); |
3040
|
615 |
|
616 return dirname; |
|
617 } |
|
618 |
|
619 // If NAME has a leading ~ or ~user, Unix-style, expand it to the |
|
620 // user's home directory. If no ~, or no <pwd.h>, just return NAME. |
|
621 |
3504
|
622 std::string |
|
623 file_ops::tilde_expand (const std::string& name) |
2926
|
624 { |
3504
|
625 std::string result; |
2926
|
626 |
3040
|
627 size_t name_len = name.length (); |
2926
|
628 |
3040
|
629 // Scan through S expanding tildes as we come to them. |
2926
|
630 |
3040
|
631 size_t pos = 0; |
2926
|
632 |
3040
|
633 while (1) |
|
634 { |
|
635 if (pos > name_len) |
|
636 break; |
2926
|
637 |
3040
|
638 size_t len; |
|
639 |
|
640 // Make START point to the tilde which starts the expansion. |
2926
|
641 |
3040
|
642 size_t start = tilde_find_prefix (name.substr (pos), len); |
|
643 |
|
644 result.append (name.substr (pos, start)); |
2926
|
645 |
3040
|
646 // Advance STRING to the starting tilde. |
|
647 |
|
648 pos += start; |
2926
|
649 |
3040
|
650 // Make FINI be the index of one after the last character of the |
|
651 // username. |
2926
|
652 |
3040
|
653 size_t fini = tilde_find_suffix (name.substr (pos)); |
2926
|
654 |
3040
|
655 // If both START and FINI are zero, we are all done. |
2926
|
656 |
3040
|
657 if (! (start || fini)) |
|
658 break; |
2926
|
659 |
3040
|
660 // Expand the entire tilde word, and copy it into RESULT. |
2947
|
661 |
3504
|
662 std::string tilde_word = name.substr (pos, fini); |
3040
|
663 |
|
664 pos += fini; |
2926
|
665 |
3504
|
666 std::string expansion = tilde_expand_word (tilde_word); |
3040
|
667 |
|
668 result.append (expansion); |
2926
|
669 } |
|
670 |
3040
|
671 return result; |
2926
|
672 } |
|
673 |
|
674 // A vector version of the above. |
|
675 |
|
676 string_vector |
|
677 file_ops::tilde_expand (const string_vector& names) |
|
678 { |
|
679 string_vector retval; |
|
680 |
|
681 int n = names.length (); |
|
682 |
|
683 retval.resize (n); |
|
684 |
|
685 for (int i = 0; i < n; i++) |
|
686 retval[i] = file_ops::tilde_expand (names[i]); |
|
687 |
|
688 return retval; |
|
689 } |
1802
|
690 |
1765
|
691 int |
2926
|
692 file_ops::umask (mode_t mode) |
1765
|
693 { |
|
694 #if defined (HAVE_UMASK) |
2926
|
695 return ::umask (mode); |
1765
|
696 #else |
|
697 return 0; |
|
698 #endif |
|
699 } |
|
700 |
1773
|
701 int |
3504
|
702 file_ops::unlink (const std::string& name) |
1773
|
703 { |
3504
|
704 std::string msg; |
2937
|
705 return unlink (name, msg); |
1773
|
706 } |
|
707 |
2668
|
708 int |
3504
|
709 file_ops::unlink (const std::string& name, std::string& msg) |
2668
|
710 { |
3504
|
711 msg = std::string (); |
2668
|
712 |
2937
|
713 int status = -1; |
|
714 |
|
715 #if defined (HAVE_UNLINK) |
|
716 status = ::unlink (name.c_str ()); |
2668
|
717 |
|
718 if (status < 0) |
3504
|
719 { |
|
720 using namespace std; |
|
721 msg = ::strerror (errno); |
|
722 } |
2937
|
723 #else |
|
724 msg = NOT_SUPPORTED ("unlink"); |
|
725 #endif |
2668
|
726 |
|
727 return status; |
|
728 } |
|
729 |
4097
|
730 bool |
|
731 file_ops::is_dir_sep (char c) |
|
732 { |
4101
|
733 return dir_sep_chars.find (c) != NPOS; |
4097
|
734 } |
|
735 |
1765
|
736 /* |
|
737 ;;; Local Variables: *** |
|
738 ;;; mode: C++ *** |
|
739 ;;; End: *** |
|
740 */ |