Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / libwebm / source / vttreader.cc
1 // Copyright (c) 2012 The WebM project authors. All Rights Reserved.
2 //
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the LICENSE file in the root of the source
5 // tree. An additional intellectual property rights grant can be found
6 // in the file PATENTS.  All contributing project authors may
7 // be found in the AUTHORS file in the root of the source tree.
8
9 #include "./vttreader.h"  // NOLINT
10
11 #ifdef _MSC_VER
12 // Disable MSVC warnings that suggest making code non-portable.
13 #pragma warning(disable:4996)
14 #endif
15
16 namespace libwebvtt {
17
18 VttReader::VttReader() : file_(NULL) {
19 }
20
21 VttReader::~VttReader() {
22   Close();
23 }
24
25 int VttReader::Open(const char* filename) {
26   if (filename == NULL || file_ != NULL)
27     return -1;
28
29   file_ = fopen(filename, "rb");
30   if (file_ == NULL)
31     return -1;
32
33   return 0;  // success
34 }
35
36 void VttReader::Close() {
37   if (file_) {
38     fclose(file_);
39     file_ = NULL;
40   }
41 }
42
43 int VttReader::GetChar(char* c) {
44   if (c == NULL || file_ == NULL)
45     return -1;
46
47   const int result = fgetc(file_);
48   if (result != EOF) {
49     *c = static_cast<char>(result);
50     return 0;  // success
51   }
52
53   if (ferror(file_))
54     return -1;  // error
55
56   if (feof(file_))
57     return 1;  // EOF
58
59   return -1;  // weird
60 }
61
62 }  // namespace libwebvtt