Compare commits
5 commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a281399876 | |||
| 1b00020597 | |||
| 036d9f8d82 | |||
|
|
dc1d5b6f24 | ||
|
|
ec4e798496 |
3 changed files with 23 additions and 16 deletions
|
|
@ -11,9 +11,9 @@ INCS =
|
||||||
LIBS =
|
LIBS =
|
||||||
|
|
||||||
# flags
|
# flags
|
||||||
CPPFLAGS = -DVERSION=\"${VERSION}\"
|
CPPFLAGS = -DVERSION=\"${VERSION}\" -D_XOPEN_SOURCE=500
|
||||||
CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
|
CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
|
||||||
LDFLAGS = -s ${LIBS}
|
LDFLAGS = -static -s ${LIBS}
|
||||||
|
|
||||||
# compiler and linker
|
# compiler and linker
|
||||||
CC = cc
|
CC = cc
|
||||||
|
|
|
||||||
35
slow.c
35
slow.c
|
|
@ -1,4 +1,3 @@
|
||||||
#define _XOPEN_SOURCE 500
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
@ -7,12 +6,18 @@
|
||||||
|
|
||||||
char *argv0;
|
char *argv0;
|
||||||
|
|
||||||
void usage() {
|
static void usage(void);
|
||||||
|
|
||||||
|
void
|
||||||
|
usage()
|
||||||
|
{
|
||||||
fprintf(stderr, "usage: %s [-t usec] [-f]\n", argv0);
|
fprintf(stderr, "usage: %s [-t usec] [-f]\n", argv0);
|
||||||
exit(EXIT_FAILURE);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
|
|
@ -31,18 +36,20 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
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(1);
|
||||||
}
|
|
||||||
if (flush) {
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (ferror(stdin)) {
|
|
||||||
fprintf(stderr, "stdin: read error");
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
if (flush)
|
||||||
|
fflush(stdout);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ferror(stdin)) {
|
||||||
|
fprintf(stderr, "stdin: read error");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue