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:
@@ -1,12 +1,13 @@
|
|||||||
/*
|
/*
|
||||||
** Copyright 2002-2004, Axel Dörfler, [email protected]. All rights reserved.
|
* Copyright 2002-2005, Axel Dörfler, [email protected]. All rights reserved.
|
||||||
** Distributed under the terms of the Haiku License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <syscalls.h>
|
#include <syscalls.h>
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
|
||||||
@@ -39,8 +40,24 @@ fchdir(int fd)
|
|||||||
char *
|
char *
|
||||||
getcwd(char *buffer, size_t size)
|
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 (status < B_OK) {
|
||||||
|
if (allocated)
|
||||||
|
free(buffer);
|
||||||
|
|
||||||
errno = status;
|
errno = status;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user