Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: third_party/lzma/v4_65/files/CPP/Common/StdInStream.cpp

Issue 624713003: Keep only base/extractor.[cc|h]. (Closed) Base URL: https://chromium.googlesource.com/external/omaha.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Common/StdInStream.cpp
2
3 #include "StdAfx.h"
4
5 #include <tchar.h>
6 #include "StdInStream.h"
7
8 #ifdef _MSC_VER
9 // "was declared deprecated" disabling
10 #pragma warning(disable : 4996 )
11 #endif
12
13 static const char kIllegalChar = '\0';
14 static const char kNewLineChar = '\n';
15
16 static const char *kEOFMessage = "Unexpected end of input stream";
17 static const char *kReadErrorMessage ="Error reading input stream";
18 static const char *kIllegalCharMessage = "Illegal character in input stream";
19
20 static LPCTSTR kFileOpenMode = TEXT("r");
21
22 CStdInStream g_StdIn(stdin);
23
24 bool CStdInStream::Open(LPCTSTR fileName)
25 {
26 Close();
27 _stream = _tfopen(fileName, kFileOpenMode);
28 _streamIsOpen = (_stream != 0);
29 return _streamIsOpen;
30 }
31
32 bool CStdInStream::Close()
33 {
34 if (!_streamIsOpen)
35 return true;
36 _streamIsOpen = (fclose(_stream) != 0);
37 return !_streamIsOpen;
38 }
39
40 CStdInStream::~CStdInStream()
41 {
42 Close();
43 }
44
45 AString CStdInStream::ScanStringUntilNewLine()
46 {
47 AString s;
48 for (;;)
49 {
50 int intChar = GetChar();
51 if (intChar == EOF)
52 throw kEOFMessage;
53 char c = char(intChar);
54 if (c == kIllegalChar)
55 throw kIllegalCharMessage;
56 if (c == kNewLineChar)
57 break;
58 s += c;
59 }
60 return s;
61 }
62
63 void CStdInStream::ReadToString(AString &resultString)
64 {
65 resultString.Empty();
66 int c;
67 while ((c = GetChar()) != EOF)
68 resultString += char(c);
69 }
70
71 bool CStdInStream::Eof()
72 {
73 return (feof(_stream) != 0);
74 }
75
76 int CStdInStream::GetChar()
77 {
78 int c = fgetc(_stream); // getc() doesn't work in BeOS?
79 if (c == EOF && !Eof())
80 throw kReadErrorMessage;
81 return c;
82 }
83
84
OLDNEW
« no previous file with comments | « third_party/lzma/v4_65/files/CPP/Common/StdInStream.h ('k') | third_party/lzma/v4_65/files/CPP/Common/StdOutStream.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698