Ignore:
Timestamp:
Nov 6, 2016, 1:07:37 AM (9 years ago)
Author:
bird
Message:

fts-nt.c: Wide char support, part 4.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/nt/ntdir.c

    r3004 r3005  
    115115BirdDir_T *birdDirOpenFromHandle(void *pvHandle, const void *pvReserved, unsigned fFlags)
    116116{
    117     if (!pvReserved)
     117    if (!pvReserved && !(fFlags & BIRDDIR_F_STATIC_ALLOC))
    118118    {
    119119        /*
     
    138138    }
    139139    else
     140    {
     141        assert(!(fFlags & BIRDDIR_F_STATIC_ALLOC));
    140142        assert(pvReserved == NULL);
    141     birdSetErrnoToNoMem();
     143    }
     144    birdSetErrnoToInvalidArg();
     145    return NULL;
     146}
     147
     148
     149/**
     150 * Special API that takes a preallocated BirdDir_T and can be called again
     151 * without involving birdDirClose.
     152 *
     153 *
     154 */
     155BirdDir_T *birdDirOpenFromHandleWithReuse(BirdDir_T *pDir, void *pvHandle, const void *pvReserved, unsigned fFlags)
     156{
     157    if (!pvReserved)
     158    {
     159        /*
     160         * Allocate and initialize the directory enum handle.
     161         */
     162        if (pDir)
     163        {
     164            if (pDir->uMagic == BIRD_DIR_MAGIC)
     165            {
     166                if (   (pDir->fFlags & BIRDDIR_F_CLOSE_HANDLE)
     167                    && pDir->pvHandle != INVALID_HANDLE_VALUE)
     168                    birdCloseFile((HANDLE)pDir->pvHandle);
     169            }
     170            else
     171            {
     172                pDir->cbBuf     = 0;
     173                pDir->pabBuf    = NULL;
     174                pDir->uMagic    = BIRD_DIR_MAGIC;
     175            }
     176            pDir->pvHandle      = pvHandle;
     177            pDir->fFlags        = fFlags;
     178            pDir->uDev          = 0;
     179            pDir->offPos        = 0;
     180            pDir->fHaveData     = 0;
     181            pDir->fFirst        = 1;
     182            pDir->iInfoClass    = fFlags & BIRDDIR_F_EXTRA_INFO ? MyFileIdFullDirectoryInformation : MyFileNamesInformation;
     183            pDir->offBuf        = 0;
     184            return pDir;
     185        }
     186    }
     187    else
     188        assert(pvReserved == NULL);
     189    birdSetErrnoToInvalidArg();
    142190    return NULL;
    143191}
     
    174222            pDir->uDev = 0;
    175223
    176         /*
    177          * Allocate a buffer.
    178          */
    179         pDir->cbBuf = 0x20000;
    180         pDir->pabBuf = birdMemAlloc(pDir->cbBuf);
    181224        if (!pDir->pabBuf)
    182             return birdSetErrnoToNoMem();
     225        {
     226            /*
     227             * Allocate a buffer.
     228             *
     229             * Better not exceed 64KB or CIFS may throw a fit.  Also, on win10/64
     230             * here there is a noticable speedup when going one byte below 64KB.
     231             */
     232            pDir->cbBuf = 0xffe0;
     233            pDir->pabBuf = birdMemAlloc(pDir->cbBuf);
     234            if (!pDir->pabBuf)
     235                return birdSetErrnoToNoMem();
     236        }
    183237
    184238        pDir->fFirst = 0;
     
    548602 * Implements closedir().
    549603 */
    550 int             birdDirClose(BirdDir_T *pDir)
     604int birdDirClose(BirdDir_T *pDir)
    551605{
    552606    if (!pDir || pDir->uMagic != BIRD_DIR_MAGIC)
     
    559613    birdMemFree(pDir->pabBuf);
    560614    pDir->pabBuf = NULL;
    561     birdMemFree(pDir);
     615    if (!(pDir->fFlags & BIRDDIR_F_STATIC_ALLOC))
     616        birdMemFree(pDir);
    562617
    563618    return 0;
Note: See TracChangeset for help on using the changeset viewer.