t.Errorf("files should be different")
}
}
+
+func TestDevNullFile(t *testing.T) {
+ f, err := Open(DevNull)
+ if err != nil {
+ t.Fatalf("Open(%s): %v", DevNull, err)
+ }
+ defer f.Close()
+ fi, err := f.Stat()
+ if err != nil {
+ t.Fatalf("Stat(%s): %v", DevNull, err)
+ }
+ name := filepath.Base(DevNull)
+ if fi.Name() != name {
+ t.Fatalf("wrong file name have %v want %v", fi.Name(), name)
+ }
+ if fi.Size() != 0 {
+ t.Fatalf("wrong file size have %d want 0", fi.Size())
+ }
+}
// I don't know any better way to do that for directory
return Stat(file.name)
}
+ if file.name == DevNull {
+ return statDevNull()
+ }
var d syscall.ByHandleFileInformation
e := syscall.GetFileInformationByHandle(syscall.Handle(file.fd), &d)
if e != nil {
if len(name) == 0 {
return nil, &PathError{"Stat", name, syscall.Errno(syscall.ERROR_PATH_NOT_FOUND)}
}
+ if name == DevNull {
+ return statDevNull()
+ }
var d syscall.Win32FileAttributeData
e := syscall.GetFileAttributesEx(syscall.StringToUTF16Ptr(name), syscall.GetFileExInfoStandard, (*byte)(unsafe.Pointer(&d)))
if e != nil {
return Stat(name)
}
+// statDevNull return FileInfo structure describing DevNull file ("NUL").
+// It creates invented data, since none of windows api will return
+// that information.
+func statDevNull() (fi FileInfo, err error) {
+ return &fileStat{
+ name: DevNull,
+ mode: ModeDevice | ModeCharDevice | 0666,
+ sys: &winSys{
+ // hopefully this will work for SameFile
+ vol: 0,
+ idxhi: 0,
+ idxlo: 0,
+ },
+ }, nil
+}
+
// basename removes trailing slashes and the leading
// directory name and drive letter from path name.
func basename(name string) string {