1affc150dc44fab1911775a49636d0ce85333b634Zonr Chang//===- FileHandle.cpp -----------------------------------------------------===//
2affc150dc44fab1911775a49636d0ce85333b634Zonr Chang//
3affc150dc44fab1911775a49636d0ce85333b634Zonr Chang//                     The MCLinker Project
4affc150dc44fab1911775a49636d0ce85333b634Zonr Chang//
5affc150dc44fab1911775a49636d0ce85333b634Zonr Chang// This file is distributed under the University of Illinois Open Source
6affc150dc44fab1911775a49636d0ce85333b634Zonr Chang// License. See LICENSE.TXT for details.
7affc150dc44fab1911775a49636d0ce85333b634Zonr Chang//
8affc150dc44fab1911775a49636d0ce85333b634Zonr Chang//===----------------------------------------------------------------------===//
96f75755c9204b1d8817ae5a65a2f7e5af0ec3f70Stephen Hines#include "mcld/Config/Config.h"
10affc150dc44fab1911775a49636d0ce85333b634Zonr Chang#include <mcld/Support/FileHandle.h>
11affc150dc44fab1911775a49636d0ce85333b634Zonr Chang#include <mcld/Support/FileSystem.h>
12affc150dc44fab1911775a49636d0ce85333b634Zonr Chang#include <errno.h>
1322add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
1422add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao#if defined(HAVE_UNISTD_H)
1522add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao# include <unistd.h>
1622add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao#endif
1722add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao#if defined(HAVE_FCNTL_H)
1822add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao# include <fcntl.h>
1922add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao#endif
2022add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
21affc150dc44fab1911775a49636d0ce85333b634Zonr Chang#include <sys/stat.h>
2222add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
23affc150dc44fab1911775a49636d0ce85333b634Zonr Changusing namespace mcld;
24affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
25affc150dc44fab1911775a49636d0ce85333b634Zonr Chang//===----------------------------------------------------------------------===//
26affc150dc44fab1911775a49636d0ce85333b634Zonr Chang// FileHandle
27f7ac0f19a1c8d0ad14bcf6456ce368b830fea886Stephen Hines//===----------------------------------------------------------------------===//
28affc150dc44fab1911775a49636d0ce85333b634Zonr ChangFileHandle::FileHandle()
29affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  : m_Path(),
30affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    m_Handler(-1),
31affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    m_Size(0),
32affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    m_State(GoodBit),
33affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    m_OpenMode(NotOpen) {
34affc150dc44fab1911775a49636d0ce85333b634Zonr Chang}
35affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
36affc150dc44fab1911775a49636d0ce85333b634Zonr ChangFileHandle::~FileHandle()
37affc150dc44fab1911775a49636d0ce85333b634Zonr Chang{
38affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  if (isOpened())
39affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    close();
40affc150dc44fab1911775a49636d0ce85333b634Zonr Chang}
41affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
42affc150dc44fab1911775a49636d0ce85333b634Zonr Changinline static int oflag(FileHandle::OpenMode pMode)
43affc150dc44fab1911775a49636d0ce85333b634Zonr Chang{
44affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  int result = 0x0;
45affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  if (FileHandle::Unknown == pMode)
46affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    return result;
47affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
48affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  if (FileHandle::ReadWrite == (pMode & FileHandle::ReadWrite))
49affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    result |= O_RDWR;
5022add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  else if (FileHandle::ReadOnly == (pMode & FileHandle::ReadOnly))
51affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    result |= O_RDONLY;
5222add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  else if (FileHandle::WriteOnly == (pMode & FileHandle::WriteOnly))
53affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    result |= O_WRONLY;
54affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
5522add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  if (FileHandle::Append == (pMode & FileHandle::Append))
56affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    result |= O_APPEND;
57affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
5822add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  if (FileHandle::Create == (pMode & FileHandle::Create))
59affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    result |= O_CREAT;
60affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
6122add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  if (FileHandle::Truncate == (pMode & FileHandle::Truncate))
62affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    result |= O_TRUNC;
63affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
64affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  return result;
65affc150dc44fab1911775a49636d0ce85333b634Zonr Chang}
66affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
67affc150dc44fab1911775a49636d0ce85333b634Zonr Changinline static bool get_size(int pHandler, unsigned int &pSize)
68affc150dc44fab1911775a49636d0ce85333b634Zonr Chang{
69affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  struct ::stat file_stat;
70affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  if (-1 == ::fstat(pHandler, &file_stat)) {
71affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    pSize = 0;
72affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    return false;
73affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  }
74affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  pSize = file_stat.st_size;
75affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  return true;
76affc150dc44fab1911775a49636d0ce85333b634Zonr Chang}
77affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
78affc150dc44fab1911775a49636d0ce85333b634Zonr Changbool FileHandle::open(const sys::fs::Path& pPath,
79affc150dc44fab1911775a49636d0ce85333b634Zonr Chang                      FileHandle::OpenMode pMode,
80affc150dc44fab1911775a49636d0ce85333b634Zonr Chang                      FileHandle::Permission pPerm)
81affc150dc44fab1911775a49636d0ce85333b634Zonr Chang{
82affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  if (isOpened() || Unknown == pMode) {
83affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    setState(BadBit);
84affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    return false;
85affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  }
86affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
87affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  m_OpenMode = pMode;
8822add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  if (System == pPerm)
8922add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao    m_Handler = sys::fs::detail::open(pPath, oflag(pMode));
9022add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao  else
9122add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao    m_Handler = sys::fs::detail::open(pPath, oflag(pMode), (int)pPerm);
9222add6ff3426df1a85089fe6a6e1597ee3b6f300Shih-wei Liao
93affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  m_Path = pPath;
94affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  if (-1 == m_Handler) {
95affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    m_OpenMode = NotOpen;
96affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    setState(FailBit);
97affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    return false;
98affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  }
99affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
100affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  if (!get_size(m_Handler, m_Size)) {
101affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    setState(FailBit);
102affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    return false;
103affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  }
104affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
105affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  return true;
106affc150dc44fab1911775a49636d0ce85333b634Zonr Chang}
107affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
108affc150dc44fab1911775a49636d0ce85333b634Zonr Changbool FileHandle::delegate(int pFD, FileHandle::OpenMode pMode)
109affc150dc44fab1911775a49636d0ce85333b634Zonr Chang{
110affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  if (isOpened()) {
111affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    setState(BadBit);
112affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    return false;
113affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  }
114affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
115affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  m_Handler = pFD;
116affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  m_OpenMode = pMode;
1176f75755c9204b1d8817ae5a65a2f7e5af0ec3f70Stephen Hines  m_State = (GoodBit | DeputedBit);
118affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
119affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  if (!get_size(m_Handler, m_Size)) {
120affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    setState(FailBit);
121affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    return false;
122affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  }
123affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
124affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  return true;
125affc150dc44fab1911775a49636d0ce85333b634Zonr Chang}
126affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
127affc150dc44fab1911775a49636d0ce85333b634Zonr Changbool FileHandle::close()
128affc150dc44fab1911775a49636d0ce85333b634Zonr Chang{
129affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  if (!isOpened()) {
130affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    setState(BadBit);
131affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    return false;
132affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  }
133affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
1346f75755c9204b1d8817ae5a65a2f7e5af0ec3f70Stephen Hines  if (isOwned()) {
1356f75755c9204b1d8817ae5a65a2f7e5af0ec3f70Stephen Hines    if (-1 == ::close(m_Handler)) {
1366f75755c9204b1d8817ae5a65a2f7e5af0ec3f70Stephen Hines      setState(FailBit);
1376f75755c9204b1d8817ae5a65a2f7e5af0ec3f70Stephen Hines      return false;
1386f75755c9204b1d8817ae5a65a2f7e5af0ec3f70Stephen Hines    }
139affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  }
140affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
141affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  m_Path.native().clear();
142affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  m_Size = 0;
143affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  m_OpenMode = NotOpen;
144affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  cleanState();
145affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  return true;
146affc150dc44fab1911775a49636d0ce85333b634Zonr Chang}
147affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
148affc150dc44fab1911775a49636d0ce85333b634Zonr Changbool FileHandle::truncate(size_t pSize)
149affc150dc44fab1911775a49636d0ce85333b634Zonr Chang{
150affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  if (!isOpened() || !isWritable()) {
151affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    setState(BadBit);
152affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    return false;
153affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  }
154affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
155affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  if (-1 == sys::fs::detail::ftruncate(m_Handler, pSize)) {
156affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    setState(FailBit);
157affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    return false;
158affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  }
159affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
160affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  m_Size = pSize;
161affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  return true;
162affc150dc44fab1911775a49636d0ce85333b634Zonr Chang}
163affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
164affc150dc44fab1911775a49636d0ce85333b634Zonr Changbool FileHandle::read(void* pMemBuffer, size_t pStartOffset, size_t pLength)
165affc150dc44fab1911775a49636d0ce85333b634Zonr Chang{
166affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  if (!isOpened() || !isReadable()) {
167affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    setState(BadBit);
168affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    return false;
169affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  }
170affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
171affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  if (0 == pLength)
172affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    return true;
173affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
174affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  ssize_t read_bytes = sys::fs::detail::pread(m_Handler,
175affc150dc44fab1911775a49636d0ce85333b634Zonr Chang                                              pMemBuffer,
176affc150dc44fab1911775a49636d0ce85333b634Zonr Chang                                              pLength,
177affc150dc44fab1911775a49636d0ce85333b634Zonr Chang                                              pStartOffset);
178affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
179affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  if (-1 == read_bytes) {
180affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    setState(FailBit);
181affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    return false;
182affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  }
183affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
184affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  return true;
185affc150dc44fab1911775a49636d0ce85333b634Zonr Chang}
186affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
187affc150dc44fab1911775a49636d0ce85333b634Zonr Changbool FileHandle::write(const void* pMemBuffer, size_t pStartOffset, size_t pLength)
188affc150dc44fab1911775a49636d0ce85333b634Zonr Chang{
189affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  if (!isOpened() || !isWritable()) {
190affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    setState(BadBit);
191affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    return false;
192affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  }
193affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
194affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  if (0 == pLength)
195affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    return true;
196affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
197affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
198affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  ssize_t write_bytes = sys::fs::detail::pwrite(m_Handler,
199affc150dc44fab1911775a49636d0ce85333b634Zonr Chang                                                pMemBuffer,
200affc150dc44fab1911775a49636d0ce85333b634Zonr Chang                                                pLength,
201affc150dc44fab1911775a49636d0ce85333b634Zonr Chang                                                pStartOffset);
202affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
203affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  if (-1 == write_bytes) {
204affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    setState(FailBit);
205affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    return false;
206affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  }
207affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
208affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  return true;
209affc150dc44fab1911775a49636d0ce85333b634Zonr Chang}
210affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
211affc150dc44fab1911775a49636d0ce85333b634Zonr Changvoid FileHandle::setState(FileHandle::IOState pState)
212affc150dc44fab1911775a49636d0ce85333b634Zonr Chang{
213affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  m_State |= pState;
214affc150dc44fab1911775a49636d0ce85333b634Zonr Chang}
215affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
216affc150dc44fab1911775a49636d0ce85333b634Zonr Changvoid FileHandle::cleanState(FileHandle::IOState pState)
217affc150dc44fab1911775a49636d0ce85333b634Zonr Chang{
218affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  m_State = pState;
219affc150dc44fab1911775a49636d0ce85333b634Zonr Chang}
220affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
221affc150dc44fab1911775a49636d0ce85333b634Zonr Changbool FileHandle::isOpened() const
222affc150dc44fab1911775a49636d0ce85333b634Zonr Chang{
223affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  if (-1 != m_Handler && m_OpenMode != NotOpen && isGood())
224affc150dc44fab1911775a49636d0ce85333b634Zonr Chang    return true;
225affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
226affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  return false;
227affc150dc44fab1911775a49636d0ce85333b634Zonr Chang}
228affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
229affc150dc44fab1911775a49636d0ce85333b634Zonr Chang// Assume Unknown OpenMode is readable
230affc150dc44fab1911775a49636d0ce85333b634Zonr Changbool FileHandle::isReadable() const
231affc150dc44fab1911775a49636d0ce85333b634Zonr Chang{
232affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  return (m_OpenMode & ReadOnly);
233affc150dc44fab1911775a49636d0ce85333b634Zonr Chang}
234affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
235affc150dc44fab1911775a49636d0ce85333b634Zonr Chang// Assume Unknown OpenMode is writable
236affc150dc44fab1911775a49636d0ce85333b634Zonr Changbool FileHandle::isWritable() const
237affc150dc44fab1911775a49636d0ce85333b634Zonr Chang{
238affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  return (m_OpenMode & WriteOnly);
239affc150dc44fab1911775a49636d0ce85333b634Zonr Chang}
240affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
241affc150dc44fab1911775a49636d0ce85333b634Zonr Chang// Assume Unknown OpenMode is both readable and writable
242affc150dc44fab1911775a49636d0ce85333b634Zonr Changbool FileHandle::isReadWrite() const
243affc150dc44fab1911775a49636d0ce85333b634Zonr Chang{
244affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  return (FileHandle::ReadWrite == (m_OpenMode & FileHandle::ReadWrite));
245affc150dc44fab1911775a49636d0ce85333b634Zonr Chang}
246affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
247affc150dc44fab1911775a49636d0ce85333b634Zonr Changbool FileHandle::isGood() const
248affc150dc44fab1911775a49636d0ce85333b634Zonr Chang{
249affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  return !(m_State & (BadBit | FailBit));
250affc150dc44fab1911775a49636d0ce85333b634Zonr Chang}
251affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
252affc150dc44fab1911775a49636d0ce85333b634Zonr Changbool FileHandle::isBad() const
253affc150dc44fab1911775a49636d0ce85333b634Zonr Chang{
254affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  return (m_State & BadBit);
255affc150dc44fab1911775a49636d0ce85333b634Zonr Chang}
256affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
257affc150dc44fab1911775a49636d0ce85333b634Zonr Changbool FileHandle::isFailed() const
258affc150dc44fab1911775a49636d0ce85333b634Zonr Chang{
259affc150dc44fab1911775a49636d0ce85333b634Zonr Chang  return (m_State & (BadBit | FailBit));
260affc150dc44fab1911775a49636d0ce85333b634Zonr Chang}
261affc150dc44fab1911775a49636d0ce85333b634Zonr Chang
2626f75755c9204b1d8817ae5a65a2f7e5af0ec3f70Stephen Hinesbool FileHandle::isOwned() const
2636f75755c9204b1d8817ae5a65a2f7e5af0ec3f70Stephen Hines{
2646f75755c9204b1d8817ae5a65a2f7e5af0ec3f70Stephen Hines  return !(m_State & DeputedBit);
2656f75755c9204b1d8817ae5a65a2f7e5af0ec3f70Stephen Hines}
2666f75755c9204b1d8817ae5a65a2f7e5af0ec3f70Stephen Hines
267