func-os.go: fixed the handling of err==io.EOF

This commit is contained in:
Celestino Amoroso 2024-05-01 05:48:37 +02:00
parent be874503ec
commit d657cbb51e

View File

@ -126,7 +126,7 @@ func writeFileFunc(ctx ExprContext, name string, args []any) (result any, err er
func readFileFunc(ctx ExprContext, name string, args []any) (result any, err error) { func readFileFunc(ctx ExprContext, name string, args []any) (result any, err error) {
var handle osHandle var handle osHandle
result = nil
if len(args) > 0 { if len(args) > 0 {
handle, _ = args[0].(osHandle) handle, _ = args[0].(osHandle)
} }
@ -141,13 +141,16 @@ func readFileFunc(ctx ExprContext, name string, args []any) (result any, err err
limit = s[0] limit = s[0]
} }
} }
if v, err = r.reader.ReadString(limit); err == nil || err == io.EOF { if v, err = r.reader.ReadString(limit); err == nil {
if len(v) > 0 && v[len(v)-1] == limit { if len(v) > 0 && v[len(v)-1] == limit {
result = v[0 : len(v)-1] result = v[0 : len(v)-1]
} else { } else {
result = v result = v
} }
} }
if err == io.EOF {
err = nil
}
} }
} }
} }