commit 31ab1e2879765fc05589d10e2b68603275b269df
Author: Matsuda Kenji <info@mtkn.jp>
Date: Tue, 17 Sep 2024 15:25:42 +0900
first commit
Diffstat:
4 files changed, 60 insertions(+), 0 deletions(-)
diff --git a/cat/main.go b/cat/main.go
@@ -0,0 +1,45 @@
+package main
+
+import (
+ "fmt"
+ "io"
+ "os"
+)
+
+func main() {
+ if len(os.Args) == 1 {
+ cat(os.Stdin)
+ return
+ }
+ for _, fname := range os.Args[1:] {
+ f, err := os.Open(fname)
+ if err != nil {
+ fmt.Fprintf(os.Stderr, "cat: %v\n", err)
+ os.Exit(1)
+ }
+ if err := cat(f); err != nil {
+ fmt.Fprintf(os.Stderr, "cat: %v\n", err)
+ f.Close()
+ os.Exit(1)
+ }
+ f.Close()
+ }
+}
+
+func cat(f *os.File) error {
+ buf := make([]byte, 8192)
+ for {
+ n, err := f.Read(buf)
+ if n == 0 && err == io.EOF {
+ break
+ }
+ if err != nil {
+ return err
+ }
+ _, err = os.Stdout.Write(buf[:n])
+ if err != nil {
+ return err
+ }
+ }
+ return nil
+}
diff --git a/false/main.go b/false/main.go
@@ -0,0 +1,5 @@
+package main
+
+import "os"
+
+func main() { os.Exit(1) }
diff --git a/go.mod b/go.mod
@@ -0,0 +1,3 @@
+module git.mtkn.jp/goutils
+
+go 1.23.0
diff --git a/true/main.go b/true/main.go
@@ -0,0 +1,7 @@
+package main
+
+import "os"
+
+func main() {
+ os.Exit(0)
+}