Get_current_directory() allocate buffer if needed
This commit is contained in:
parent
f90a2331dd
commit
a69ad46902
15
src/io.c
15
src/io.c
@ -886,7 +886,18 @@ char * Get_current_directory(char * buf, word * buf_unicode, size_t size)
|
|||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
#elif defined(WIN32)
|
#elif defined(WIN32)
|
||||||
/// @TODO allocate buf if needed
|
if (buf == NULL)
|
||||||
|
{
|
||||||
|
size = (size_t)GetCurrentDirectoryA(0, buf);
|
||||||
|
if (size == 0)
|
||||||
|
return NULL;
|
||||||
|
buf = malloc(size);
|
||||||
|
if (buf == NULL)
|
||||||
|
{
|
||||||
|
GFX2_Log(GFX2_ERROR, "Failed to allocate %lu bytes.\n", (unsigned long)size);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (GetCurrentDirectoryA(size, buf) == 0)
|
if (GetCurrentDirectoryA(size, buf) == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (buf_unicode != NULL)
|
if (buf_unicode != NULL)
|
||||||
@ -903,6 +914,8 @@ char * Get_current_directory(char * buf, word * buf_unicode, size_t size)
|
|||||||
return buf;
|
return buf;
|
||||||
#else
|
#else
|
||||||
char * ret = getcwd(buf, size);
|
char * ret = getcwd(buf, size);
|
||||||
|
if (ret == NULL)
|
||||||
|
GFX2_Log(GFX2_ERROR, "getcwd(%p, %lu) failed !\n", buf, (unsigned long)size);
|
||||||
#ifdef ENABLE_FILENAMES_ICONV
|
#ifdef ENABLE_FILENAMES_ICONV
|
||||||
if (ret != NULL && buf_unicode != NULL)
|
if (ret != NULL && buf_unicode != NULL)
|
||||||
{
|
{
|
||||||
|
|||||||
4
src/io.h
4
src/io.h
@ -183,6 +183,10 @@ void Release_lock_file(const char *file_directory);
|
|||||||
|
|
||||||
///
|
///
|
||||||
/// Return the current directory, equivalent to getcwd()
|
/// Return the current directory, equivalent to getcwd()
|
||||||
|
/// @param buf destination buffer. can be NULL
|
||||||
|
/// @param buf_unicode destination buffer for the unicode version of the path
|
||||||
|
/// @param size destination buffer size, ignored if buf is NULL
|
||||||
|
/// @return NULL for error, buf or a malloc'ed buffer
|
||||||
char * Get_current_directory(char * buf, word * buf_unicode, size_t size);
|
char * Get_current_directory(char * buf, word * buf_unicode, size_t size);
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user