2006-06-18から1日間の記事一覧

5.8 練習問題の解答

P100 練習問題。 1. 本章で作ったcatコマンドを改造して、コマンドライン引数でファイル名が渡されなかったら標準入力を読むようにしなさい。 do_cat()をオーバーロードして、 static void do_cat( const char *path ); static void do_cat( int fd );として…

screenのコピーモード

screenでC-a escとするとコピー/スクロールバックモードに入る(screenコマンドの開始をC-aにしている場合)。このモードではvi形式のキー操作でカーソル移動とかスクロールアップダウンができる(hjklとC-u/C-d)。 というのは最近知って便利だなーと思って…

catコマンドを作る

P86 掲載されているソースを見ないで書いてみる。 #include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #define BUF_SIZE 1024 void do_cat( const char *pszFileName ) { int fd = open( pszFileName, O_RDONLY ); if (fd > 0) { char buf[BUF_SIZE]; int b</fcntl.h></sys/stat.h></sys/types.h></unistd.h></stdio.h>…