Indentation & alignment.

Tabs for indentation, spaces for alignment.
This commit is contained in:
Simon Lieb 2015-03-11 18:47:28 +01:00
parent 68e58f2a9d
commit 26e7ffbbfc
2 changed files with 10 additions and 9 deletions

View file

@ -12,6 +12,7 @@ Usage
----- -----
$ slow [-t usec] [-f] $ slow [-t usec] [-f]
-t usec : Define sleep between each bytes in micro-second. Default to 1 second. -t usec : Define sleep between each bytes in micro-second. Default to 1 second.
-f : Force flushing after each byte. Useful with buffered stdout like ttys. -f : Force flushing after each byte. Useful with buffered stdout like ttys.

16
slow.c
View file

@ -13,10 +13,10 @@ void usage() {
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
char buffer; char buffer;
size_t nread; size_t nread;
useconds_t useconds = 1000000; // default 1 second useconds_t useconds = 1000000; // default 1 second
unsigned int flush = 0; unsigned int flush = 0;
ARGBEGIN { ARGBEGIN {
case 't': case 't':
@ -29,17 +29,17 @@ int main(int argc, char *argv[]) {
usage(); usage();
} ARGEND; } ARGEND;
while((nread = fread(&buffer, 1, sizeof buffer, stdin)) > 0) { while ((nread = fread(&buffer, 1, sizeof buffer, stdin)) > 0) {
usleep(useconds); usleep(useconds);
if(fwrite(&buffer, 1, nread, stdout) != nread) { if (fwrite(&buffer, 1, nread, stdout) != nread) {
fprintf(stderr, "stdout: write error"); fprintf(stderr, "stdout: write error");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if(flush) { if (flush) {
fflush(stdout); fflush(stdout);
} }
} }
if(ferror(stdin)) { if (ferror(stdin)) {
fprintf(stderr, "stdin: read error"); fprintf(stderr, "stdin: read error");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }