Blame view

mail/cd.c 1.09 KB
1
/* GNU Mailutils -- a suite of utilities for electronic mail
2
   Copyright (C) 1999, 2005, 2007, 2010 Free Software Foundation, Inc.
3

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
6
   the Free Software Foundation; either version 3, or (at your option)
7 8
   any later version.

9
   GNU Mailutils is distributed in the hope that it will be useful,
10 11 12 13 14
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
15
   along with GNU Mailutils.  If not, see <http://www.gnu.org/licenses/>. */
16 17 18 19 20 21 22 23 24 25 26

#include "mail.h"

/*
 * cd [directory]
 * ch[dir] [directory]
 */

int
mail_cd (int argc, char **argv)
{
27 28
  char *dir;
  
29 30
  if (argc > 2)
    return 1;
31 32 33 34 35 36 37
  else if (argc == 2)
    dir = argv[1];
  else 
    dir = getenv ("HOME");

  if (chdir (dir))
    {
38
      mu_diag_funcall (MU_DIAG_ERROR, "chdir", dir, errno);
39 40
      return 1;
    }
41 42
  return 0;
}