aboutsummaryrefslogtreecommitdiff
path: root/src/net/parse.go
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2022-11-08 15:08:48 -0800
committerGopher Robot <gobot@golang.org>2022-11-15 20:15:51 +0000
commit37ca171ce79a86924b7db4dd07b1e7760cfed4fc (patch)
tree7e098bdc63578d95b4016f02e70386b1cbcb848e /src/net/parse.go
parent678cd71d11f927fcde0c1fa5d380860ce77f8391 (diff)
downloadgo-37ca171ce79a86924b7db4dd07b1e7760cfed4fc.tar.xz
net: rewrite nsswitch.conf parsing to work like other parsers
Seems simpler than having two different parsing mechanisms. Change-Id: I4f8468bc025f8e03f59ec9c79b17721581b64eed Reviewed-on: https://go-review.googlesource.com/c/go/+/448855 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Joedian Reid <joedian@golang.org> Reviewed-by: Damien Neil <dneil@google.com> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/net/parse.go')
-rw-r--r--src/net/parse.go50
1 files changed, 13 insertions, 37 deletions
diff --git a/src/net/parse.go b/src/net/parse.go
index ee2890fe2c..fbc50144c2 100644
--- a/src/net/parse.go
+++ b/src/net/parse.go
@@ -64,6 +64,14 @@ func (f *file) readLine() (s string, ok bool) {
return
}
+func (f *file) stat() (mtime time.Time, size int64, err error) {
+ st, err := f.file.Stat()
+ if err != nil {
+ return time.Time{}, 0, err
+ }
+ return st.ModTime(), st.Size(), nil
+}
+
func open(name string) (*file, error) {
fd, err := os.Open(name)
if err != nil {
@@ -236,7 +244,7 @@ func lowerASCII(b byte) byte {
}
// trimSpace returns x without any leading or trailing ASCII whitespace.
-func trimSpace(x []byte) []byte {
+func trimSpace(x string) string {
for len(x) > 0 && isSpace(x[0]) {
x = x[1:]
}
@@ -253,37 +261,19 @@ func isSpace(b byte) bool {
// removeComment returns line, removing any '#' byte and any following
// bytes.
-func removeComment(line []byte) []byte {
- if i := bytealg.IndexByte(line, '#'); i != -1 {
+func removeComment(line string) string {
+ if i := bytealg.IndexByteString(line, '#'); i != -1 {
return line[:i]
}
return line
}
-// foreachLine runs fn on each line of x.
-// Each line (except for possibly the last) ends in '\n'.
-// It returns the first non-nil error returned by fn.
-func foreachLine(x []byte, fn func(line []byte) error) error {
- for len(x) > 0 {
- nl := bytealg.IndexByte(x, '\n')
- if nl == -1 {
- return fn(x)
- }
- line := x[:nl+1]
- x = x[nl+1:]
- if err := fn(line); err != nil {
- return err
- }
- }
- return nil
-}
-
// foreachField runs fn on each non-empty run of non-space bytes in x.
// It returns the first non-nil error returned by fn.
-func foreachField(x []byte, fn func(field []byte) error) error {
+func foreachField(x string, fn func(field string) error) error {
x = trimSpace(x)
for len(x) > 0 {
- sp := bytealg.IndexByte(x, ' ')
+ sp := bytealg.IndexByteString(x, ' ')
if sp == -1 {
return fn(x)
}
@@ -327,17 +317,3 @@ func stringsEqualFold(s, t string) bool {
}
return true
}
-
-func readFull(r io.Reader) (all []byte, err error) {
- buf := make([]byte, 1024)
- for {
- n, err := r.Read(buf)
- all = append(all, buf[:n]...)
- if err == io.EOF {
- return all, nil
- }
- if err != nil {
- return nil, err
- }
- }
-}