Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <unistd.h>
- void incorrect_arg_fmt()
- {
- fputs("incorrect arguments\n", stderr);
- abort();
- }
- int main(int argc, char **argv)
- {
- int bytes = 2048;
- int just_read;
- void *buffer;
- if (argc == 2) {
- if (sscanf(argv[1], "%d", &bytes) != 1)
- incorrect_arg_fmt();
- } else if (argc != 1) {
- incorrect_arg_fmt();
- }
- buffer = malloc(bytes);
- while (bytes != 0 && (just_read = read(0, buffer, bytes)) != 0) {
- int delta;
- if (just_read < bytes)
- delta = just_read;
- else
- delta = bytes;
- bytes -= delta;
- write(1, buffer, delta);
- }
- free(buffer);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement