Mercurial > emacs
comparison src/w32.c @ 23622:0dc79ede9c53
(stat): GetFileInformationByHandle can legitimately fail, so don't
rely on it succeeding.
author | Andrew Innes <andrewi@gnu.org> |
---|---|
date | Tue, 03 Nov 1998 22:39:04 +0000 |
parents | 989c9cb875e3 |
children | 2a6ad78388b3 |
comparison
equal
deleted
inserted
replaced
23621:82325b2dbb5e | 23622:0dc79ede9c53 |
---|---|
1958 making a list of file name completions). */ | 1958 making a list of file name completions). */ |
1959 BY_HANDLE_FILE_INFORMATION info; | 1959 BY_HANDLE_FILE_INFORMATION info; |
1960 | 1960 |
1961 if (GetFileInformationByHandle (fh, &info)) | 1961 if (GetFileInformationByHandle (fh, &info)) |
1962 { | 1962 { |
1963 switch (GetFileType (fh)) | |
1964 { | |
1965 case FILE_TYPE_DISK: | |
1966 buf->st_mode = _S_IFREG; | |
1967 break; | |
1968 case FILE_TYPE_PIPE: | |
1969 buf->st_mode = _S_IFIFO; | |
1970 break; | |
1971 case FILE_TYPE_CHAR: | |
1972 case FILE_TYPE_UNKNOWN: | |
1973 default: | |
1974 buf->st_mode = _S_IFCHR; | |
1975 } | |
1976 buf->st_nlink = info.nNumberOfLinks; | 1963 buf->st_nlink = info.nNumberOfLinks; |
1977 /* Might as well use file index to fake inode values, but this | 1964 /* Might as well use file index to fake inode values, but this |
1978 is not guaranteed to be unique unless we keep a handle open | 1965 is not guaranteed to be unique unless we keep a handle open |
1979 all the time (even then there are situations where it is | 1966 all the time (even then there are situations where it is |
1980 not unique). Reputedly, there are at most 48 bits of info | 1967 not unique). Reputedly, there are at most 48 bits of info |
1981 (on NTFS, presumably less on FAT). */ | 1968 (on NTFS, presumably less on FAT). */ |
1982 fake_inode = info.nFileIndexLow ^ info.nFileIndexHigh; | 1969 fake_inode = info.nFileIndexLow ^ info.nFileIndexHigh; |
1983 CloseHandle (fh); | |
1984 } | 1970 } |
1985 else | 1971 else |
1986 { | 1972 { |
1987 errno = EACCES; | 1973 buf->st_nlink = 1; |
1988 return -1; | 1974 fake_inode = 0; |
1989 } | 1975 } |
1976 | |
1977 switch (GetFileType (fh)) | |
1978 { | |
1979 case FILE_TYPE_DISK: | |
1980 buf->st_mode = _S_IFREG; | |
1981 break; | |
1982 case FILE_TYPE_PIPE: | |
1983 buf->st_mode = _S_IFIFO; | |
1984 break; | |
1985 case FILE_TYPE_CHAR: | |
1986 case FILE_TYPE_UNKNOWN: | |
1987 default: | |
1988 buf->st_mode = _S_IFCHR; | |
1989 } | |
1990 CloseHandle (fh); | |
1990 } | 1991 } |
1991 else | 1992 else |
1992 { | 1993 { |
1993 /* Don't bother to make this information more accurate. */ | 1994 /* Don't bother to make this information more accurate. */ |
1994 buf->st_mode = _S_IFREG; | 1995 buf->st_mode = _S_IFREG; |