Mercurial > hg > svcore
comparison data/fileio/MP3FileReader.cpp @ 231:0031495aba07
...
author | Chris Cannam |
---|---|
date | Mon, 12 Feb 2007 18:15:49 +0000 |
parents | 2854dc429310 |
children | 71dfc6ab3b54 |
comparison
equal
deleted
inserted
replaced
230:2854dc429310 | 231:0031495aba07 |
---|---|
49 } | 49 } |
50 | 50 |
51 m_fileSize = stat.st_size; | 51 m_fileSize = stat.st_size; |
52 | 52 |
53 int fd = -1; | 53 int fd = -1; |
54 if ((fd = ::open(path.toLocal8Bit().data(), O_RDONLY, 0)) < 0) { | 54 if ((fd = ::open(path.toLocal8Bit().data(), O_RDONLY |
55 #ifdef _WIN32 | |
56 | O_BINARY | |
57 #endif | |
58 , 0)) < 0) { | |
55 m_error = QString("Failed to open file %1 for reading.").arg(path); | 59 m_error = QString("Failed to open file %1 for reading.").arg(path); |
56 return; | 60 return; |
57 } | 61 } |
58 | 62 |
59 unsigned char *filebuffer = 0; | 63 unsigned char *filebuffer = 0; |
69 ssize_t sz = 0; | 73 ssize_t sz = 0; |
70 size_t offset = 0; | 74 size_t offset = 0; |
71 while (offset < m_fileSize) { | 75 while (offset < m_fileSize) { |
72 sz = ::read(fd, filebuffer + offset, m_fileSize - offset); | 76 sz = ::read(fd, filebuffer + offset, m_fileSize - offset); |
73 if (sz < 0) { | 77 if (sz < 0) { |
74 m_error = QString("Read error for file %1 (after %2 bytes)").arg(path).arg(offset); | 78 m_error = QString("Read error for file %1 (after %2 bytes)") |
79 .arg(path).arg(offset); | |
75 delete[] filebuffer; | 80 delete[] filebuffer; |
76 ::close(fd); | 81 ::close(fd); |
77 return; | 82 return; |
78 } else if (sz == 0) { | 83 } else if (sz == 0) { |
79 std::cerr << QString("MP3FileReader::MP3FileReader: Warning: read only %1 of %2 bytes").arg(offset).arg(m_fileSize).toStdString() << std::endl; | 84 std::cerr << QString("MP3FileReader::MP3FileReader: Warning: reached EOF after only %1 of %2 bytes") |
85 .arg(offset).arg(m_fileSize).toStdString() << std::endl; | |
86 m_fileSize = offset; | |
80 break; | 87 break; |
81 } | 88 } |
82 offset += sz; | 89 offset += sz; |
83 } | 90 } |
84 | 91 |