1 // TortoiseSVN - a Windows shell extension for easy version control
\r
3 // Copyright (C) 2003-2006 - Stefan Kueng
\r
5 // This program is free software; you can redistribute it and/or
\r
6 // modify it under the terms of the GNU General Public License
\r
7 // as published by the Free Software Foundation; either version 2
\r
8 // of the License, or (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, write to the Free Software Foundation,
\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
20 #include "StdioFileT.h"
\r
22 CStdioFileT::CStdioFileT() : CStdioFile()
\r
26 CStdioFileT::CStdioFileT(LPCTSTR lpszFileName, UINT nOpenFlags)
\r
28 ASSERT(lpszFileName != NULL);
\r
29 ASSERT(AfxIsValidString(lpszFileName));
\r
32 if (!Open(lpszFileName, nOpenFlags, &e))
\r
33 AfxThrowFileException(e.m_cause, e.m_lOsError, e.m_strFileName);
\r
37 void CStdioFileT::WriteString(LPCSTR lpsz)
\r
39 ASSERT(lpsz != NULL);
\r
40 ASSERT(m_pStream != NULL);
\r
44 AfxThrowInvalidArgException();
\r
47 if (fputs(lpsz, m_pStream) == EOF)
\r
48 AfxThrowFileException(CFileException::diskFull, _doserrno, m_strFileName);
\r
52 void CStdioFileT::WriteString(LPCWSTR lpsz)
\r
54 ASSERT(lpsz != NULL);
\r
55 ASSERT(m_pStream != NULL);
\r
59 AfxThrowInvalidArgException();
\r
62 if (fputws(lpsz, m_pStream) == EOF)
\r
63 AfxThrowFileException(CFileException::diskFull, _doserrno, m_strFileName);
\r
66 BOOL CStdioFileT::ReadString(CStringA& rString)
\r
71 static TCHAR afxChNil = '\0';
\r
74 rString = &afxChNil; // empty string without deallocating
\r
75 const int nMaxSize = 128;
\r
76 LPSTR lpsz = rString.GetBuffer(nMaxSize);
\r
81 lpszResult = fgets(lpsz, nMaxSize+1, m_pStream);
\r
82 rString.ReleaseBuffer();
\r
84 // handle error/eof case
\r
85 if (lpszResult == NULL && !feof(m_pStream))
\r
87 clearerr(m_pStream);
\r
88 AfxThrowFileException(CFileException::genericException, _doserrno,
\r
92 // if string is read completely or EOF
\r
93 if (lpszResult == NULL ||
\r
94 (nLen = (int)strlen(lpsz)) < nMaxSize ||
\r
95 lpsz[nLen-1] == '\n')
\r
98 nLen = rString.GetLength();
\r
99 lpsz = rString.GetBuffer(nMaxSize + nLen) + nLen;
\r
102 // remove '\n' from end of string if present
\r
103 lpsz = rString.GetBuffer(0);
\r
104 nLen = rString.GetLength();
\r
105 if (nLen != 0 && lpsz[nLen-1] == '\n')
\r
106 rString.GetBufferSetLength(nLen-1);
\r
108 return lpszResult != NULL;
\r