getcwd() is actually implemented like elsewhere, and not strictly after
POSIX demands: if you pass in a NULL pointer, a buffer will now be allocated for you. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11388 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
86e404324f
commit
4b72e95292
@ -1,12 +1,13 @@
|
||||
/*
|
||||
** Copyright 2002-2004, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
|
||||
** Distributed under the terms of the Haiku License.
|
||||
*/
|
||||
/*
|
||||
* Copyright 2002-2005, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <syscalls.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
@ -39,8 +40,24 @@ fchdir(int fd)
|
||||
char *
|
||||
getcwd(char *buffer, size_t size)
|
||||
{
|
||||
int status = _kern_getcwd(buffer, size);
|
||||
bool allocated = false;
|
||||
status_t status;
|
||||
|
||||
if (buffer == NULL) {
|
||||
buffer = malloc(size = PATH_MAX);
|
||||
if (buffer == NULL) {
|
||||
errno = B_NO_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
allocated = true;
|
||||
}
|
||||
|
||||
status = _kern_getcwd(buffer, size);
|
||||
if (status < B_OK) {
|
||||
if (allocated)
|
||||
free(buffer);
|
||||
|
||||
errno = status;
|
||||
return NULL;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user