hppa: fix loading of global pointer in _start [BZ #20277]
[glibc.git] / sysdeps / nacl / getcwd.c
blob85a7eb22445b6c94d08a09c9535e274b9e1a509b
1 /* Get current working directory. NaCl version.
2 Copyright (C) 2015-2016 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library 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 GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <unistd.h>
20 #include <limits.h>
21 #include <stdlib.h>
22 #include <nacl-interfaces.h>
24 /* Get the pathname of the current working directory,
25 and put it in SIZE bytes of BUF. Returns NULL if the
26 directory couldn't be determined or SIZE was too small.
27 If successful, returns BUF. In GNU, if BUF is NULL,
28 an array is allocated with `malloc'; the array is SIZE
29 bytes long, unless SIZE <= 0, in which case it is as
30 big as necessary. */
31 char *
32 __getcwd (char *buf, size_t size)
34 char *use_buf = buf;
36 if (buf == NULL)
38 if (size == 0)
39 size = PATH_MAX;
40 use_buf = malloc (size);
41 if (__glibc_unlikely (use_buf == NULL))
42 return NULL;
45 int error = __nacl_irt_dev_filename.getcwd (use_buf, size);
46 if (__glibc_unlikely (error))
48 if (use_buf != buf)
49 free (use_buf);
50 errno = error;
51 return NULL;
54 return use_buf;
56 weak_alias (__getcwd, getcwd)