Changeset 21542 for trunk/src


Ignore:
Timestamp:
Jan 6, 2011, 12:34:08 PM (15 years ago)
Author:
dmik
Message:

minivcrt: Fixed _fullpath() which could implicitly change the current drive (LIBC bug).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/msvcrt/dir.c

    r21439 r21542  
    6262#include <errno.h>
    6363#include <stdlib.h>
     64#include <limits.h>
    6465
    6566#ifdef __EMX__
     
    778779#ifdef __EMX__
    779780
    780 // The EMX version of _fullpath() returns int instead of char*,
    781 // provide a wrapper
     781// The EMX version of _fullpath() returns int instead of char* and implicitly
     782// changes the current drive. It also doesn't expect absPath to be NULL and
     783// allocate a buffer in this case. Provide a wrapper to fix these issues.
    782784char *MSVCRT__fullpath(char * absPath, const char* relPath, unsigned int size)
    783785{
    784     return _fullpath(absPath, relPath, size) == 0 ? absPath : NULL;
     786    char *buf = NULL;
     787    if (absPath == NULL)
     788    {
     789        size = PATH_MAX;
     790        absPath = buf = (char *)MSVCRT_malloc(size);
     791        if (buf == NULL)
     792        {
     793            *MSVCRT__errno() = ENOMEM;
     794            return NULL;
     795        }
     796    }
     797
     798    int d = _getdrive();
     799    char *result = _fullpath(absPath, relPath, size) == 0 ? absPath : NULL;
     800    _chdrive(d);
     801
     802    if (result == NULL && buf != NULL)
     803      MSVCRT_free(buf);
     804
     805    return result;
    785806}
    786807
Note: See TracChangeset for help on using the changeset viewer.