summaryrefslogtreecommitdiff
path: root/poppler/StdinCachedFile.cc
blob: db966377bb0fc4e6e1675adec839cc8eace925de (plain)
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
39
40
41
42
43
44
45
46
47
//========================================================================
//
// StdinCachedFile.cc
//
// This file is licensed under the GPLv2 or later
//
// Copyright 2010 Hib Eris <hib@hiberis.nl>
// Copyright 2010 Albert Astals Cid <aacid@kde.org>
// Copyright 2010 Jonathan Liu <net147@gmail.com>
//
//========================================================================

#include <config.h>

#include "StdinCachedFile.h"

#ifdef _WIN32
#include <fcntl.h> // for O_BINARY
#include <io.h>    // for setmode
#endif
#include <stdio.h>

size_t StdinCacheLoader::init(GooString *dummy, CachedFile *cachedFile)
{
  size_t read, size = 0;
  char buf[CachedFileChunkSize];

#ifdef _WIN32
  setmode(fileno(stdin), O_BINARY);
#endif

  CachedFileWriter writer = CachedFileWriter (cachedFile, NULL);
  do {
    read = fread(buf, 1, CachedFileChunkSize, stdin);
    (writer.write) (buf, CachedFileChunkSize);
    size += read;
  }
  while (read == CachedFileChunkSize);

  return size;
}

int StdinCacheLoader::load(const std::vector<ByteRange> &ranges, CachedFileWriter *writer)
{
  return 0;
}