summaryrefslogtreecommitdiffhomepage
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/mfmt/main.go19
1 files changed, 18 insertions, 1 deletions
diff --git a/cmd/mfmt/main.go b/cmd/mfmt/main.go
index f2aa24f..57d9e8f 100644
--- a/cmd/mfmt/main.go
+++ b/cmd/mfmt/main.go
@@ -7,6 +7,7 @@ package main
import (
"bufio"
+ "bytes"
"fmt"
"io"
"os"
@@ -36,7 +37,23 @@ func main() {
continue
}
defer f.Close()
- mfmt(arg, f, f)
+
+ buf := bytes.NewBuffer(make([]byte, 0, 8192))
+ mfmt(arg, f, buf)
+
+ if _, err = f.Seek(0, io.SeekStart); err != nil {
+ warn(err)
+ continue
+ }
+
+ if _, err = f.Write(buf.Bytes()); err != nil {
+ warn(err)
+ continue
+ }
+
+ if err = f.Truncate(int64(buf.Len())); err != nil {
+ warn(err)
+ }
}
os.Exit(rv)
}