forked from quickshell/quickshell
		
	io/fileview: support zero-sized files (/proc)
This commit is contained in:
		
							parent
							
								
									0dd19d4a18
								
							
						
					
					
						commit
						60dfa67ec7
					
				
					 1 changed files with 27 additions and 11 deletions
				
			
		| 
						 | 
				
			
			@ -1,4 +1,5 @@
 | 
			
		|||
#include "fileview.hpp"
 | 
			
		||||
#include <array>
 | 
			
		||||
#include <utility>
 | 
			
		||||
 | 
			
		||||
#include <qfileinfo.h>
 | 
			
		||||
| 
						 | 
				
			
			@ -68,8 +69,8 @@ void FileViewReader::read(FileViewState& state, bool doStringConversion) {
 | 
			
		|||
		}
 | 
			
		||||
 | 
			
		||||
		auto& data = state.data;
 | 
			
		||||
		if (file.size() != 0) {
 | 
			
		||||
			data = QByteArray(file.size(), Qt::Uninitialized);
 | 
			
		||||
 | 
			
		||||
			qint64 i = 0;
 | 
			
		||||
 | 
			
		||||
			while (true) {
 | 
			
		||||
| 
						 | 
				
			
			@ -85,6 +86,21 @@ void FileViewReader::read(FileViewState& state, bool doStringConversion) {
 | 
			
		|||
 | 
			
		||||
				i += r;
 | 
			
		||||
			}
 | 
			
		||||
		} else {
 | 
			
		||||
			auto buf = std::array<char, 4096>();
 | 
			
		||||
 | 
			
		||||
			while (true) {
 | 
			
		||||
				auto r = file.read(buf.data(), buf.size()); // NOLINT
 | 
			
		||||
 | 
			
		||||
				if (r == -1) {
 | 
			
		||||
					qCCritical(logFileView) << "Failed to read" << state.path;
 | 
			
		||||
					goto error;
 | 
			
		||||
				} else {
 | 
			
		||||
					data.append(buf.data(), r);
 | 
			
		||||
					if (r == 0) break;
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (doStringConversion) {
 | 
			
		||||
			state.text = QString::fromUtf8(state.data);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue