Commit 44774504 447745040b16d1dab3e36b0886546f90324ae60b by Sergey Poznyakoff

(mail_cd): Check chdir return value

1 parent f19c3e15
Showing 1 changed file with 12 additions and 4 deletions
1 /* GNU Mailutils -- a suite of utilities for electronic mail 1 /* GNU Mailutils -- a suite of utilities for electronic mail
2 Copyright (C) 1999 Free Software Foundation, Inc. 2 Copyright (C) 1999, 2005 Free Software Foundation, Inc.
3 3
4 GNU Mailutils is free software; you can redistribute it and/or modify 4 GNU Mailutils is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by 5 it under the terms of the GNU General Public License as published by
...@@ -26,11 +26,19 @@ ...@@ -26,11 +26,19 @@
26 int 26 int
27 mail_cd (int argc, char **argv) 27 mail_cd (int argc, char **argv)
28 { 28 {
29 char *dir;
30
29 if (argc > 2) 31 if (argc > 2)
30 return 1; 32 return 1;
31 else if (argc == 2 && (chdir (argv[1]) != 0)) 33 else if (argc == 2)
32 return 1; 34 dir = argv[1];
33 else if (argc < 2 && chdir (getenv ("HOME")) != 0) 35 else
36 dir = getenv ("HOME");
37
38 if (chdir (dir))
39 {
40 mu_error (_("cannot change to '%s': %s"), dir, mu_strerror (errno));
34 return 1; 41 return 1;
42 }
35 return 0; 43 return 0;
36 } 44 }
......