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