File indexing completed on 2025-01-05 04:37:30
0001 /* 0002 SPDX-FileCopyrightText: 2005 Joris Guisson <joris.guisson@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #ifndef BTFILE_H 0007 #define BTFILE_H 0008 0009 #include "constants.h" 0010 #include <QSharedPointer> 0011 #include <ktorrent_export.h> 0012 #include <stdio.h> 0013 0014 namespace bt 0015 { 0016 /** 0017 * @author Joris Guisson 0018 * @brief Wrapper class for stdio's FILE 0019 * 0020 * Wrapper class for stdio's FILE. 0021 */ 0022 class KTORRENT_EXPORT File 0023 { 0024 FILE *fptr; 0025 QString file; 0026 0027 public: 0028 /** 0029 * Constructor. 0030 */ 0031 File(); 0032 0033 /** 0034 * Destructor, closes the file. 0035 */ 0036 virtual ~File(); 0037 0038 /** 0039 * Open the file similar to fopen 0040 * @param file Filename 0041 * @param mode Mode 0042 * @return true upon succes 0043 */ 0044 bool open(const QString &file, const QString &mode); 0045 0046 /** 0047 * Close the file. 0048 */ 0049 void close(); 0050 0051 /** 0052 * Flush the file. 0053 */ 0054 void flush(); 0055 0056 /** 0057 * Write a bunch of data. If anything goes wrong 0058 * an Error will be thrown. 0059 * @param buf The data 0060 * @param size Size of the data 0061 * @return The number of bytes written 0062 */ 0063 Uint32 write(const void *buf, Uint32 size); 0064 0065 /** 0066 * Read a bunch of data. If anything goes wrong 0067 * an Error will be thrown. 0068 * @param buf The buffer to store the data 0069 * @param size Size of the buffer 0070 * @return The number of bytes read 0071 */ 0072 Uint32 read(void *buf, Uint32 size); 0073 0074 enum SeekPos { 0075 BEGIN, 0076 END, 0077 CURRENT, 0078 }; 0079 0080 /** 0081 * Seek in the file. 0082 * @param from Position to seek from 0083 * @param num Number of bytes to move 0084 * @return New position 0085 */ 0086 Uint64 seek(SeekPos from, Int64 num); 0087 0088 /// Check to see if we are at the end of the file. 0089 bool eof() const; 0090 0091 /// Get the current position in the file. 0092 Uint64 tell() const; 0093 0094 /// Get the error string. 0095 QString errorString() const; 0096 0097 typedef QSharedPointer<File> Ptr; 0098 }; 0099 0100 } 0101 0102 #endif