#include <sys/mman.h>
#include <sys/stat.h>
#include <err.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>

static void cat(const char *filename) {
  int fd;
  struct stat st;
  size_t len;
  void *p;

  fd = open(filename, O_RDONLY);
  if (fd < 0) err(EXIT_FAILURE, "open");

  /* get file length */
  if (fstat(fd, &st) < 0) err(EXIT_FAILURE, "fstat");
  len = st.st_size;

  p = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0);
  if (p == MAP_FAILED) err(EXIT_FAILURE, "mmap");

  write(STDOUT_FILENO, p, len);

  munmap(p, len);
}

int main(int argc, char **argv) {
  int i;

  for (i = 1; i < argc; ++i) cat(argv[i]);
  return EXIT_SUCCESS;
}