Created
February 28, 2018 20:48
-
-
Save scriptnull/04950add551c91d4060c8c165290074d to your computer and use it in GitHub Desktop.
Opens multiple files and prints out their file descriptor value
This file contains hidden or 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
| package main | |
| import ( | |
| "fmt" | |
| "log" | |
| "os" | |
| "golang.org/x/sys/unix" | |
| ) | |
| func main() { | |
| if len(os.Args) < 2 { | |
| log.Fatalln("Requires atleast one argument") | |
| } | |
| for _, filePath := range os.Args[1:] { | |
| // Example of filePath: /home/scriptnull/cool/code.js | |
| if filePath == "" { | |
| log.Fatalln("Requires a non-empty file path") | |
| } | |
| // Open the filePath | |
| fd, err := unix.Open(filePath, unix.O_RDWR|unix.O_CREAT, 0755) | |
| if err != nil { | |
| log.Fatalf("Error: %+v fd: %d \n", err, fd) | |
| } | |
| // Print the file Descriptor | |
| fmt.Printf("File descriptor value of %s is %d \n", filePath, fd) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment