Added extra check if fileContainsNullChar returns err; pass filename to it instead of file
This commit is contained in:
11
kg/main.go
11
kg/main.go
@@ -91,6 +91,7 @@ func main() {
|
||||
inputFilenames := flag.Args()[1:]
|
||||
for _, inputFilename := range inputFilenames {
|
||||
inputFile, err := os.Open(inputFilename)
|
||||
defer inputFile.Close()
|
||||
if err != nil {
|
||||
fmt.Printf("%s: %s: No such file or directory\n", os.Args[0], inputFilename)
|
||||
} else {
|
||||
@@ -102,8 +103,14 @@ func main() {
|
||||
if fileStat.Mode().IsDir() {
|
||||
fmt.Printf("%s: %s: Is a directory\n", os.Args[0], inputFilename)
|
||||
} else {
|
||||
if fileContainsNullChar(inputFile) {
|
||||
fmt.Printf("%s: %s: Is a binary file\n", os.Args[0], inputFilename)
|
||||
var nullCharPresent bool
|
||||
if nullCharPresent, err = fileContainsNullChar(inputFilename); nullCharPresent {
|
||||
if err != nil {
|
||||
fmt.Printf("%v\n", err)
|
||||
os.Exit(1)
|
||||
} else {
|
||||
fmt.Printf("%s: %s: Is a binary file\n", os.Args[0], inputFilename)
|
||||
}
|
||||
} else {
|
||||
inputFiles = append(inputFiles, inputFile)
|
||||
}
|
||||
|
Reference in New Issue
Block a user