1994-04-29 02:39:34 +08:00
|
|
|
/* xgetcwd.c -- return current directory with unlimited length
|
2004-08-03 06:47:00 +08:00
|
|
|
|
2004-11-26 03:25:07 +08:00
|
|
|
Copyright (C) 2001, 2003, 2004 Free Software Foundation, Inc.
|
1994-04-29 02:39:34 +08:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
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
|
1996-07-15 11:36:16 +08:00
|
|
|
along with this program; if not, write to the Free Software Foundation,
|
2005-05-14 15:58:06 +08:00
|
|
|
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
|
1994-04-29 02:39:34 +08:00
|
|
|
|
2004-11-26 03:25:07 +08:00
|
|
|
/* Written by Jim Meyering. */
|
1994-04-29 02:39:34 +08:00
|
|
|
|
2005-09-22 14:05:39 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
1996-07-15 11:56:06 +08:00
|
|
|
# include <config.h>
|
1994-04-29 02:39:34 +08:00
|
|
|
#endif
|
|
|
|
|
2004-11-26 03:25:07 +08:00
|
|
|
#include "xgetcwd.h"
|
1994-04-29 02:39:34 +08:00
|
|
|
|
2004-11-26 03:25:07 +08:00
|
|
|
#include <errno.h>
|
1994-04-29 02:39:34 +08:00
|
|
|
|
2004-11-26 03:25:07 +08:00
|
|
|
#include "getcwd.h"
|
2001-09-05 04:28:31 +08:00
|
|
|
#include "xalloc.h"
|
|
|
|
|
2004-11-26 03:25:07 +08:00
|
|
|
/* Return the current directory, newly allocated.
|
2003-03-05 02:07:59 +08:00
|
|
|
Upon an out-of-memory error, call xalloc_die.
|
|
|
|
Upon any other type of error, return NULL. */
|
1994-04-29 02:39:34 +08:00
|
|
|
|
|
|
|
char *
|
2003-01-11 06:45:14 +08:00
|
|
|
xgetcwd (void)
|
1994-04-29 02:39:34 +08:00
|
|
|
{
|
2001-09-05 04:28:31 +08:00
|
|
|
char *cwd = getcwd (NULL, 0);
|
|
|
|
if (! cwd && errno == ENOMEM)
|
|
|
|
xalloc_die ();
|
|
|
|
return cwd;
|
1994-04-29 02:39:34 +08:00
|
|
|
}
|