Merge branch '1783_remove_bzero_decl'
[free-mc.git] / vfs / utilvfs.c
blob7abc068ac1cecef830406865796ed7f5ce7f1518
1 /* Utilities for VFS modules.
3 Copyright (C) 1988, 1992, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
4 2005, 2006, 2007 Free Software Foundation, Inc.
5 Copyright (C) 1995, 1996 Miguel de Icaza
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public License
9 as published by the Free Software Foundation; either version 2 of
10 the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Library General Public License for more details.
17 You should have received a copy of the GNU Library General Public
18 License along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
21 /**
22 * \file
23 * \brief Source: Utilities for VFS modules
24 * \author Miguel de Icaza
25 * \date 1995, 1996
28 #include <config.h>
30 #include <ctype.h>
32 #include <pwd.h>
33 #include <grp.h>
34 #include <stdlib.h>
36 #include "../src/global.h"
38 #include "../src/wtools.h" /* message() */
39 #include "../src/main.h" /* print_vfs_message */
40 #include "../src/unixcompat.h"
41 #include "../src/history.h"
43 #include "vfs.h"
44 #include "utilvfs.h"
46 /* Extract the hostname and username from the path */
47 /* path is in the form: [user@]hostname:port/remote-dir, e.g.:
49 * ftp://sunsite.unc.edu/pub/linux
50 * ftp://miguel@sphinx.nuclecu.unam.mx/c/nc
51 * ftp://tsx-11.mit.edu:8192/
52 * ftp://joe@foo.edu:11321/private
53 * ftp://joe:password@foo.se
55 * Returns g_malloc()ed host, user and pass they are present.
56 * If the user is empty, e.g. ftp://@roxanne/private, and URL_ALLOW_ANON
57 * is not set, then the current login name is supplied.
59 * Return value is a g_malloc()ed string with the pathname relative to the
60 * host.
63 #ifdef USE_NETCODE
64 char *
65 vfs_split_url (const char *path, char **host, char **user, int *port,
66 char **pass, int default_port, int flags)
68 struct passwd *passwd_info;
69 char *dir, *colon, *inner_colon, *at, *rest;
70 char *retval;
71 char * const pcopy = g_strdup (path);
72 const char *pend = pcopy + strlen (pcopy);
74 if (pass)
75 *pass = NULL;
76 *port = default_port;
77 *user = NULL;
78 retval = NULL;
80 dir = pcopy;
81 if (!(flags & URL_NOSLASH)) {
82 /* locate path component */
83 while (*dir != PATH_SEP && *dir)
84 dir++;
85 if (*dir) {
86 retval = g_strdup (dir);
87 *dir = 0;
88 } else
89 retval = g_strdup (PATH_SEP_STR);
92 /* search for any possible user */
93 at = strrchr (pcopy, '@');
95 /* We have a username */
96 if (at) {
97 *at = 0;
98 inner_colon = strchr (pcopy, ':');
99 if (inner_colon) {
100 *inner_colon = 0;
101 inner_colon++;
102 if (pass)
103 *pass = g_strdup (inner_colon);
105 if (*pcopy != 0)
106 *user = g_strdup (pcopy);
108 if (pend == at + 1)
109 rest = at;
110 else
111 rest = at + 1;
112 } else
113 rest = pcopy;
115 if (!*user && !(flags & URL_ALLOW_ANON)) {
116 passwd_info = getpwuid (geteuid ());
117 if (passwd_info && passwd_info->pw_name)
118 *user = g_strdup (passwd_info->pw_name);
119 else {
120 /* This is very unlikely to happen */
121 *user = g_strdup ("anonymous");
123 endpwent ();
126 /* Check if the host comes with a port spec, if so, chop it */
127 if ('[' == *rest) {
128 colon = strchr (++rest, ']');
129 if (colon) {
130 colon[0] = '\0';
131 colon[1] = '\0';
132 colon++;
133 } else {
134 g_free (pcopy);
135 *host = NULL;
136 *port = 0;
137 return NULL;
139 } else
140 colon = strchr (rest, ':');
142 if (colon) {
143 *colon = 0;
144 if (sscanf (colon + 1, "%d", port) == 1) {
145 if (*port <= 0 || *port >= 65536)
146 *port = default_port;
147 } else {
148 while (*(++colon)) {
149 switch (*colon) {
150 case 'C':
151 *port = 1;
152 break;
153 case 'r':
154 *port = 2;
155 break;
160 if (host)
161 *host = g_strdup (rest);
163 g_free (pcopy);
164 return retval;
166 #endif /* USE_NETCODE */
169 * Look up a user or group name from a uid/gid, maintaining a cache.
170 * FIXME, for now it's a one-entry cache.
171 * FIXME2, the "-993" is to reduce the chance of a hit on the first lookup.
172 * This file should be modified for non-unix systems to do something
173 * reasonable.
176 #ifndef TUNMLEN
177 #define TUNMLEN 256
178 #endif
179 #ifndef TGNMLEN
180 #define TGNMLEN 256
181 #endif
183 #define myuid ( my_uid < 0? (my_uid = getuid()): my_uid )
184 #define mygid ( my_gid < 0? (my_gid = getgid()): my_gid )
187 vfs_finduid (const char *uname)
189 static int saveuid = -993;
190 static char saveuname[TUNMLEN];
191 static int my_uid = -993;
193 struct passwd *pw;
195 if (uname[0] != saveuname[0] /* Quick test w/o proc call */
196 ||0 != strncmp (uname, saveuname, TUNMLEN)) {
197 g_strlcpy (saveuname, uname, TUNMLEN);
198 pw = getpwnam (uname);
199 if (pw) {
200 saveuid = pw->pw_uid;
201 } else {
202 saveuid = myuid;
205 return saveuid;
209 vfs_findgid (const char *gname)
211 static int savegid = -993;
212 static char savegname[TGNMLEN];
213 static int my_gid = -993;
215 struct group *gr;
217 if (gname[0] != savegname[0] /* Quick test w/o proc call */
218 ||0 != strncmp (gname, savegname, TUNMLEN)) {
219 g_strlcpy (savegname, gname, TUNMLEN);
220 gr = getgrnam (gname);
221 if (gr) {
222 savegid = gr->gr_gid;
223 } else {
224 savegid = mygid;
227 return savegid;
231 * Create a temporary file with a name resembling the original.
232 * This is needed e.g. for local copies requested by extfs.
233 * Some extfs scripts may look at the extension.
234 * We also protect stupid scripts agains dangerous names.
237 vfs_mkstemps (char **pname, const char *prefix, const char *param_basename)
239 const char *p;
240 char *suffix, *q;
241 int shift;
242 int fd;
244 /* Strip directories */
245 p = strrchr (param_basename, PATH_SEP);
246 if (!p)
247 p = param_basename;
248 else
249 p++;
251 /* Protection against very long names */
252 shift = strlen (p) - (MC_MAXPATHLEN - 16);
253 if (shift > 0)
254 p += shift;
256 suffix = g_malloc (MC_MAXPATHLEN);
258 /* Protection against unusual characters */
259 q = suffix;
260 while (*p && (*p != '#')) {
261 if (strchr (".-_@", *p) || isalnum ((unsigned char) *p))
262 *q++ = *p;
263 p++;
265 *q = 0;
267 fd = mc_mkstemps (pname, prefix, suffix);
268 g_free (suffix);
269 return fd;
272 /* Parsing code is used by ftpfs, fish and extfs */
273 #define MAXCOLS 30
275 static char *columns[MAXCOLS]; /* Points to the string in column n */
276 static int column_ptr[MAXCOLS]; /* Index from 0 to the starting positions of the columns */
279 vfs_split_text (char *p)
281 char *original = p;
282 int numcols;
284 memset (columns, 0, sizeof (columns));
286 for (numcols = 0; *p && numcols < MAXCOLS; numcols++) {
287 while (*p == ' ' || *p == '\r' || *p == '\n') {
288 *p = 0;
289 p++;
291 columns[numcols] = p;
292 column_ptr[numcols] = p - original;
293 while (*p && *p != ' ' && *p != '\r' && *p != '\n')
294 p++;
296 return numcols;
299 static int
300 is_num (int idx)
302 char *column = columns[idx];
304 if (!column || column[0] < '0' || column[0] > '9')
305 return 0;
307 return 1;
310 /* Return 1 for MM-DD-YY and MM-DD-YYYY */
311 static int
312 is_dos_date (const char *str)
314 int len;
316 if (!str)
317 return 0;
319 len = strlen (str);
320 if (len != 8 && len != 10)
321 return 0;
323 if (str[2] != str[5])
324 return 0;
326 if (!strchr ("\\-/", (int) str[2]))
327 return 0;
329 return 1;
332 static int
333 is_week (const char *str, struct tm *tim)
335 static const char *week = "SunMonTueWedThuFriSat";
336 const char *pos;
338 if (!str)
339 return 0;
341 if ((pos = strstr (week, str)) != NULL) {
342 if (tim != NULL)
343 tim->tm_wday = (pos - week) / 3;
344 return 1;
346 return 0;
349 static int
350 is_month (const char *str, struct tm *tim)
352 static const char *month = "JanFebMarAprMayJunJulAugSepOctNovDec";
353 const char *pos;
355 if (!str)
356 return 0;
358 if ((pos = strstr (month, str)) != NULL) {
359 if (tim != NULL)
360 tim->tm_mon = (pos - month) / 3;
361 return 1;
363 return 0;
367 * Check for possible locale's abbreviated month name (Jan..Dec).
368 * Any 3 bytes long string without digit, control and punctuation characters.
369 * isalpha() is locale specific, so it cannot be used if current
370 * locale is "C" and ftp server use Cyrillic.
371 * NB: It is assumed there are no whitespaces in month.
373 static int
374 is_localized_month (const char *month)
376 int i = 0;
378 if (!month)
379 return 0;
381 while ((i < 3) && *month && !isdigit ((unsigned char) *month)
382 && !iscntrl ((unsigned char) *month)
383 && !ispunct ((unsigned char) *month)) {
384 i++;
385 month++;
387 return ((i == 3) && (*month == 0));
390 static int
391 is_time (const char *str, struct tm *tim)
393 const char *p, *p2;
395 if (!str)
396 return 0;
398 if ((p = strchr (str, ':')) && (p2 = strrchr (str, ':'))) {
399 if (p != p2) {
400 if (sscanf
401 (str, "%2d:%2d:%2d", &tim->tm_hour, &tim->tm_min,
402 &tim->tm_sec) != 3)
403 return 0;
404 } else {
405 if (sscanf (str, "%2d:%2d", &tim->tm_hour, &tim->tm_min) != 2)
406 return 0;
408 } else
409 return 0;
411 return 1;
414 static int
415 is_year (char *str, struct tm *tim)
417 long year;
419 if (!str)
420 return 0;
422 if (strchr (str, ':'))
423 return 0;
425 if (strlen (str) != 4)
426 return 0;
428 if (sscanf (str, "%ld", &year) != 1)
429 return 0;
431 if (year < 1900 || year > 3000)
432 return 0;
434 tim->tm_year = (int) (year - 1900);
436 return 1;
439 gboolean
440 vfs_parse_filetype (const char *s, size_t *ret_skipped, mode_t *ret_type)
442 mode_t type;
444 switch (*s) {
445 case 'd': type = S_IFDIR; break;
446 case 'b': type = S_IFBLK; break;
447 case 'c': type = S_IFCHR; break;
448 case 'l': type = S_IFLNK; break;
449 #ifdef S_IFSOCK
450 case 's': type = S_IFSOCK; break;
451 #else
452 case 's': type = S_IFIFO; break;
453 #endif
454 #ifdef S_IFDOOR /* Solaris door */
455 case 'D': type = S_IFDOOR; break;
456 #else
457 case 'D': type = S_IFIFO; break;
458 #endif
459 case 'p': type = S_IFIFO; break;
460 #ifdef S_IFNAM /* Special named files */
461 case 'n': type = S_IFNAM; break;
462 #else
463 case 'n': type = S_IFREG; break;
464 #endif
465 case 'm': /* Don't know what these are :-) */
466 case '-':
467 case '?': type = S_IFREG; break;
468 default: return FALSE;
471 *ret_type = type;
472 *ret_skipped = 1;
473 return TRUE;
476 gboolean
477 vfs_parse_fileperms (const char *s, size_t *ret_skipped, mode_t *ret_perms)
479 const char *p;
480 mode_t perms;
482 p = s;
483 perms = 0;
485 switch (*p++) {
486 case '-': break;
487 case 'r': perms |= S_IRUSR; break;
488 default: return FALSE;
490 switch (*p++) {
491 case '-': break;
492 case 'w': perms |= S_IWUSR; break;
493 default: return FALSE;
495 switch (*p++) {
496 case '-': break;
497 case 'S': perms |= S_ISUID; break;
498 case 's': perms |= S_IXUSR | S_ISUID; break;
499 case 'x': perms |= S_IXUSR; break;
500 default: return FALSE;
502 switch (*p++) {
503 case '-': break;
504 case 'r': perms |= S_IRGRP; break;
505 default: return FALSE;
507 switch (*p++) {
508 case '-': break;
509 case 'w': perms |= S_IWGRP; break;
510 default: return FALSE;
512 switch (*p++) {
513 case '-': break;
514 case 'S': perms |= S_ISGID; break;
515 case 'l': perms |= S_ISGID; break; /* found on Solaris */
516 case 's': perms |= S_IXGRP | S_ISGID; break;
517 case 'x': perms |= S_IXGRP; break;
518 default: return FALSE;
520 switch (*p++) {
521 case '-': break;
522 case 'r': perms |= S_IROTH; break;
523 default: return FALSE;
525 switch (*p++) {
526 case '-': break;
527 case 'w': perms |= S_IWOTH; break;
528 default: return FALSE;
530 switch (*p++) {
531 case '-': break;
532 case 'T': perms |= S_ISVTX; break;
533 case 't': perms |= S_IXOTH | S_ISVTX; break;
534 case 'x': perms |= S_IXOTH; break;
535 default: return FALSE;
537 if (*p == '+') { /* ACLs on Solaris, HP-UX and others */
538 p++;
541 *ret_skipped = p - s;
542 *ret_perms = perms;
543 return TRUE;
546 gboolean
547 vfs_parse_filemode (const char *s, size_t *ret_skipped,
548 mode_t *ret_mode)
550 const char *p;
551 mode_t type, perms;
552 size_t skipped;
554 p = s;
556 if (!vfs_parse_filetype (p, &skipped, &type))
557 return FALSE;
558 p += skipped;
560 if (!vfs_parse_fileperms (p, &skipped, &perms))
561 return FALSE;
562 p += skipped;
564 *ret_skipped = p - s;
565 *ret_mode = type | perms;
566 return TRUE;
569 gboolean
570 vfs_parse_raw_filemode (const char *s, size_t *ret_skipped,
571 mode_t *ret_mode)
573 const char *p;
574 mode_t remote_type = 0, local_type, perms = 0;
576 p = s;
578 /* isoctal */
579 while(*p >= '0' && *p <= '7')
581 perms *= 010;
582 perms += (*p - '0');
583 ++p;
586 if (*p++ != ' ')
587 return FALSE;
589 while(*p >= '0' && *p <= '7')
591 remote_type *= 010;
592 remote_type += (*p - '0');
593 ++p;
596 if (*p++ != ' ')
597 return FALSE;
599 /* generated with:
600 $ perl -e 'use Fcntl ":mode";
601 my @modes = (S_IFDIR, S_IFBLK, S_IFCHR, S_IFLNK, S_IFREG);
602 foreach $t (@modes) { printf ("%o\n", $t); };'
603 TODO: S_IFDOOR, S_IFIFO, S_IFSOCK (if supported by os)
604 (see vfs_parse_filetype)
607 switch (remote_type)
609 case 020000:
610 local_type = S_IFCHR; break;
611 case 040000:
612 local_type = S_IFDIR; break;
613 case 060000:
614 local_type = S_IFBLK; break;
615 case 0120000:
616 local_type = S_IFLNK; break;
617 case 0100000:
618 default: /* don't know what is it */
619 local_type = S_IFREG; break;
622 *ret_skipped = p - s;
623 *ret_mode = local_type | perms;
624 return TRUE;
627 /* This function parses from idx in the columns[] array */
629 vfs_parse_filedate (int idx, time_t *t)
631 char *p;
632 struct tm tim;
633 int d[3];
634 int got_year = 0;
635 int l10n = 0; /* Locale's abbreviated month name */
636 time_t current_time;
637 struct tm *local_time;
639 /* Let's setup default time values */
640 current_time = time (NULL);
641 local_time = localtime (&current_time);
642 tim.tm_mday = local_time->tm_mday;
643 tim.tm_mon = local_time->tm_mon;
644 tim.tm_year = local_time->tm_year;
646 tim.tm_hour = 0;
647 tim.tm_min = 0;
648 tim.tm_sec = 0;
649 tim.tm_isdst = -1; /* Let mktime() try to guess correct dst offset */
651 p = columns[idx++];
653 /* We eat weekday name in case of extfs */
654 if (is_week (p, &tim))
655 p = columns[idx++];
657 /* Month name */
658 if (is_month (p, &tim)) {
659 /* And we expect, it followed by day number */
660 if (is_num (idx))
661 tim.tm_mday = (int) atol (columns[idx++]);
662 else
663 return 0; /* No day */
665 } else {
666 /* We expect:
667 3 fields max or we'll see oddities with certain file names.
668 So both year and time is not allowed.
669 Mon DD hh:mm[:ss]
670 Mon DD YYYY
671 But in case of extfs we allow these date formats:
672 MM-DD-YY hh:mm[:ss]
673 where Mon is Jan-Dec, DD, MM, YY two digit day, month, year,
674 YYYY four digit year, hh, mm, ss two digit hour, minute or second. */
676 /* Special case with MM-DD-YY or MM-DD-YYYY */
677 if (is_dos_date (p)) {
678 p[2] = p[5] = '-';
680 if (sscanf (p, "%2d-%2d-%d", &d[0], &d[1], &d[2]) == 3) {
681 /* Months are zero based */
682 if (d[0] > 0)
683 d[0]--;
685 if (d[2] > 1900) {
686 d[2] -= 1900;
687 } else {
688 /* Y2K madness */
689 if (d[2] < 70)
690 d[2] += 100;
693 tim.tm_mon = d[0];
694 tim.tm_mday = d[1];
695 tim.tm_year = d[2];
696 got_year = 1;
697 } else
698 return 0; /* sscanf failed */
699 } else {
700 /* Locale's abbreviated month name followed by day number */
701 if (is_localized_month (p) && (is_num (idx++)))
702 l10n = 1;
703 else
704 return 0; /* unsupported format */
708 /* Here we expect to find time or year */
709 if (is_num (idx) && (is_time (columns[idx], &tim)
710 || (got_year = is_year (columns[idx], &tim))))
711 idx++;
712 else
713 return 0; /* Neither time nor date */
716 * If the date is less than 6 months in the past, it is shown without year
717 * other dates in the past or future are shown with year but without time
718 * This does not check for years before 1900 ... I don't know, how
719 * to represent them at all
721 if (!got_year && local_time->tm_mon < 6
722 && local_time->tm_mon < tim.tm_mon
723 && tim.tm_mon - local_time->tm_mon >= 6)
725 tim.tm_year--;
727 if (l10n || (*t = mktime (&tim)) < 0)
728 *t = 0;
729 return idx;
733 vfs_parse_ls_lga (const char *p, struct stat *s, char **filename,
734 char **linkname)
736 int idx, idx2, num_cols;
737 int i;
738 char *p_copy = NULL;
739 char *t = NULL;
740 const char *line = p;
741 size_t skipped;
743 if (strncmp (p, "total", 5) == 0)
744 return 0;
746 if (!vfs_parse_filetype (p, &skipped, &s->st_mode))
747 goto error;
748 p += skipped;
750 if (*p == ' ') /* Notwell 4 */
751 p++;
752 if (*p == '[') {
753 if (strlen (p) <= 8 || p[8] != ']')
754 goto error;
755 /* Should parse here the Notwell permissions :) */
756 if (S_ISDIR (s->st_mode))
757 s->st_mode |=
758 (S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR | S_IXUSR | S_IXGRP
759 | S_IXOTH);
760 else
761 s->st_mode |= (S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR);
762 p += 9;
763 } else {
764 size_t lc_skipped;
765 mode_t perms;
767 if (!vfs_parse_fileperms (p, &lc_skipped, &perms))
768 goto error;
769 p += lc_skipped;
770 s->st_mode |= perms;
773 p_copy = g_strdup (p);
774 num_cols = vfs_split_text (p_copy);
776 s->st_nlink = atol (columns[0]);
777 if (s->st_nlink <= 0)
778 goto error;
780 if (!is_num (1))
781 s->st_uid = vfs_finduid (columns[1]);
782 else
783 s->st_uid = (uid_t) atol (columns[1]);
785 /* Mhm, the ls -lg did not produce a group field */
786 for (idx = 3; idx <= 5; idx++)
787 if (is_month (columns[idx], NULL) || is_week (columns[idx], NULL)
788 || is_dos_date (columns[idx])
789 || is_localized_month (columns[idx]))
790 break;
792 if (idx == 6
793 || (idx == 5 && !S_ISCHR (s->st_mode) && !S_ISBLK (s->st_mode)))
794 goto error;
796 /* We don't have gid */
797 if (idx == 3
798 || (idx == 4 && (S_ISCHR (s->st_mode) || S_ISBLK (s->st_mode))))
799 idx2 = 2;
800 else {
801 /* We have gid field */
802 if (is_num (2))
803 s->st_gid = (gid_t) atol (columns[2]);
804 else
805 s->st_gid = vfs_findgid (columns[2]);
806 idx2 = 3;
809 /* This is device */
810 if (S_ISCHR (s->st_mode) || S_ISBLK (s->st_mode)) {
811 int maj, min;
813 /* Corner case: there is no whitespace(s) between maj & min */
814 if (!is_num (idx2) && idx2 == 2) {
815 if (!is_num (++idx2) || sscanf (columns[idx2], " %d,%d", &min, &min) != 2)
816 goto error;
817 } else {
818 if (!is_num (idx2) || sscanf (columns[idx2], " %d,", &maj) != 1)
819 goto error;
821 if (!is_num (++idx2) || sscanf (columns[idx2], " %d", &min) != 1)
822 goto error;
824 #ifdef HAVE_STRUCT_STAT_ST_RDEV
825 s->st_rdev = makedev (maj, min);
826 #endif
827 s->st_size = 0;
829 } else {
830 /* Common file size */
831 if (!is_num (idx2))
832 goto error;
834 #ifdef HAVE_ATOLL
835 s->st_size = (off_t) atoll (columns[idx2]);
836 #else
837 s->st_size = (off_t) atof (columns[idx2]);
838 #endif
839 #ifdef HAVE_STRUCT_STAT_ST_RDEV
840 s->st_rdev = 0;
841 #endif
844 idx = vfs_parse_filedate (idx, &s->st_mtime);
845 if (!idx)
846 goto error;
847 /* Use resulting time value */
848 s->st_atime = s->st_ctime = s->st_mtime;
849 /* s->st_dev and s->st_ino must be initialized by vfs_s_new_inode () */
850 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
851 s->st_blksize = 512;
852 #endif
853 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
854 s->st_blocks = (s->st_size + 511) / 512;
855 #endif
857 for (i = idx + 1, idx2 = 0; i < num_cols; i++)
858 if (strcmp (columns[i], "->") == 0) {
859 idx2 = i;
860 break;
863 if (((S_ISLNK (s->st_mode) || (num_cols == idx + 3 && s->st_nlink > 1))) /* Maybe a hardlink? (in extfs) */
864 &&idx2) {
866 if (filename) {
867 *filename =
868 g_strndup (p + column_ptr[idx],
869 column_ptr[idx2] - column_ptr[idx] - 1);
871 if (linkname) {
872 t = g_strdup (p + column_ptr[idx2 + 1]);
873 *linkname = t;
875 } else {
876 /* Extract the filename from the string copy, not from the columns
877 * this way we have a chance of entering hidden directories like ". ."
879 if (filename) {
881 * filename = g_strdup (columns [idx++]);
884 t = g_strdup (p + column_ptr[idx]);
885 *filename = t;
887 if (linkname)
888 *linkname = NULL;
891 if (t) {
892 int p2 = strlen (t);
893 if ((--p2 > 0) && (t[p2] == '\r' || t[p2] == '\n'))
894 t[p2] = 0;
895 if ((--p2 > 0) && (t[p2] == '\r' || t[p2] == '\n'))
896 t[p2] = 0;
899 g_free (p_copy);
900 return 1;
902 error:
904 static int errorcount = 0;
906 if (++errorcount < 5) {
907 message (D_ERROR, _("Cannot parse:"), "%s",
908 (p_copy && *p_copy) ? p_copy : line);
909 } else if (errorcount == 5)
910 message (D_ERROR, MSG_ERROR,
911 _("More parsing errors will be ignored."));
914 g_free (p_copy);
915 return 0;
918 void
919 vfs_die (const char *m)
921 message (D_ERROR, _("Internal error:"), "%s", m);
922 exit (1);
925 char *
926 vfs_get_password (const char *msg)
928 return input_dialog (msg, _("Password:"), MC_HISTORY_VFS_PASSWORD, INPUT_PASSWORD);