StdinCachedFile.cc 1.07 KB
Newer Older
1 2 3 4 5 6 7
//========================================================================
//
// StdinCachedFile.cc
//
// This file is licensed under the GPLv2 or later
//
// Copyright 2010 Hib Eris <hib@hiberis.nl>
8
// Copyright 2010 Albert Astals Cid <aacid@kde.org>
9
// Copyright 2010 Jonathan Liu <net147@gmail.com>
10 11 12 13 14 15 16
//
//========================================================================

#include <config.h>

#include "StdinCachedFile.h"

17 18 19 20
#ifdef _WIN32
#include <fcntl.h> // for O_BINARY
#include <io.h>    // for setmode
#endif
21 22 23 24 25 26 27
#include <stdio.h>

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

28
#ifdef _WIN32
29 30 31
  setmode(fileno(stdin), O_BINARY);
#endif

32
  CachedFileWriter writer = CachedFileWriter (cachedFile, nullptr);
33 34 35 36 37 38 39 40 41 42
  do {
    read = fread(buf, 1, CachedFileChunkSize, stdin);
    (writer.write) (buf, CachedFileChunkSize);
    size += read;
  }
  while (read == CachedFileChunkSize);

  return size;
}

Albert Astals Cid's avatar
Albert Astals Cid committed
43
int StdinCacheLoader::load(const std::vector<ByteRange> &ranges, CachedFileWriter *writer)
44 45 46 47
{
  return 0;
}