Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(20)

Delta Between Two Patch Sets: src/pkg/os/file_mingw.go

Issue 851045: code review 851045: os: mingw version of Readdir() and Stat() implemented (Closed)
Left Patch Set: code review 851045: os: mingw version of Readdir() and Stat() implemented Created 14 years, 11 months ago
Right Patch Set: code review 851045: os: mingw version of Readdir() and Stat() implemented Created 14 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/os/file.go ('k') | src/pkg/os/file_unix.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 // Copyright 2009 The Go Authors. All rights reserved. 1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 // The os package provides a platform-independent interface to operating 5 // The os package provides a platform-independent interface to operating
6 // system functionality. The design is Unix-like. 6 // system functionality. The design is Unix-like.
7 package os 7 package os
8 8
9 import ( 9 import (
10 "runtime" 10 "runtime"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 err = &PathError{"close", file.name, Errno(e)} 79 err = &PathError{"close", file.name, Errno(e)}
80 } 80 }
81 file.fd = -1 // so it can't be closed again 81 file.fd = -1 // so it can't be closed again
82 82
83 // no need for a finalizer anymore 83 // no need for a finalizer anymore
84 runtime.SetFinalizer(file, nil) 84 runtime.SetFinalizer(file, nil)
85 return err 85 return err
86 } 86 }
87 87
88 // Readdir reads the contents of the directory associated with file and 88 // Readdir reads the contents of the directory associated with file and
89 // returns an array of up to count Dir structures, as would be returned 89 // returns an array of up to count FileInfo structures, as would be returned
90 // by Stat, in directory order. Subsequent calls on the same file will yield fu rther Dirs. 90 // by Stat, in directory order. Subsequent calls on the same file will yield
91 // further FileInfos.
91 // A negative count means to read until EOF. 92 // A negative count means to read until EOF.
92 // Readdir returns the array and an Error, if any. 93 // Readdir returns the array and an Error, if any.
93 func (file *File) Readdir(count int) (dirs []Dir, err Error) { 94 func (file *File) Readdir(count int) (fi []FileInfo, err Error) {
94 di := file.dirinfo 95 di := file.dirinfo
95 size := count 96 size := count
96 if size < 0 { 97 if size < 0 {
97 size = 100 98 size = 100
98 } 99 }
99 » dirs = make([]Dir, 0, size) // Empty with room to grow. 100 » fi = make([]FileInfo, 0, size) // Empty with room to grow.
100 for count != 0 { 101 for count != 0 {
101 var s syscall.Stat_t
102 p := &s
103 if di.usefirststat { 102 if di.usefirststat {
104 di.usefirststat = false 103 di.usefirststat = false
105 p = &di.stat
106 } else { 104 } else {
107 » » » _, e := syscall.FindNextFile(int32(file.fd), &s.Windata) 105 » » » _, e := syscall.FindNextFile(int32(file.fd), &di.stat.Wi ndata)
108 if e != 0 { 106 if e != 0 {
109 if e == syscall.ERROR_NO_MORE_FILES { 107 if e == syscall.ERROR_NO_MORE_FILES {
110 break 108 break
111 } else { 109 } else {
112 return nil, &PathError{"FindNextFile", f ile.name, Errno(e)} 110 return nil, &PathError{"FindNextFile", f ile.name, Errno(e)}
113 } 111 }
114 } 112 }
115 } 113 }
116 » » var dir Dir 114 » » var f FileInfo
117 » » dirFromStat("", &dir, p, p) 115 » » fileInfoFromStat("", &f, &di.stat, &di.stat)
118 » » if dir.Name == "." || dir.Name == ".." { // Useless names 116 » » if f.Name == "." || f.Name == ".." { // Useless names
119 continue 117 continue
120 } 118 }
121 count-- 119 count--
122 » » if len(dirs) == cap(dirs) { 120 » » if len(fi) == cap(fi) {
123 » » » ndirs := make([]Dir, len(dirs), 2*len(dirs)) 121 » » » nfi := make([]FileInfo, len(fi), 2*len(fi))
124 » » » for i := 0; i < len(dirs); i++ { 122 » » » for i := 0; i < len(fi); i++ {
125 » » » » ndirs[i] = dirs[i] 123 » » » » nfi[i] = fi[i]
126 } 124 }
127 » » » dirs = ndirs 125 » » » fi = nfi
128 } 126 }
129 » » dirs = dirs[0 : len(dirs)+1] 127 » » fi = fi[0 : len(fi)+1]
130 » » dirs[len(dirs)-1] = dir 128 » » fi[len(fi)-1] = f
131 } 129 }
132 » return dirs, nil 130 » return fi, nil
133 } 131 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b