Ignore:
Timestamp:
Nov 26, 2000, 4:10:06 PM (25 years ago)
Author:
bird
Message:

OSLibDosCreateFile: Fix for OPEN_ACTION_REPLACE_IF_EXISTS being

incompatible with readonly access.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/oslibdos.cpp

    r4698 r4703  
    1 /* $Id: oslibdos.cpp,v 1.51 2000-11-25 16:56:57 sandervl Exp $ */
     1/* $Id: oslibdos.cpp,v 1.52 2000-11-26 15:10:06 bird Exp $ */
    22/*
    33 * Wrappers for OS/2 Dos* API
     
    325325//******************************************************************************
    326326//NOTE: If name == NULL, allocated gettable unnamed shared memory
    327 //OS/2 returns error 123 (invalid name) if the shared memory name includes 
     327//OS/2 returns error 123 (invalid name) if the shared memory name includes
    328328//colons. We need to replace them with underscores.
    329329//******************************************************************************
     
    759759   {
    760760   case CREATE_NEW_W:
    761   openFlag |= OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_FAIL_IF_EXISTS;
     761        openFlag |= OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_FAIL_IF_EXISTS;
    762762        break;
    763763   case CREATE_ALWAYS_W:
    764         openFlag |= OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_REPLACE_IF_EXISTS;
     764       /* kso 2000-11-26: Not sure if OPEN_ACTION_REPLACE_IF_EXISTS is correct here! It is correct according to
     765        *   MSDN, but not according to "The Win32 API SuperBible". Anyway I haven't got time to check it out in
     766        *   NT now.
     767        *   The problem is that OPEN_ACTION_REPLACE_IF_EXISTS requires write access. It failes with
     768        *   rc = ERROR_ACCESS_DENIED (5). Quick fix, use OPEN_IF_EXIST if readonly access.
     769        */
     770       if (fuAccess & GENERIC_WRITE_W)
     771           openFlag |= OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_REPLACE_IF_EXISTS;
     772       else
     773           openFlag |= OPEN_ACTION_CREATE_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS;
    765774        break;
    766775   case OPEN_EXISTING_W:
     
    823832   }
    824833   int retry = 0;
    825    while(retry < 2)
     834   while (retry < 3)
    826835   {
    827836        dprintf(("DosOpen %s openFlag=%x openMode=%x", lpszFile, openFlag, openMode));
     
    834843                      openMode,
    835844                      NULL);
    836     if(rc == ERROR_TOO_MANY_OPEN_FILES)
     845    if (rc == ERROR_TOO_MANY_OPEN_FILES)
    837846    {
    838847        ULONG CurMaxFH;
     
    847856        dprintf(("DosOpen failed -> increased nr open files to %d", CurMaxFH));
    848857    }
    849     else  break;
     858    #if 0
     859    else if (rc == ERROR_ACCESS_DENIED && (openFlag & OPEN_ACTION_REPLACE_IF_EXISTS))
     860    {   /* kso: I have great problems with the REPLACE not working
     861         *      So, I guess this emulation may help...
     862         *      This problem exist on WS4eB SMP FP1 and Warp4 FP14/Kernel 14059 at least.
     863         */
     864        rc = DosOpen((PSZ)lpszFile,
     865                      &hFile,
     866                      &actionTaken,
     867                      fileSize,
     868                      fileAttr,
     869                      (openFlag & ~OPEN_ACTION_REPLACE_IF_EXISTS) | OPEN_ACTION_OPEN_IF_EXISTS,
     870                      openMode,
     871                      NULL);
     872        if (rc == NO_ERROR)
     873        {
     874            rc = DosSetFileSize(hFile, 0);
     875            if (!rc && fileSize > 0)
     876                rc = DosSetFileSize(hFile, fileSize);
     877            if (rc)
     878            {
     879                DosClose(hFile);
     880                hFile = NULLHANDLE;
     881
     882                if (rc != ERROR_TOO_MANY_OPEN_FILES)
     883                    break;
     884            }
     885            else break;
     886        }
     887    }
     888    #endif
     889    else break;
    850890    retry++;
    851891   }
     
    21022142        len = strlen(lpszCurDriveAndDir) + 3;
    21032143
    2104         // Dir returned by DosQueryCurDir doesn't include drive, so add it 
     2144        // Dir returned by DosQueryCurDir doesn't include drive, so add it
    21052145        DosQueryCurrentDisk(&currentdisk, &drivemap);
    21062146
Note: See TracChangeset for help on using the changeset viewer.