-
-
Save fd0/6587a615cea63183676e2f2887d59d62 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// +build linux | |
package main | |
import ( | |
"io" | |
"os" | |
"golang.org/x/sys/unix" | |
) | |
// POSIX_FADV_DONTNEED should be defined by the golang.org/x/sys/unix package, but isn't. | |
const POSIX_FADV_DONTNEED = 4 | |
func main() { | |
filename := os.Args[1] | |
f, err := os.Create(filename) | |
if err != nil { | |
panic(err) | |
} | |
_, err = io.Copy(f, os.Stdin) | |
if err != nil { | |
panic(err) | |
} | |
err = f.Sync() | |
if err != nil { | |
panic(err) | |
} | |
err = unix.Fadvise(int(f.Fd()), 0, 0, POSIX_FADV_DONTNEED) | |
if err != nil { | |
panic(err) | |
} | |
err = f.Close() | |
if err != nil { | |
panic(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment