VirtualBox

Changeset 2707 in kBuild


Ignore:
Timestamp:
Nov 21, 2013 2:25:00 AM (11 years ago)
Author:
bird
Message:

ntstat.c: Fixed fstat()'ing console handles and pipes.

Location:
trunk/src/lib/nt
Files:
2 edited

Legend:

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

    r2704 r2707  
    456456    HANDLE  hFile = (HANDLE)_get_osfhandle(fd);
    457457    if (hFile != INVALID_HANDLE_VALUE)
    458         rc = birdStatHandle(hFile, pStat, NULL);
     458    {
     459        DWORD fFileType;
     460
     461        SetLastError(NO_ERROR);
     462        fFileType = GetFileType(hFile) & ~FILE_TYPE_REMOTE;
     463        switch (fFileType)
     464        {
     465            case FILE_TYPE_DISK:
     466                rc = birdStatHandle(hFile, pStat, NULL);
     467                break;
     468
     469            case FILE_TYPE_CHAR:
     470            case FILE_TYPE_PIPE:
     471                if (fFileType == FILE_TYPE_PIPE)
     472                    pStat->st_mode          = S_IFIFO | 0666;
     473                else
     474                    pStat->st_mode          = S_IFCHR | 0666;
     475                pStat->st_padding0[0]       = 0;
     476                pStat->st_padding0[1]       = 0;
     477                pStat->st_size              = 0;
     478                pStat->st_atim.tv_sec       = 0;
     479                pStat->st_atim.tv_nsec      = 0;
     480                pStat->st_mtim.tv_sec       = 0;
     481                pStat->st_mtim.tv_nsec      = 0;
     482                pStat->st_ctim.tv_sec       = 0;
     483                pStat->st_ctim.tv_nsec      = 0;
     484                pStat->st_birthtim.tv_sec   = 0;
     485                pStat->st_birthtim.tv_nsec  = 0;
     486                pStat->st_ino               = 0;
     487                pStat->st_dev               = 0;
     488                pStat->st_rdev              = 0;
     489                pStat->st_uid               = 0;
     490                pStat->st_gid               = 0;
     491                pStat->st_padding1[0]       = 0;
     492                pStat->st_padding1[1]       = 0;
     493                pStat->st_padding1[2]       = 0;
     494                pStat->st_blksize           = 512;
     495                pStat->st_blocks            = 0;
     496                if (fFileType == FILE_TYPE_PIPE)
     497                {
     498                    DWORD cbAvail;
     499                    if (PeekNamedPipe(hFile, NULL, 0, NULL, &cbAvail, NULL))
     500                        pStat->st_size = cbAvail;
     501                }
     502                rc = 0;
     503                break;
     504
     505            case FILE_TYPE_UNKNOWN:
     506            default:
     507                if (GetLastError() == NO_ERROR)
     508                    rc = birdSetErrnoToBadFileNo();
     509                else
     510                    rc = birdSetErrnoFromWin32(GetLastError());
     511                break;
     512        }
     513    }
    459514    else
    460515        rc = -1;
  • trunk/src/lib/nt/ntstat.h

    r2702 r2707  
    9494# define S_IFLNK        _S_IFLNK
    9595#endif
     96#ifndef S_IFIFO
     97# define S_IFIFO        _S_IFIFO
     98#endif
    9699
    97100#ifndef S_ISLNK
     
    105108#endif
    106109
    107 #define S_IRWXU        (_S_IREAD | _S_IWRITE | _S_IEXEC)
    108 #define S_IXUSR        _S_IEXEC
    109 #define S_IWUSR        _S_IWRITE
    110 #define S_IRUSR        _S_IREAD
    111 #define S_IRWXG        0000070
    112 #define S_IRGRP        0000040
    113 #define S_IWGRP        0000020
    114 #define S_IXGRP        0000010
    115 #define S_IRWXO        0000007
    116 #define S_IROTH        0000004
    117 #define S_IWOTH        0000002
    118 #define S_IXOTH        0000001
    119 #define S_ISUID        0004000
    120 #define S_ISGID        0002000
    121 #define ALLPERMS       0000777
     110#define S_IRWXU         (_S_IREAD | _S_IWRITE | _S_IEXEC)
     111#define S_IXUSR         _S_IEXEC
     112#define S_IWUSR         _S_IWRITE
     113#define S_IRUSR         _S_IREAD
     114#define S_IRWXG         0000070
     115#define S_IRGRP         0000040
     116#define S_IWGRP         0000020
     117#define S_IXGRP         0000010
     118#define S_IRWXO         0000007
     119#define S_IROTH         0000004
     120#define S_IWOTH         0000002
     121#define S_IXOTH         0000001
     122#define S_ISUID         0004000
     123#define S_ISGID         0002000
     124#define ALLPERMS        0000777
    122125
    123126#endif
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