VirtualBox

Ignore:
Timestamp:
Apr 17, 2017 3:08:21 PM (8 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
114618
Message:

RTFileModeToFlagsEx: Implemented missing sharing mode (sigh) and added humanly understandable alternatives to the disposition.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/misc/RTFileModeToFlags.cpp

    r62559 r66591  
    268268
    269269    /* Create a new file, always, overwrite an existing file. */
    270     if (!RTStrCmp(pszCur, "ca"))
     270    if (   !RTStrCmp(pszCur, "ca")
     271        || !RTStrCmp(pszCur, "create-replace"))
    271272        fMode |= RTFILE_O_CREATE_REPLACE;
    272273    /* Create a new file if it does not exist, fail if exist. */
    273     else if (!RTStrCmp(pszCur, "ce"))
     274    else if (   !RTStrCmp(pszCur, "ce")
     275             || !RTStrCmp(pszCur, "create"))
    274276        fMode |= RTFILE_O_CREATE;
    275277    /* Open existing file, create file if does not exist. */
    276     else if (!RTStrCmp(pszCur, "oc"))
     278    else if (   !RTStrCmp(pszCur, "oc")
     279             || !RTStrCmp(pszCur, "open-create"))
    277280        fMode |= RTFILE_O_OPEN_CREATE;
    278281    /* Open existing file and place the file pointer at
    279282     * the end of the file, if opened with write access.
    280283     * Create the file if does not exist. */
    281     else if (!RTStrCmp(pszCur, "oa"))
     284    else if (   !RTStrCmp(pszCur, "oa")
     285             || !RTStrCmp(pszCur, "open-append"))
    282286        fMode |= RTFILE_O_OPEN_CREATE | RTFILE_O_APPEND;
    283287    /* Open existing, fail if does not exist. */
    284     else if (!RTStrCmp(pszCur, "oe"))
     288    else if (   !RTStrCmp(pszCur, "oe")
     289             || !RTStrCmp(pszCur, "open"))
    285290        fMode |= RTFILE_O_OPEN;
    286291    /* Open and truncate existing, fail of not exist. */
    287     else if (!RTStrCmp(pszCur, "ot"))
     292    else if (   !RTStrCmp(pszCur, "ot")
     293             || !RTStrCmp(pszCur, "open-truncate"))
    288294        fMode |= RTFILE_O_OPEN | RTFILE_O_TRUNCATE;
    289295    else
     
    294300        return VERR_INVALID_PARAMETER;
    295301
    296     /** @todo Handle sharing mode. */
    297     fMode |= RTFILE_O_DENY_NONE;
     302    /*
     303     * Sharing mode.
     304     */
     305    if (!pszSharing || !*pszSharing)
     306        fMode |= RTFILE_O_DENY_NONE;
     307    else
     308    {
     309        do
     310        {
     311            if (pszSharing[0] == 'n')
     312            {
     313                if (pszSharing[1] == 'r') /* nr (no other readers) */
     314                {
     315                    if (pszSharing[2] == 'w') /* nrw (no other readers or writers) */
     316                    {
     317                        fMode |= RTFILE_O_DENY_READWRITE;
     318                        pszSharing += 3;
     319                    }
     320                    else
     321                    {
     322                        fMode |= RTFILE_O_DENY_READ;
     323                        pszSharing += 2;
     324                    }
     325                }
     326                else if (pszSharing[1] == 'w') /* nw (no other writers) */
     327                {
     328                    fMode |= RTFILE_O_DENY_WRITE;
     329                    pszSharing += 2;
     330                }
     331                else
     332                    return VERR_INVALID_PARAMETER;
     333            }
     334            else if (pszSharing[0] == 'd') /* d (don't deny delete) */
     335            {
     336                fMode |= RTFILE_O_DENY_WRITE;
     337                pszSharing++;
     338            }
     339            else
     340                return VERR_INVALID_PARAMETER;
     341        } while (*pszSharing != '\0');
     342    }
    298343
    299344    /* Return. */
Note: See TracChangeset for help on using the changeset viewer.

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