File: ch255.c

package info (click to toggle)
lbzip2 2.5-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,624 kB
  • sloc: ansic: 27,584; sh: 4,306; perl: 154; makefile: 70
file content (38 lines) | stat: -rw-r--r-- 618 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/* Copyright (C) 2011 Mikolaj Izdebski */

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int
main(int argc, char **argv)
{
  size_t req_sz;
  char buf[4096];

  errno = 0;
  req_sz = 900000;
  if (argc > 1)
    req_sz = strtol(argv[1], 0, 10);
  if (errno != 0) {
    perror("strtol");
    return EXIT_FAILURE;
  }

  memset(buf, 255, 4096);

  while (req_sz > 0) {
    size_t step = req_sz;
    if (step > 4096)
      step = 4096;
    req_sz -= step;

    if (fwrite(buf, step, 1, stdout) != 1) {
      perror("fwrite");
      return EXIT_FAILURE;
    }
  }

  return EXIT_SUCCESS;
}