[windows] Fix MAC Address Discovery
[xbmc.git] / xbmc / filesystem / UDFFile.cpp
blobf4c5d5b6138d567cb368f7fe759b87bccc860ad4
1 /*
2 * Copyright (C) 2005-2018 Team Kodi
3 * This file is part of Kodi - https://kodi.tv
5 * SPDX-License-Identifier: GPL-2.0-or-later
6 * See LICENSES/README.md for more information.
7 */
9 #include "UDFFile.h"
11 #include "URL.h"
13 #include <udfread/udfread.h>
15 using namespace XFILE;
17 CUDFFile::CUDFFile() : m_bi{std::make_unique<CUDFBlockInput>()}
21 bool CUDFFile::Open(const CURL& url)
23 if (m_udf && m_file)
24 return true;
26 m_udf = udfread_init();
28 if (!m_udf)
29 return false;
31 auto bi = m_bi->GetBlockInput(url.GetHostName());
33 if (!bi)
35 udfread_close(m_udf);
36 return false;
39 if (udfread_open_input(m_udf, bi) < 0)
41 bi->close(bi);
42 udfread_close(m_udf);
43 return false;
46 m_file = udfread_file_open(m_udf, url.GetFileName().c_str());
47 if (!m_file)
49 Close();
50 return false;
53 return true;
56 void CUDFFile::Close()
58 if (m_file)
60 udfread_file_close(m_file);
61 m_file = nullptr;
64 if (m_udf)
66 udfread_close(m_udf);
67 m_udf = nullptr;
71 int CUDFFile::Stat(const CURL& url, struct __stat64* buffer)
73 if (!m_udf || !m_file || !buffer)
74 return -1;
76 *buffer = {};
77 buffer->st_size = GetLength();
79 return 0;
82 ssize_t CUDFFile::Read(void* buffer, size_t size)
84 return udfread_file_read(m_file, buffer, size);
87 int64_t CUDFFile::Seek(int64_t filePosition, int whence)
89 return udfread_file_seek(m_file, filePosition, whence);
92 int64_t CUDFFile::GetLength()
94 return udfread_file_size(m_file);
97 int64_t CUDFFile::GetPosition()
99 return udfread_file_tell(m_file);
102 bool CUDFFile::Exists(const CURL& url)
104 return Open(url);