SwiftでCatコマンドを作る
catコマンド catコマンドとは、与えられたファイルパスの中身を標準出力に書き込むコマンドです。今回はそれをSwiftで再現してみたいと思います。 The cat utility reads files sequentially, writing them to the standard output. The file operands are processed in command-line order. If file is a single dash (‘-’) or absent, cat reads from the standard input. If file is a UNIX domain socket, cat connects to it and then reads it until EOF. This complements the UNIX domain binding capability available in inetd(8). 今回は、一つのファイルを読んで出力するところまでを再現します。 Swiftからシステムコールを呼ぶ Swiftからreadやwriteなどのシステムコールを呼ぶために、今回はapple/swift-system: Low-level system calls and types for SwiftというApple製のSwift Packageを利用することにしました。 ...