Switch to unified view

a/src/bincimapmime/mime-inputsource.h b/src/bincimapmime/mime-inputsource.h
...
...
23
 *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
23
 *  Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
24
 *  --------------------------------------------------------------------
24
 *  --------------------------------------------------------------------
25
 */
25
 */
26
#ifndef mime_inputsource_h_included
26
#ifndef mime_inputsource_h_included
27
#define mime_inputsource_h_included
27
#define mime_inputsource_h_included
28
28
#include "autoconfig.h"
29
// Data source for MIME parser
29
// Data source for MIME parser
30
30
31
// Note about large files: we might want to change the unsigned int
31
// Note about large files: we might want to change the unsigned int
32
// used for offsets into an off_t for intellectual satisfaction, but
32
// used for offsets into an off_t for intellectual satisfaction, but
33
// in the context of recoll, we could only get into trouble if a
33
// in the context of recoll, we could only get into trouble if a
...
...
47
  public:
47
  public:
48
    // Note that we do NOT take ownership of fd, won't close it on delete
48
    // Note that we do NOT take ownership of fd, won't close it on delete
49
    inline MimeInputSource(int fd, unsigned int start = 0);
49
    inline MimeInputSource(int fd, unsigned int start = 0);
50
    virtual inline ~MimeInputSource(void);
50
    virtual inline ~MimeInputSource(void);
51
51
52
    virtual inline size_t fillRaw(char *raw, size_t nbytes);
52
    virtual inline ssize_t fillRaw(char *raw, size_t nbytes);
53
    virtual inline void reset(void);
53
    virtual inline void reset(void);
54
54
55
    virtual inline bool fillInputBuffer(void);
55
    virtual inline bool fillInputBuffer(void);
56
    inline void seek(unsigned int offset);
56
    inline void seek(unsigned int offset);
57
    inline bool getChar(char *c);
57
    inline bool getChar(char *c);
...
...
85
85
86
  inline MimeInputSource::~MimeInputSource(void)
86
  inline MimeInputSource::~MimeInputSource(void)
87
  {
87
  {
88
  }
88
  }
89
89
90
  inline size_t MimeInputSource::fillRaw(char *raw, size_t nbytes)
90
  inline ssize_t MimeInputSource::fillRaw(char *raw, size_t nbytes)
91
  {
91
  {
92
      return read(fd, raw, nbytes);
92
      return read(fd, raw, nbytes);
93
  }
93
  }
94
94
95
  inline bool MimeInputSource::fillInputBuffer(void)
95
  inline bool MimeInputSource::fillInputBuffer(void)
...
...
177
177
178
    ///////////////////////////////////
178
    ///////////////////////////////////
179
    class MimeInputSourceStream : public MimeInputSource {
179
    class MimeInputSourceStream : public MimeInputSource {
180
  public:
180
  public:
181
    inline MimeInputSourceStream(istream& s, unsigned int start = 0);
181
    inline MimeInputSourceStream(istream& s, unsigned int start = 0);
182
    virtual inline size_t fillRaw(char *raw, size_t nb);
182
    virtual inline ssize_t fillRaw(char *raw, size_t nb);
183
    virtual inline void reset(void);
183
    virtual inline void reset(void);
184
  private:
184
  private:
185
      istream& s;
185
      istream& s;
186
  };
186
  };
187
187
...
...
189
                              unsigned int start)
189
                              unsigned int start)
190
      : MimeInputSource(-1, start), s(si)
190
      : MimeInputSource(-1, start), s(si)
191
  {
191
  {
192
  }
192
  }
193
193
194
  inline size_t MimeInputSourceStream::fillRaw(char *raw, size_t nb)
194
  inline ssize_t MimeInputSourceStream::fillRaw(char *raw, size_t nb)
195
  {
195
  {
196
    // Why can't streams tell how many characters were actually read
196
    // Why can't streams tell how many characters were actually read
197
    // when hitting eof ?
197
    // when hitting eof ?
198
    std::streampos st = s.tellg();
198
    std::streampos st = s.tellg();
199
    s.seekg(0, ios::end);
199
    s.seekg(0, ios::end);
200
    std::streampos lst = s.tellg();
200
    std::streampos lst = s.tellg();
201
    s.seekg(st);
201
    s.seekg(st);
202
    size_t nbytes = lst - st;
202
    size_t nbytes = size_t(lst - st);
203
    if (nbytes > nb) {
203
    if (nbytes > nb) {
204
    nbytes = nb;
204
    nbytes = nb;
205
    }
205
    }
206
    if (nbytes <= 0) {
206
    if (nbytes <= 0) {
207
    return (size_t)-1;
207
    return (ssize_t)-1;
208
    }
208
    }
209
209
210
    s.read(raw, nbytes);
210
    s.read(raw, nbytes);
211
    return nbytes;
211
    return static_cast<ssize_t>(nbytes);
212
  }
212
  }
213
213
214
  inline void MimeInputSourceStream::reset(void)
214
  inline void MimeInputSourceStream::reset(void)
215
  {
215
  {
216
      MimeInputSource::reset();
216
      MimeInputSource::reset();