Mercurial > hg > octave-kai > gnulib-hg
annotate lib/xgetcwd.c @ 5940:5e3f37f5f1d4
2005-06-25 Simon Josefsson <jas@extundo.com>
* modules/check-version: New file.
author | Simon Josefsson <simon@josefsson.org> |
---|---|
date | Tue, 28 Jun 2005 09:50:35 +0000 |
parents | a48fb0e98c8c |
children | 96c32553b4c6 |
rev | line source |
---|---|
212 | 1 /* xgetcwd.c -- return current directory with unlimited length |
5129
85cfcfd6d0be
(errno): Don't declare; we assume C89 or better now.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4675
diff
changeset
|
2 |
5491
b3d5c90efc81
Merge from coreutils for getcwd and HP-UX 11.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5458
diff
changeset
|
3 Copyright (C) 2001, 2003, 2004 Free Software Foundation, Inc. |
212 | 4 |
5 This program is free software; you can redistribute it and/or modify | |
6 it under the terms of the GNU General Public License as published by | |
7 the Free Software Foundation; either version 2, or (at your option) | |
8 any later version. | |
9 | |
10 This program is distributed in the hope that it will be useful, | |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 GNU General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU General Public License | |
650
b4ef1c1a0171
update FSF address in copyright
Jim Meyering <jim@meyering.net>
parents:
212
diff
changeset
|
16 along with this program; if not, write to the Free Software Foundation, |
5848
a48fb0e98c8c
*** empty log message ***
Paul Eggert <eggert@cs.ucla.edu>
parents:
5491
diff
changeset
|
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
212 | 18 |
5491
b3d5c90efc81
Merge from coreutils for getcwd and HP-UX 11.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5458
diff
changeset
|
19 /* Written by Jim Meyering. */ |
212 | 20 |
778 | 21 #if HAVE_CONFIG_H |
653 | 22 # include <config.h> |
212 | 23 #endif |
24 | |
4372 | 25 #include "xgetcwd.h" |
3466
45d73183ee54
Revert some of the previous change; intead,
Jim Meyering <jim@meyering.net>
parents:
3452
diff
changeset
|
26 |
5491
b3d5c90efc81
Merge from coreutils for getcwd and HP-UX 11.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5458
diff
changeset
|
27 #include <errno.h> |
b3d5c90efc81
Merge from coreutils for getcwd and HP-UX 11.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5458
diff
changeset
|
28 |
b3d5c90efc81
Merge from coreutils for getcwd and HP-UX 11.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5458
diff
changeset
|
29 #include "getcwd.h" |
b3d5c90efc81
Merge from coreutils for getcwd and HP-UX 11.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5458
diff
changeset
|
30 #include "xalloc.h" |
b3d5c90efc81
Merge from coreutils for getcwd and HP-UX 11.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5458
diff
changeset
|
31 |
b3d5c90efc81
Merge from coreutils for getcwd and HP-UX 11.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5458
diff
changeset
|
32 /* Return the current directory, newly allocated. |
4372 | 33 Upon an out-of-memory error, call xalloc_die. |
34 Upon any other type of error, return NULL. */ | |
212 | 35 |
36 char * | |
4372 | 37 xgetcwd (void) |
212 | 38 { |
3466
45d73183ee54
Revert some of the previous change; intead,
Jim Meyering <jim@meyering.net>
parents:
3452
diff
changeset
|
39 char *cwd = getcwd (NULL, 0); |
45d73183ee54
Revert some of the previous change; intead,
Jim Meyering <jim@meyering.net>
parents:
3452
diff
changeset
|
40 if (! cwd && errno == ENOMEM) |
45d73183ee54
Revert some of the previous change; intead,
Jim Meyering <jim@meyering.net>
parents:
3452
diff
changeset
|
41 xalloc_die (); |
45d73183ee54
Revert some of the previous change; intead,
Jim Meyering <jim@meyering.net>
parents:
3452
diff
changeset
|
42 return cwd; |
212 | 43 } |