Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 153566
Collapse All | Expand All

(-)file_not_specified_in_diff (-15 / +58 lines)
Line  Link Here
0
-- dlls/kernel32/file.c
0
++ dlls/kernel32/file.c
Lines 1553-1558 HANDLE WINAPI FindFirstFileExW( LPCWSTR Link Here
1553
    OBJECT_ATTRIBUTES attr;
1553
    OBJECT_ATTRIBUTES attr;
1554
    IO_STATUS_BLOCK io;
1554
    IO_STATUS_BLOCK io;
1555
    NTSTATUS status;
1555
    NTSTATUS status;
1556
    DWORD device = 0;
1556
1557
1557
    TRACE("%s %d %p %d %p %x\n", debugstr_w(filename), level, data, search_op, filter, flags);
1558
    TRACE("%s %d %p %d %p %x\n", debugstr_w(filename), level, data, search_op, filter, flags);
1558
1559
Lines 1574-1600 HANDLE WINAPI FindFirstFileExW( LPCWSTR Link Here
1574
        return INVALID_HANDLE_VALUE;
1575
        return INVALID_HANDLE_VALUE;
1575
    }
1576
    }
1576
1577
1577
    if (!mask || !*mask)
1578
    {
1579
        SetLastError( ERROR_FILE_NOT_FOUND );
1580
        goto error;
1581
    }
1582
1583
    if (!(info = HeapAlloc( GetProcessHeap(), 0, sizeof(*info))))
1578
    if (!(info = HeapAlloc( GetProcessHeap(), 0, sizeof(*info))))
1584
    {
1579
    {
1585
        SetLastError( ERROR_NOT_ENOUGH_MEMORY );
1580
        SetLastError( ERROR_NOT_ENOUGH_MEMORY );
1586
        goto error;
1581
        goto error;
1587
    }
1582
    }
1588
1583
1589
    if (!RtlCreateUnicodeString( &info->mask, mask ))
1584
    if (!mask && (device = RtlIsDosDeviceName_U( filename )))
1590
    {
1585
    {
1591
        SetLastError( ERROR_NOT_ENOUGH_MEMORY );
1586
        static const WCHAR dotW[] = {'.',0};
1587
        WCHAR *dir = NULL;
1588
1589
        /* we still need to check that the directory can be opened */
1590
1591
        if (HIWORD(device))
1592
        {
1593
            if (!(dir = HeapAlloc( GetProcessHeap(), 0, HIWORD(device) + sizeof(WCHAR) )))
1594
            {
1595
                SetLastError( ERROR_NOT_ENOUGH_MEMORY );
1596
                goto error;
1597
            }
1598
            memcpy( dir, filename, HIWORD(device) );
1599
            dir[HIWORD(device)/sizeof(WCHAR)] = 0;
1600
        }
1601
        RtlFreeUnicodeString( &nt_name );
1602
        if (!RtlDosPathNameToNtPathName_U( dir ? dir : dotW, &nt_name, &mask, NULL ))
1603
        {
1604
            HeapFree( GetProcessHeap(), 0, dir );
1605
            SetLastError( ERROR_PATH_NOT_FOUND );
1606
            goto error;
1607
        }
1608
        HeapFree( GetProcessHeap(), 0, dir );
1609
        RtlInitUnicodeString( &info->mask, NULL );
1610
    }
1611
    else if (!mask || !*mask)
1612
    {
1613
        SetLastError( ERROR_FILE_NOT_FOUND );
1592
        goto error;
1614
        goto error;
1593
    }
1615
    }
1616
    else
1617
    {
1618
        if (!RtlCreateUnicodeString( &info->mask, mask ))
1619
        {
1620
            SetLastError( ERROR_NOT_ENOUGH_MEMORY );
1621
            goto error;
1622
        }
1594
1623
1595
    /* truncate dir name before mask */
1624
        /* truncate dir name before mask */
1596
    *mask = 0;
1625
        *mask = 0;
1597
    nt_name.Length = (mask - nt_name.Buffer) * sizeof(WCHAR);
1626
        nt_name.Length = (mask - nt_name.Buffer) * sizeof(WCHAR);
1627
    }
1598
1628
1599
    /* check if path is the root of the drive */
1629
    /* check if path is the root of the drive */
1600
    info->is_root = FALSE;
1630
    info->is_root = FALSE;
Lines 1620-1626 HANDLE WINAPI FindFirstFileExW( LPCWSTR Link Here
1620
    if (status != STATUS_SUCCESS)
1650
    if (status != STATUS_SUCCESS)
1621
    {
1651
    {
1622
        RtlFreeUnicodeString( &info->mask );
1652
        RtlFreeUnicodeString( &info->mask );
1623
        SetLastError( RtlNtStatusToDosError(status) );
1653
        if (status == STATUS_OBJECT_NAME_NOT_FOUND)
1654
            SetLastError( ERROR_PATH_NOT_FOUND );
1655
        else
1656
            SetLastError( RtlNtStatusToDosError(status) );
1624
        goto error;
1657
        goto error;
1625
    }
1658
    }
1626
1659
Lines 1631-1644 HANDLE WINAPI FindFirstFileExW( LPCWSTR Link Here
1631
    info->data_len = 0;
1664
    info->data_len = 0;
1632
    info->search_op = search_op;
1665
    info->search_op = search_op;
1633
1666
1634
    if (!FindNextFileW( (HANDLE)info, data ))
1667
    if (device)
1668
    {
1669
        WIN32_FIND_DATAW *wfd = data;
1670
1671
        memset( wfd, 0, sizeof(*wfd) );
1672
        memcpy( wfd->cFileName, filename + HIWORD(device)/sizeof(WCHAR), LOWORD(device) );
1673
        wfd->dwFileAttributes = FILE_ATTRIBUTE_ARCHIVE;
1674
        CloseHandle( info->handle );
1675
        info->handle = 0;
1676
    }
1677
    else if (!FindNextFileW( (HANDLE)info, data ))
1635
    {
1678
    {
1636
        TRACE( "%s not found\n", debugstr_w(filename) );
1679
        TRACE( "%s not found\n", debugstr_w(filename) );
1637
        FindClose( (HANDLE)info );
1680
        FindClose( (HANDLE)info );
1638
        SetLastError( ERROR_FILE_NOT_FOUND );
1681
        SetLastError( ERROR_FILE_NOT_FOUND );
1639
        return INVALID_HANDLE_VALUE;
1682
        return INVALID_HANDLE_VALUE;
1640
    }
1683
    }
1641
    if (!strpbrkW( info->mask.Buffer, wildcardsW ))
1684
    else if (!strpbrkW( info->mask.Buffer, wildcardsW ))
1642
    {
1685
    {
1643
        /* we can't find two files with the same name */
1686
        /* we can't find two files with the same name */
1644
        CloseHandle( info->handle );
1687
        CloseHandle( info->handle );
(-)dlls/kernel32/tests/file.c (-16 / +77 lines)
Lines 1186-1192 Link Here
1186
static void test_FindFirstFileA(void)
1186
static void test_FindFirstFileA(void)
1187
{
1187
{
1188
    HANDLE handle;
1188
    HANDLE handle;
1189
    WIN32_FIND_DATAA search_results;
1189
    WIN32_FIND_DATAA data;
1190
    int err;
1190
    int err;
1191
    char buffer[5] = "C:\\";
1191
    char buffer[5] = "C:\\";
1192
    char buffer2[100];
1192
    char buffer2[100];
Lines 1195-1201 Link Here
1195
    buffer[0] = get_windows_drive();
1195
    buffer[0] = get_windows_drive();
1196
    
1196
    
1197
    SetLastError( 0xdeadbeaf );
1197
    SetLastError( 0xdeadbeaf );
1198
    handle = FindFirstFileA(buffer, &search_results);
1198
    handle = FindFirstFileA(buffer, &data);
1199
    err = GetLastError();
1199
    err = GetLastError();
1200
    ok ( handle == INVALID_HANDLE_VALUE, "FindFirstFile on root directory should fail\n" );
1200
    ok ( handle == INVALID_HANDLE_VALUE, "FindFirstFile on root directory should fail\n" );
1201
    ok ( err == ERROR_FILE_NOT_FOUND, "Bad Error number %d\n", err );
1201
    ok ( err == ERROR_FILE_NOT_FOUND, "Bad Error number %d\n", err );
Lines 1203-1209 Link Here
1203
    /* try FindFirstFileA on "C:\*" */
1203
    /* try FindFirstFileA on "C:\*" */
1204
    strcpy(buffer2, buffer);
1204
    strcpy(buffer2, buffer);
1205
    strcat(buffer2, "*");
1205
    strcat(buffer2, "*");
1206
    handle = FindFirstFileA(buffer2, &search_results);
1206
    handle = FindFirstFileA(buffer2, &data);
1207
    ok ( handle != INVALID_HANDLE_VALUE, "FindFirstFile on %s should succeed\n", buffer2 );
1207
    ok ( handle != INVALID_HANDLE_VALUE, "FindFirstFile on %s should succeed\n", buffer2 );
1208
    ok ( FindClose(handle) == TRUE, "Failed to close handle %s\n", buffer2 );
1208
    ok ( FindClose(handle) == TRUE, "Failed to close handle %s\n", buffer2 );
1209
1209
Lines 1211-1217 Link Here
1211
    SetLastError( 0xdeadbeaf );
1211
    SetLastError( 0xdeadbeaf );
1212
    strcpy(buffer2, buffer);
1212
    strcpy(buffer2, buffer);
1213
    strcat(buffer2, "foo\\");
1213
    strcat(buffer2, "foo\\");
1214
    handle = FindFirstFileA(buffer2, &search_results);
1214
    handle = FindFirstFileA(buffer2, &data);
1215
    err = GetLastError();
1215
    err = GetLastError();
1216
    ok ( handle == INVALID_HANDLE_VALUE, "FindFirstFile on %s should Fail\n", buffer2 );
1216
    ok ( handle == INVALID_HANDLE_VALUE, "FindFirstFile on %s should Fail\n", buffer2 );
1217
    todo_wine {
1217
    todo_wine {
Lines 1222-1254 Link Here
1222
    SetLastError( 0xdeadbeaf );
1222
    SetLastError( 0xdeadbeaf );
1223
    strcpy(buffer2, buffer);
1223
    strcpy(buffer2, buffer);
1224
    strcat(buffer2, "foo\\bar.txt");
1224
    strcat(buffer2, "foo\\bar.txt");
1225
    handle = FindFirstFileA(buffer2, &search_results);
1225
    handle = FindFirstFileA(buffer2, &data);
1226
    err = GetLastError();
1226
    err = GetLastError();
1227
    ok ( handle == INVALID_HANDLE_VALUE, "FindFirstFile on %s should Fail\n", buffer2 );
1227
    ok ( handle == INVALID_HANDLE_VALUE, "FindFirstFile on %s should Fail\n", buffer2 );
1228
    todo_wine {
1228
    ok ( err == ERROR_PATH_NOT_FOUND, "Bad Error number %d\n", err );
1229
	ok ( err == ERROR_PATH_NOT_FOUND, "Bad Error number %d\n", err );
1230
    }
1231
1229
1232
    /* try FindFirstFileA on "C:\foo\*.*" */
1230
    /* try FindFirstFileA on "C:\foo\*.*" */
1233
    SetLastError( 0xdeadbeaf );
1231
    SetLastError( 0xdeadbeaf );
1234
    strcpy(buffer2, buffer);
1232
    strcpy(buffer2, buffer);
1235
    strcat(buffer2, "foo\\*.*");
1233
    strcat(buffer2, "foo\\*.*");
1236
    handle = FindFirstFileA(buffer2, &search_results);
1234
    handle = FindFirstFileA(buffer2, &data);
1237
    err = GetLastError();
1235
    err = GetLastError();
1238
    ok ( handle == INVALID_HANDLE_VALUE, "FindFirstFile on %s should Fail\n", buffer2 );
1236
    ok ( handle == INVALID_HANDLE_VALUE, "FindFirstFile on %s should Fail\n", buffer2 );
1239
    todo_wine {
1237
    ok ( err == ERROR_PATH_NOT_FOUND, "Bad Error number %d\n", err );
1240
	ok ( err == ERROR_PATH_NOT_FOUND, "Bad Error number %d\n", err );
1241
    }
1242
1238
1243
    /* try FindFirstFileA on "foo\bar.txt" */
1239
    /* try FindFirstFileA on "foo\bar.txt" */
1244
    SetLastError( 0xdeadbeaf );
1240
    SetLastError( 0xdeadbeaf );
1245
    strcpy(buffer2, "foo\\bar.txt");
1241
    strcpy(buffer2, "foo\\bar.txt");
1246
    handle = FindFirstFileA(buffer2, &search_results);
1242
    handle = FindFirstFileA(buffer2, &data);
1247
    err = GetLastError();
1243
    err = GetLastError();
1248
    ok ( handle == INVALID_HANDLE_VALUE, "FindFirstFile on %s should Fail\n", buffer2 );
1244
    ok ( handle == INVALID_HANDLE_VALUE, "FindFirstFile on %s should Fail\n", buffer2 );
1249
    todo_wine {
1245
    ok ( err == ERROR_PATH_NOT_FOUND, "Bad Error number %d\n", err );
1250
	ok ( err == ERROR_PATH_NOT_FOUND, "Bad Error number %d\n", err );
1246
1251
    }
1247
   /* try FindFirstFileA on "c:\nul" */
1248
   SetLastError( 0xdeadbeaf );
1249
   strcpy(buffer2, buffer);
1250
   strcat(buffer2, "nul");
1251
   handle = FindFirstFileA(buffer2, &data);
1252
   err = GetLastError();
1253
   ok( handle != INVALID_HANDLE_VALUE, "FindFirstFile on %s failed\n", buffer2 );
1254
   ok( 0 == lstrcmpiA(data.cFileName, "nul"), "wrong name %s\n", data.cFileName );
1255
   ok( 0 == data.nFileSizeHigh, "wrong size %d\n", data.nFileSizeHigh );
1256
   ok( 0 == data.nFileSizeLow, "wrong size %d\n", data.nFileSizeLow );
1257
   ok( FILE_ATTRIBUTE_ARCHIVE == data.dwFileAttributes, "wrong attributes %x\n", data.dwFileAttributes );
1258
   SetLastError( 0xdeadbeaf );
1259
   ok( !FindNextFileA( handle, &data ), "FindNextFileA succeeded\n" );
1260
   ok( GetLastError() == ERROR_NO_MORE_FILES, "bad error %d\n", GetLastError() );
1261
   ok( FindClose( handle ), "failed to close handle\n" );
1262
1263
   /* try FindFirstFileA on "lpt1" */
1264
   SetLastError( 0xdeadbeaf );
1265
   strcpy(buffer2, "lpt1");
1266
   handle = FindFirstFileA(buffer2, &data);
1267
   err = GetLastError();
1268
   ok( handle != INVALID_HANDLE_VALUE, "FindFirstFile on %s failed\n", buffer2 );
1269
   ok( 0 == lstrcmpiA(data.cFileName, "lpt1"), "wrong name %s\n", data.cFileName );
1270
   ok( 0 == data.nFileSizeHigh, "wrong size %d\n", data.nFileSizeHigh );
1271
   ok( 0 == data.nFileSizeLow, "wrong size %d\n", data.nFileSizeLow );
1272
   ok( FILE_ATTRIBUTE_ARCHIVE == data.dwFileAttributes, "wrong attributes %x\n", data.dwFileAttributes );
1273
   SetLastError( 0xdeadbeaf );
1274
   ok( !FindNextFileA( handle, &data ), "FindNextFileA succeeded\n" );
1275
   ok( GetLastError() == ERROR_NO_MORE_FILES, "bad error %d\n", GetLastError() );
1276
   ok( FindClose( handle ), "failed to close handle\n" );
1277
1278
   /* try FindFirstFileA on "c:\nul\*" */
1279
   SetLastError( 0xdeadbeaf );
1280
   strcpy(buffer2, buffer);
1281
   strcat(buffer2, "nul\\*");
1282
   handle = FindFirstFileA(buffer2, &data);
1283
   err = GetLastError();
1284
   ok ( handle == INVALID_HANDLE_VALUE, "FindFirstFile on %s should Fail\n", buffer2 );
1285
   ok ( err == ERROR_PATH_NOT_FOUND, "Bad Error number %d\n", err );
1286
1287
   /* try FindFirstFileA on "c:\nul*" */
1288
   SetLastError( 0xdeadbeaf );
1289
   strcpy(buffer2, buffer);
1290
   strcat(buffer2, "nul*");
1291
   handle = FindFirstFileA(buffer2, &data);
1292
   err = GetLastError();
1293
   ok ( handle == INVALID_HANDLE_VALUE, "FindFirstFile on %s should Fail\n", buffer2 );
1294
   ok ( err == ERROR_FILE_NOT_FOUND, "Bad Error number %d\n", err );
1295
1296
   /* try FindFirstFileA on "c:\foo\bar\nul" */
1297
   SetLastError( 0xdeadbeaf );
1298
   strcpy(buffer2, buffer);
1299
   strcat(buffer2, "foo\\bar\\nul");
1300
   handle = FindFirstFileA(buffer2, &data);
1301
   err = GetLastError();
1302
   ok ( handle == INVALID_HANDLE_VALUE, "FindFirstFile on %s should Fail\n", buffer2 );
1303
   ok ( err == ERROR_PATH_NOT_FOUND, "Bad Error number %d\n", err );
1304
1305
   /* try FindFirstFileA on "c:\foo\nul\bar" */
1306
   SetLastError( 0xdeadbeaf );
1307
   strcpy(buffer2, buffer);
1308
   strcat(buffer2, "foo\\nul\\bar");
1309
   handle = FindFirstFileA(buffer2, &data);
1310
   err = GetLastError();
1311
   ok ( handle == INVALID_HANDLE_VALUE, "FindFirstFile on %s should Fail\n", buffer2 );
1312
   ok ( err == ERROR_PATH_NOT_FOUND, "Bad Error number %d\n", err );
1252
}
1313
}
1253
1314
1254
static void test_FindNextFileA(void)
1315
static void test_FindNextFileA(void)

Return to bug 153566