Ticket #1475: warningis fix
[midnight-commander.git] / vfs / utilvfs.c
blobaf05144cd3f463ea3b600f36adc40b760919b635
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"
37 #include "../src/tty.h" /* enable/disable interrupt key */
38 #include "../src/wtools.h" /* message() */
39 #include "../src/main.h" /* print_vfs_message */
40 #include "utilvfs.h"
41 #include "vfs.h"
42 #include "../src/unixcompat.h"
43 #include "../src/history.h"
45 /* Extract the hostname and username from the path */
46 /* path is in the form: [user@]hostname:port/remote-dir, e.g.:
48 * ftp://sunsite.unc.edu/pub/linux
49 * ftp://miguel@sphinx.nuclecu.unam.mx/c/nc
50 * ftp://tsx-11.mit.edu:8192/
51 * ftp://joe@foo.edu:11321/private
52 * ftp://joe:password@foo.se
54 * Returns g_malloc()ed host, user and pass they are present.
55 * If the user is empty, e.g. ftp://@roxanne/private, and URL_ALLOW_ANON
56 * is not set, then the current login name is supplied.
58 * Return value is a g_malloc()ed string with the pathname relative to the
59 * host.
62 #ifdef USE_NETCODE
63 char *
64 vfs_split_url (const char *path, char **host, char **user, int *port,
65 char **pass, int default_port, int flags)
67 struct passwd *passwd_info;
68 char *dir, *colon, *inner_colon, *at, *rest;
69 char *retval;
70 char * const pcopy = g_strdup (path);
71 const char *pend = pcopy + strlen (pcopy);
73 if (pass)
74 *pass = NULL;
75 *port = default_port;
76 *user = NULL;
77 retval = NULL;
79 dir = pcopy;
80 if (!(flags & URL_NOSLASH)) {
81 /* locate path component */
82 while (*dir != PATH_SEP && *dir)
83 dir++;
84 if (*dir) {
85 retval = g_strdup (dir);
86 *dir = 0;
87 } else
88 retval = g_strdup (PATH_SEP_STR);
91 /* search for any possible user */
92 at = strrchr (pcopy, '@');
94 /* We have a username */
95 if (at) {
96 *at = 0;
97 inner_colon = strchr (pcopy, ':');
98 if (inner_colon) {
99 *inner_colon = 0;
100 inner_colon++;
101 if (pass)
102 *pass = g_strdup (inner_colon);
104 if (*pcopy != 0)
105 *user = g_strdup (pcopy);
107 if (pend == at + 1)
108 rest = at;
109 else
110 rest = at + 1;
111 } else
112 rest = pcopy;
114 if (!*user && !(flags & URL_ALLOW_ANON)) {
115 passwd_info = getpwuid (geteuid ());
116 if (passwd_info && passwd_info->pw_name)
117 *user = g_strdup (passwd_info->pw_name);
118 else {
119 /* This is very unlikely to happen */
120 *user = g_strdup ("anonymous");
122 endpwent ();
125 /* Check if the host comes with a port spec, if so, chop it */
126 colon = strchr (rest, ':');
127 if (colon) {
128 *colon = 0;
129 if (sscanf (colon + 1, "%d", port) == 1) {
130 if (*port <= 0 || *port >= 65536)
131 *port = default_port;
132 } else {
133 while (*(++colon)) {
134 switch (*colon) {
135 case 'C':
136 *port = 1;
137 break;
138 case 'r':
139 *port = 2;
140 break;
145 if (host)
146 *host = g_strdup (rest);
148 g_free (pcopy);
149 return retval;
151 #endif /* USE_NETCODE */
154 * Look up a user or group name from a uid/gid, maintaining a cache.
155 * FIXME, for now it's a one-entry cache.
156 * FIXME2, the "-993" is to reduce the chance of a hit on the first lookup.
157 * This file should be modified for non-unix systems to do something
158 * reasonable.
161 #ifndef TUNMLEN
162 #define TUNMLEN 256
163 #endif
164 #ifndef TGNMLEN
165 #define TGNMLEN 256
166 #endif
168 #define myuid ( my_uid < 0? (my_uid = getuid()): my_uid )
169 #define mygid ( my_gid < 0? (my_gid = getgid()): my_gid )
172 vfs_finduid (const char *uname)
174 static int saveuid = -993;
175 static char saveuname[TUNMLEN];
176 static int my_uid = -993;
178 struct passwd *pw;
180 if (uname[0] != saveuname[0] /* Quick test w/o proc call */
181 ||0 != strncmp (uname, saveuname, TUNMLEN)) {
182 g_strlcpy (saveuname, uname, TUNMLEN);
183 pw = getpwnam (uname);
184 if (pw) {
185 saveuid = pw->pw_uid;
186 } else {
187 saveuid = myuid;
190 return saveuid;
194 vfs_findgid (const char *gname)
196 static int savegid = -993;
197 static char savegname[TGNMLEN];
198 static int my_gid = -993;
200 struct group *gr;
202 if (gname[0] != savegname[0] /* Quick test w/o proc call */
203 ||0 != strncmp (gname, savegname, TUNMLEN)) {
204 g_strlcpy (savegname, gname, TUNMLEN);
205 gr = getgrnam (gname);
206 if (gr) {
207 savegid = gr->gr_gid;
208 } else {
209 savegid = mygid;
212 return savegid;
216 * Create a temporary file with a name resembling the original.
217 * This is needed e.g. for local copies requested by extfs.
218 * Some extfs scripts may look at the extension.
219 * We also protect stupid scripts agains dangerous names.
222 vfs_mkstemps (char **pname, const char *prefix, const char *basename)
224 const char *p;
225 char *suffix, *q;
226 int shift;
227 int fd;
229 /* Strip directories */
230 p = strrchr (basename, PATH_SEP);
231 if (!p)
232 p = basename;
233 else
234 p++;
236 /* Protection against very long names */
237 shift = strlen (p) - (MC_MAXPATHLEN - 16);
238 if (shift > 0)
239 p += shift;
241 suffix = g_malloc (MC_MAXPATHLEN);
243 /* Protection against unusual characters */
244 q = suffix;
245 while (*p && (*p != '#')) {
246 if (strchr (".-_@", *p) || isalnum ((unsigned char) *p))
247 *q++ = *p;
248 p++;
250 *q = 0;
252 fd = mc_mkstemps (pname, prefix, suffix);
253 g_free (suffix);
254 return fd;
257 /* Parsing code is used by ftpfs, fish and extfs */
258 #define MAXCOLS 30
260 static char *columns[MAXCOLS]; /* Points to the string in column n */
261 static int column_ptr[MAXCOLS]; /* Index from 0 to the starting positions of the columns */
264 vfs_split_text (char *p)
266 char *original = p;
267 int numcols;
269 memset (columns, 0, sizeof (columns));
271 for (numcols = 0; *p && numcols < MAXCOLS; numcols++) {
272 while (*p == ' ' || *p == '\r' || *p == '\n') {
273 *p = 0;
274 p++;
276 columns[numcols] = p;
277 column_ptr[numcols] = p - original;
278 while (*p && *p != ' ' && *p != '\r' && *p != '\n')
279 p++;
281 return numcols;
284 static int
285 is_num (int idx)
287 char *column = columns[idx];
289 if (!column || column[0] < '0' || column[0] > '9')
290 return 0;
292 return 1;
295 /* Return 1 for MM-DD-YY and MM-DD-YYYY */
296 static int
297 is_dos_date (const char *str)
299 int len;
301 if (!str)
302 return 0;
304 len = strlen (str);
305 if (len != 8 && len != 10)
306 return 0;
308 if (str[2] != str[5])
309 return 0;
311 if (!strchr ("\\-/", (int) str[2]))
312 return 0;
314 return 1;
317 static int
318 is_week (const char *str, struct tm *tim)
320 static const char *week = "SunMonTueWedThuFriSat";
321 const char *pos;
323 if (!str)
324 return 0;
326 if ((pos = strstr (week, str)) != NULL) {
327 if (tim != NULL)
328 tim->tm_wday = (pos - week) / 3;
329 return 1;
331 return 0;
334 static int
335 is_month (const char *str, struct tm *tim)
337 static const char *month = "JanFebMarAprMayJunJulAugSepOctNovDec";
338 const char *pos;
340 if (!str)
341 return 0;
343 if ((pos = strstr (month, str)) != NULL) {
344 if (tim != NULL)
345 tim->tm_mon = (pos - month) / 3;
346 return 1;
348 return 0;
352 * Check for possible locale's abbreviated month name (Jan..Dec).
353 * Any 3 bytes long string without digit, control and punctuation characters.
354 * isalpha() is locale specific, so it cannot be used if current
355 * locale is "C" and ftp server use Cyrillic.
356 * NB: It is assumed there are no whitespaces in month.
358 static int
359 is_localized_month (const char *month)
361 int i = 0;
363 if (!month)
364 return 0;
366 while ((i < 3) && *month && !isdigit ((unsigned char) *month)
367 && !iscntrl ((unsigned char) *month)
368 && !ispunct ((unsigned char) *month)) {
369 i++;
370 month++;
372 return ((i == 3) && (*month == 0));
375 static int
376 is_time (const char *str, struct tm *tim)
378 const char *p, *p2;
380 if (!str)
381 return 0;
383 if ((p = strchr (str, ':')) && (p2 = strrchr (str, ':'))) {
384 if (p != p2) {
385 if (sscanf
386 (str, "%2d:%2d:%2d", &tim->tm_hour, &tim->tm_min,
387 &tim->tm_sec) != 3)
388 return 0;
389 } else {
390 if (sscanf (str, "%2d:%2d", &tim->tm_hour, &tim->tm_min) != 2)
391 return 0;
393 } else
394 return 0;
396 return 1;
399 static int
400 is_year (char *str, struct tm *tim)
402 long year;
404 if (!str)
405 return 0;
407 if (strchr (str, ':'))
408 return 0;
410 if (strlen (str) != 4)
411 return 0;
413 if (sscanf (str, "%ld", &year) != 1)
414 return 0;
416 if (year < 1900 || year > 3000)
417 return 0;
419 tim->tm_year = (int) (year - 1900);
421 return 1;
424 gboolean
425 vfs_parse_filetype (const char *s, size_t *ret_skipped, mode_t *ret_type)
427 mode_t type;
429 switch (*s) {
430 case 'd': type = S_IFDIR; break;
431 case 'b': type = S_IFBLK; break;
432 case 'c': type = S_IFCHR; break;
433 case 'l': type = S_IFLNK; break;
434 #ifdef S_IFSOCK
435 case 's': type = S_IFSOCK; break;
436 #else
437 case 's': type = S_IFIFO; break;
438 #endif
439 #ifdef S_IFDOOR /* Solaris door */
440 case 'D': type = S_IFDOOR; break;
441 #else
442 case 'D': type = S_IFIFO; break;
443 #endif
444 case 'p': type = S_IFIFO; break;
445 #ifdef S_IFNAM /* Special named files */
446 case 'n': type = S_IFNAM; break;
447 #else
448 case 'n': type = S_IFREG; break;
449 #endif
450 case 'm': /* Don't know what these are :-) */
451 case '-':
452 case '?': type = S_IFREG; break;
453 default: return FALSE;
456 *ret_type = type;
457 *ret_skipped = 1;
458 return TRUE;
461 gboolean
462 vfs_parse_fileperms (const char *s, size_t *ret_skipped, mode_t *ret_perms)
464 const char *p;
465 mode_t perms;
467 p = s;
468 perms = 0;
470 switch (*p++) {
471 case '-': break;
472 case 'r': perms |= S_IRUSR; break;
473 default: return FALSE;
475 switch (*p++) {
476 case '-': break;
477 case 'w': perms |= S_IWUSR; break;
478 default: return FALSE;
480 switch (*p++) {
481 case '-': break;
482 case 'S': perms |= S_ISUID; break;
483 case 's': perms |= S_IXUSR | S_ISUID; break;
484 case 'x': perms |= S_IXUSR; break;
485 default: return FALSE;
487 switch (*p++) {
488 case '-': break;
489 case 'r': perms |= S_IRGRP; break;
490 default: return FALSE;
492 switch (*p++) {
493 case '-': break;
494 case 'w': perms |= S_IWGRP; break;
495 default: return FALSE;
497 switch (*p++) {
498 case '-': break;
499 case 'S': perms |= S_ISGID; break;
500 case 'l': perms |= S_ISGID; break; /* found on Solaris */
501 case 's': perms |= S_IXGRP | S_ISGID; break;
502 case 'x': perms |= S_IXGRP; break;
503 default: return FALSE;
505 switch (*p++) {
506 case '-': break;
507 case 'r': perms |= S_IROTH; break;
508 default: return FALSE;
510 switch (*p++) {
511 case '-': break;
512 case 'w': perms |= S_IWOTH; break;
513 default: return FALSE;
515 switch (*p++) {
516 case '-': break;
517 case 'T': perms |= S_ISVTX; break;
518 case 't': perms |= S_IXOTH | S_ISVTX; break;
519 case 'x': perms |= S_IXOTH; break;
520 default: return FALSE;
522 if (*p == '+') { /* ACLs on Solaris, HP-UX and others */
523 p++;
526 *ret_skipped = p - s;
527 *ret_perms = perms;
528 return TRUE;
531 gboolean
532 vfs_parse_filemode (const char *s, size_t *ret_skipped,
533 mode_t *ret_mode)
535 const char *p;
536 mode_t type, perms;
537 size_t skipped;
539 p = s;
541 if (!vfs_parse_filetype (p, &skipped, &type))
542 return FALSE;
543 p += skipped;
545 if (!vfs_parse_fileperms (p, &skipped, &perms))
546 return FALSE;
547 p += skipped;
549 *ret_skipped = p - s;
550 *ret_mode = type | perms;
551 return TRUE;
554 gboolean
555 vfs_parse_raw_filemode (const char *s, size_t *ret_skipped,
556 mode_t *ret_mode)
558 const char *p;
559 mode_t remote_type = 0, local_type, perms = 0;
561 p = s;
563 /* isoctal */
564 while(*p >= '0' && *p <= '7')
566 perms *= 010;
567 perms += (*p - '0');
568 ++p;
571 if (*p++ != ' ')
572 return FALSE;
574 while(*p >= '0' && *p <= '7')
576 remote_type *= 010;
577 remote_type += (*p - '0');
578 ++p;
581 if (*p++ != ' ')
582 return FALSE;
584 /* generated with:
585 $ perl -e 'use Fcntl ":mode";
586 my @modes = (S_IFDIR, S_IFBLK, S_IFCHR, S_IFLNK, S_IFREG);
587 foreach $t (@modes) { printf ("%o\n", $t); };'
588 TODO: S_IFDOOR, S_IFIFO, S_IFSOCK (if supported by os)
589 (see vfs_parse_filetype)
592 switch (remote_type)
594 case 020000:
595 local_type = S_IFCHR; break;
596 case 040000:
597 local_type = S_IFDIR; break;
598 case 060000:
599 local_type = S_IFBLK; break;
600 case 0120000:
601 local_type = S_IFLNK; break;
602 case 0100000:
603 default: /* don't know what is it */
604 local_type = S_IFREG; break;
607 *ret_skipped = p - s;
608 *ret_mode = local_type | perms;
609 return TRUE;
612 /* This function parses from idx in the columns[] array */
614 vfs_parse_filedate (int idx, time_t *t)
616 char *p;
617 struct tm tim;
618 int d[3];
619 int got_year = 0;
620 int l10n = 0; /* Locale's abbreviated month name */
621 time_t current_time;
622 struct tm *local_time;
624 /* Let's setup default time values */
625 current_time = time (NULL);
626 local_time = localtime (&current_time);
627 tim.tm_mday = local_time->tm_mday;
628 tim.tm_mon = local_time->tm_mon;
629 tim.tm_year = local_time->tm_year;
631 tim.tm_hour = 0;
632 tim.tm_min = 0;
633 tim.tm_sec = 0;
634 tim.tm_isdst = -1; /* Let mktime() try to guess correct dst offset */
636 p = columns[idx++];
638 /* We eat weekday name in case of extfs */
639 if (is_week (p, &tim))
640 p = columns[idx++];
642 /* Month name */
643 if (is_month (p, &tim)) {
644 /* And we expect, it followed by day number */
645 if (is_num (idx))
646 tim.tm_mday = (int) atol (columns[idx++]);
647 else
648 return 0; /* No day */
650 } else {
651 /* We expect:
652 3 fields max or we'll see oddities with certain file names.
653 So both year and time is not allowed.
654 Mon DD hh:mm[:ss]
655 Mon DD YYYY
656 But in case of extfs we allow these date formats:
657 MM-DD-YY hh:mm[:ss]
658 where Mon is Jan-Dec, DD, MM, YY two digit day, month, year,
659 YYYY four digit year, hh, mm, ss two digit hour, minute or second. */
661 /* Special case with MM-DD-YY or MM-DD-YYYY */
662 if (is_dos_date (p)) {
663 p[2] = p[5] = '-';
665 if (sscanf (p, "%2d-%2d-%d", &d[0], &d[1], &d[2]) == 3) {
666 /* Months are zero based */
667 if (d[0] > 0)
668 d[0]--;
670 if (d[2] > 1900) {
671 d[2] -= 1900;
672 } else {
673 /* Y2K madness */
674 if (d[2] < 70)
675 d[2] += 100;
678 tim.tm_mon = d[0];
679 tim.tm_mday = d[1];
680 tim.tm_year = d[2];
681 got_year = 1;
682 } else
683 return 0; /* sscanf failed */
684 } else {
685 /* Locale's abbreviated month name followed by day number */
686 if (is_localized_month (p) && (is_num (idx++)))
687 l10n = 1;
688 else
689 return 0; /* unsupported format */
693 /* Here we expect to find time or year */
694 if (is_num (idx) && (is_time (columns[idx], &tim)
695 || (got_year = is_year (columns[idx], &tim))))
696 idx++;
697 else
698 return 0; /* Neither time nor date */
701 * If the date is less than 6 months in the past, it is shown without year
702 * other dates in the past or future are shown with year but without time
703 * This does not check for years before 1900 ... I don't know, how
704 * to represent them at all
706 if (!got_year && local_time->tm_mon < 6
707 && local_time->tm_mon < tim.tm_mon
708 && tim.tm_mon - local_time->tm_mon >= 6)
710 tim.tm_year--;
712 if (l10n || (*t = mktime (&tim)) < 0)
713 *t = 0;
714 return idx;
718 vfs_parse_ls_lga (const char *p, struct stat *s, char **filename,
719 char **linkname)
721 int idx, idx2, num_cols;
722 int i;
723 char *p_copy = NULL;
724 char *t = NULL;
725 const char *line = p;
726 size_t skipped;
728 if (strncmp (p, "total", 5) == 0)
729 return 0;
731 if (!vfs_parse_filetype (p, &skipped, &s->st_mode))
732 goto error;
733 p += skipped;
735 if (*p == ' ') /* Notwell 4 */
736 p++;
737 if (*p == '[') {
738 if (strlen (p) <= 8 || p[8] != ']')
739 goto error;
740 /* Should parse here the Notwell permissions :) */
741 if (S_ISDIR (s->st_mode))
742 s->st_mode |=
743 (S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR | S_IXUSR | S_IXGRP
744 | S_IXOTH);
745 else
746 s->st_mode |= (S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR);
747 p += 9;
748 } else {
749 size_t skipped;
750 mode_t perms;
752 if (!vfs_parse_fileperms (p, &skipped, &perms))
753 goto error;
754 p += skipped;
755 s->st_mode |= perms;
758 p_copy = g_strdup (p);
759 num_cols = vfs_split_text (p_copy);
761 s->st_nlink = atol (columns[0]);
762 if (s->st_nlink <= 0)
763 goto error;
765 if (!is_num (1))
766 s->st_uid = vfs_finduid (columns[1]);
767 else
768 s->st_uid = (uid_t) atol (columns[1]);
770 /* Mhm, the ls -lg did not produce a group field */
771 for (idx = 3; idx <= 5; idx++)
772 if (is_month (columns[idx], NULL) || is_week (columns[idx], NULL)
773 || is_dos_date (columns[idx])
774 || is_localized_month (columns[idx]))
775 break;
777 if (idx == 6
778 || (idx == 5 && !S_ISCHR (s->st_mode) && !S_ISBLK (s->st_mode)))
779 goto error;
781 /* We don't have gid */
782 if (idx == 3
783 || (idx == 4 && (S_ISCHR (s->st_mode) || S_ISBLK (s->st_mode))))
784 idx2 = 2;
785 else {
786 /* We have gid field */
787 if (is_num (2))
788 s->st_gid = (gid_t) atol (columns[2]);
789 else
790 s->st_gid = vfs_findgid (columns[2]);
791 idx2 = 3;
794 /* This is device */
795 if (S_ISCHR (s->st_mode) || S_ISBLK (s->st_mode)) {
796 int maj, min;
798 /* Corner case: there is no whitespace(s) between maj & min */
799 if (!is_num (idx2) && idx2 == 2) {
800 if (!is_num (++idx2) || sscanf (columns[idx2], " %d,%d", &min, &min) != 2)
801 goto error;
802 } else {
803 if (!is_num (idx2) || sscanf (columns[idx2], " %d,", &maj) != 1)
804 goto error;
806 if (!is_num (++idx2) || sscanf (columns[idx2], " %d", &min) != 1)
807 goto error;
809 #ifdef HAVE_STRUCT_STAT_ST_RDEV
810 s->st_rdev = makedev (maj, min);
811 #endif
812 s->st_size = 0;
814 } else {
815 /* Common file size */
816 if (!is_num (idx2))
817 goto error;
819 #ifdef HAVE_ATOLL
820 s->st_size = (off_t) atoll (columns[idx2]);
821 #else
822 s->st_size = (off_t) atof (columns[idx2]);
823 #endif
824 #ifdef HAVE_STRUCT_STAT_ST_RDEV
825 s->st_rdev = 0;
826 #endif
829 idx = vfs_parse_filedate (idx, &s->st_mtime);
830 if (!idx)
831 goto error;
832 /* Use resulting time value */
833 s->st_atime = s->st_ctime = s->st_mtime;
834 /* s->st_dev and s->st_ino must be initialized by vfs_s_new_inode () */
835 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
836 s->st_blksize = 512;
837 #endif
838 #ifdef HAVE_STRUCT_STAT_ST_BLOCKS
839 s->st_blocks = (s->st_size + 511) / 512;
840 #endif
842 for (i = idx + 1, idx2 = 0; i < num_cols; i++)
843 if (strcmp (columns[i], "->") == 0) {
844 idx2 = i;
845 break;
848 if (((S_ISLNK (s->st_mode) || (num_cols == idx + 3 && s->st_nlink > 1))) /* Maybe a hardlink? (in extfs) */
849 &&idx2) {
851 if (filename) {
852 *filename =
853 g_strndup (p + column_ptr[idx],
854 column_ptr[idx2] - column_ptr[idx] - 1);
856 if (linkname) {
857 t = g_strdup (p + column_ptr[idx2 + 1]);
858 *linkname = t;
860 } else {
861 /* Extract the filename from the string copy, not from the columns
862 * this way we have a chance of entering hidden directories like ". ."
864 if (filename) {
866 * filename = g_strdup (columns [idx++]);
869 t = g_strdup (p + column_ptr[idx]);
870 *filename = t;
872 if (linkname)
873 *linkname = NULL;
876 if (t) {
877 int p = strlen (t);
878 if ((--p > 0) && (t[p] == '\r' || t[p] == '\n'))
879 t[p] = 0;
880 if ((--p > 0) && (t[p] == '\r' || t[p] == '\n'))
881 t[p] = 0;
884 g_free (p_copy);
885 return 1;
887 error:
889 static int errorcount = 0;
891 if (++errorcount < 5) {
892 message (D_ERROR, _("Cannot parse:"), "%s",
893 (p_copy && *p_copy) ? p_copy : line);
894 } else if (errorcount == 5)
895 message (D_ERROR, MSG_ERROR,
896 _("More parsing errors will be ignored."));
899 g_free (p_copy);
900 return 0;
903 void
904 vfs_die (const char *m)
906 message (D_ERROR, _("Internal error:"), "%s", m);
907 exit (1);
910 char *
911 vfs_get_password (const char *msg)
913 return input_dialog (msg, _("Password:"), MC_HISTORY_VFS_PASSWORD, INPUT_PASSWORD);