Upstream version 5.34.92.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 namespace libwebvtt {
12
13 VttReader::VttReader() : file_(NULL) {
14 }
15
16 VttReader::~VttReader() {
17   Close();
18 }
19
20 int VttReader::Open(const char* filename) {
21   if (filename == NULL || file_ != NULL)
22     return -1;
23
24   file_ = fopen(filename, "rb");
25   if (file_ == NULL)
26     return -1;
27
28   return 0;  // success
29 }
30
31 void VttReader::Close() {
32   if (file_) {
33     fclose(file_);
34     file_ = NULL;
35   }
36 }
37
38 int VttReader::GetChar(char* c) {
39   if (c == NULL || file_ == NULL)
40     return -1;
41
42   const int result = fgetc(file_);
43   if (result != EOF) {
44     *c = static_cast<char>(result);
45     return 0;  // success
46   }
47
48   if (ferror(file_))
49     return -1;  // error
50
51   if (feof(file_))
52     return 1;  // EOF
53
54   return -1;  // weird
55 }
56
57 }  // namespace libwebvtt