diff --git a/examples/other/cat_noblock.c b/examples/other/cat_nonblock.c similarity index 85% rename from examples/other/cat_noblock.c rename to examples/other/cat_nonblock.c index 42117cd..50f3b67 100644 --- a/examples/other/cat_noblock.c +++ b/examples/other/cat_nonblock.c @@ -1,5 +1,5 @@ /* - * cat_noblock.c - open a file and display its contents, but exit rather than + * cat_nonblock.c - open a file and display its contents, but exit rather than * wait for input. */ #include /* for errno */ @@ -16,7 +16,6 @@ int main(int argc, char *argv[]) size_t bytes; /* The number of bytes read */ char buffer[MAX_BYTES]; /* The buffer for the bytes */ - /* Usage */ if (argc != 2) { printf("Usage: %s \n", argv[0]); @@ -29,17 +28,12 @@ int main(int argc, char *argv[]) /* If open failed */ if (fd == -1) { - if (errno = EAGAIN) - puts("Open would block"); - else - puts("Open failed"); + puts(errno == EAGAIN ? "Open would block" : "Open failed"); exit(-1); } /* Read the file and output its contents */ do { - int i; - /* Read characters from the file */ bytes = read(fd, buffer, MAX_BYTES); @@ -54,11 +48,12 @@ int main(int argc, char *argv[]) /* Print the characters */ if (bytes > 0) { - for (i = 0; i < bytes; i++) + for (int i = 0; i < bytes; i++) putchar(buffer[i]); } /* While there are no errors and the file isn't over */ } while (bytes > 0); + return 0; } diff --git a/lkmpg.tex b/lkmpg.tex index e5afe44..0bd97fa 100644 --- a/lkmpg.tex +++ b/lkmpg.tex @@ -1238,7 +1238,7 @@ There is one more point to remember. Some times processes don't want to sleep, t \begin{verbatim} $ sudo insmod sleep.ko -$ cat_noblock /proc/sleep +$ cat_nonblock /proc/sleep Last input: $ tail -f /proc/sleep & Last input: @@ -1250,18 +1250,18 @@ Last input: Last input: tail: /proc/sleep: file truncated [1] 6540 -$ cat_noblock /proc/sleep +$ cat_nonblock /proc/sleep Open would block $ kill %1 [1]+ Terminated tail -f /proc/sleep -$ cat_noblock /proc/sleep +$ cat_nonblock /proc/sleep Last input: $ \end{verbatim} \samplec{examples/sleep.c} -\samplec{examples/other/cat_noblock.c} +\samplec{examples/other/cat_nonblock.c} \subsection{Completions} \label{sec:orgd9f9de4}