VirtualBox

Changeset 74358 in vbox for trunk/src/VBox/Runtime


Ignore:
Timestamp:
Sep 19, 2018 8:01:43 AM (6 years ago)
Author:
vboxsync
Message:

IPRT/win/fileio-win.cpp: Added support for longer file names (> 260 characters) for RTFileOpen().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/r3/win/fileio-win.cpp

    r72845 r74358  
    55
    66/*
    7  * Copyright (C) 2006-2017 Oracle Corporation
     7 * Copyright (C) 2006-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    4747#include "internal/fs.h"
    4848#include "internal/path.h"
     49#include "internal-r3-win.h" /* For g_enmWinVer + kRTWinOSType_XXX */
    4950
    5051
     
    288289    /*
    289290     * Open/Create the file.
    290      */
    291     PRTUTF16 pwszFilename;
    292     rc = RTStrToUtf16(pszFilename, &pwszFilename);
     291     *
     292     * When opening files with paths longer than 260 chars, CreateFileW() will fail, unless
     293     * you explicitly specify a prefix (see [1], RTPATH_WIN_LONG_PATH_PREFIX).
     294     *
     295     * Note: Relative paths are not supported, so check for this.
     296     *
     297     * [1] https://docs.microsoft.com/en-gb/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation
     298     */
     299    PRTUTF16 pwszFilename = NULL;
     300    if (g_enmWinVer >= kRTWinOSType_XP) /* Not sure since when the prefix is available, so play safe by default. */
     301    {
     302#define RTPATH_WIN_LONG_PATH_PREFIX "\\\\?\\"
     303
     304        if (   strlen(pszFilename) > 260
     305            && !RTPathStartsWith(pszFilename, RTPATH_WIN_LONG_PATH_PREFIX)
     306            && RTPathStartsWithRoot(pszFilename))
     307        {
     308            char *pszFilenameWithPrefix = RTStrAPrintf2("%s%s", RTPATH_WIN_LONG_PATH_PREFIX, pszFilename);
     309            if (pszFilenameWithPrefix)
     310            {
     311                rc = RTStrToUtf16(pszFilenameWithPrefix, &pwszFilename);
     312                RTStrFree(pszFilenameWithPrefix);
     313            }
     314            else
     315                rc = VERR_NO_MEMORY;
     316        }
     317#undef RTPATH_WIN_LONG_PATH_PREFIX
     318    }
     319
     320    if (   RT_SUCCESS(rc)
     321        && !pwszFilename)
     322    {
     323        rc = RTStrToUtf16(pszFilename, &pwszFilename);
     324    }
     325
    293326    if (RT_FAILURE(rc))
    294327        return rc;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette