Mercurial > hg > octave-kai > gnulib-hg
annotate lib/xgetcwd.c @ 10531:e83a90adf243
Override fopen more carefully.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sun, 28 Sep 2008 16:12:20 +0200 |
parents | bbbbbf4cd1c5 |
children | b5e42ef33b49 |
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 |
8199
51d32a83a7df
Move more declarations into <unistd.h>.
Bruno Haible <bruno@clisp.org>
parents:
7302
diff
changeset
|
3 Copyright (C) 2001, 2003, 2004, 2006, 2007 Free Software Foundation, Inc. |
212 | 4 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8199
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify |
212 | 6 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8199
diff
changeset
|
7 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8199
diff
changeset
|
8 (at your option) any later version. |
212 | 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 | |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8199
diff
changeset
|
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
212 | 17 |
5491
b3d5c90efc81
Merge from coreutils for getcwd and HP-UX 11.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5458
diff
changeset
|
18 /* Written by Jim Meyering. */ |
212 | 19 |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
20 #include <config.h> |
212 | 21 |
4372 | 22 #include "xgetcwd.h" |
3466
45d73183ee54
Revert some of the previous change; intead,
Jim Meyering <jim@meyering.net>
parents:
3452
diff
changeset
|
23 |
5491
b3d5c90efc81
Merge from coreutils for getcwd and HP-UX 11.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5458
diff
changeset
|
24 #include <errno.h> |
8199
51d32a83a7df
Move more declarations into <unistd.h>.
Bruno Haible <bruno@clisp.org>
parents:
7302
diff
changeset
|
25 #include <unistd.h> |
5491
b3d5c90efc81
Merge from coreutils for getcwd and HP-UX 11.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5458
diff
changeset
|
26 |
b3d5c90efc81
Merge from coreutils for getcwd and HP-UX 11.
Paul Eggert <eggert@cs.ucla.edu>
parents:
5458
diff
changeset
|
27 #include "xalloc.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 /* Return the current directory, newly allocated. |
4372 | 30 Upon an out-of-memory error, call xalloc_die. |
31 Upon any other type of error, return NULL. */ | |
212 | 32 |
33 char * | |
4372 | 34 xgetcwd (void) |
212 | 35 { |
3466
45d73183ee54
Revert some of the previous change; intead,
Jim Meyering <jim@meyering.net>
parents:
3452
diff
changeset
|
36 char *cwd = getcwd (NULL, 0); |
45d73183ee54
Revert some of the previous change; intead,
Jim Meyering <jim@meyering.net>
parents:
3452
diff
changeset
|
37 if (! cwd && errno == ENOMEM) |
45d73183ee54
Revert some of the previous change; intead,
Jim Meyering <jim@meyering.net>
parents:
3452
diff
changeset
|
38 xalloc_die (); |
45d73183ee54
Revert some of the previous change; intead,
Jim Meyering <jim@meyering.net>
parents:
3452
diff
changeset
|
39 return cwd; |
212 | 40 } |