Coverage Report

Created: 2026-08-13 06:45

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/dng_sdk/source/dng_file_stream.cpp
Line
Count
Source
1
/*****************************************************************************/
2
// Copyright 2006-2007 Adobe Systems Incorporated
3
// All Rights Reserved.
4
//
5
// NOTICE:  Adobe permits you to use, modify, and distribute this file in
6
// accordance with the terms of the Adobe license agreement accompanying it.
7
/*****************************************************************************/
8
9
/* $Id: //mondo/dng_sdk_1_4/dng_sdk/source/dng_file_stream.cpp#2 $ */ 
10
/* $DateTime: 2012/06/01 07:28:57 $ */
11
/* $Change: 832715 $ */
12
/* $Author: tknoll $ */
13
14
/*****************************************************************************/
15
16
#include "dng_file_stream.h"
17
18
#include "dng_exceptions.h"
19
20
/*****************************************************************************/
21
22
dng_file_stream::dng_file_stream (const char *filename,
23
                  bool output,
24
                  uint32 bufferSize)
25
26
185k
  : dng_stream ((dng_abort_sniffer *) NULL,
27
185k
          bufferSize,
28
185k
          0)
29
  
30
185k
  , fFile (NULL)
31
  
32
185k
  {
33
  
34
185k
  fFile = fopen (filename, output ? "wb" : "rb");
35
  
36
185k
  if (!fFile)
37
0
    {
38
    
39
    #if qDNGValidate
40
41
    ReportError ("Unable to open file",
42
           filename);
43
           
44
    ThrowSilentError ();
45
    
46
    #else
47
    
48
0
    ThrowOpenFile ();
49
    
50
0
    #endif
51
52
0
    }
53
  
54
185k
  }
55
    
56
/*****************************************************************************/
57
58
dng_file_stream::~dng_file_stream ()
59
185k
  {
60
  
61
185k
  if (fFile)
62
185k
    {
63
185k
    fclose (fFile);
64
185k
    fFile = NULL;
65
185k
    }
66
  
67
185k
  }
68
    
69
/*****************************************************************************/
70
71
uint64 dng_file_stream::DoGetLength ()
72
171k
  {
73
  
74
171k
  if (fseek (fFile, 0, SEEK_END) != 0)
75
0
    {
76
    
77
0
    ThrowReadFile ();
78
79
0
    }
80
  
81
171k
  return (uint64) ftell (fFile);
82
  
83
171k
  }
84
    
85
/*****************************************************************************/
86
87
void dng_file_stream::DoRead (void *data,
88
                uint32 count,
89
                uint64 offset)
90
14.2M
  {
91
  
92
14.2M
  if (fseek (fFile, (long) offset, SEEK_SET) != 0)
93
0
    {
94
    
95
0
    ThrowReadFile ();
96
97
0
    }
98
  
99
14.2M
  uint32 bytesRead = (uint32) fread (data, 1, count, fFile);
100
  
101
14.2M
  if (bytesRead != count)
102
0
    {
103
    
104
0
    ThrowReadFile ();
105
106
0
    }
107
  
108
14.2M
  }
109
    
110
/*****************************************************************************/
111
112
void dng_file_stream::DoWrite (const void *data,
113
                 uint32 count,
114
                 uint64 offset)
115
472k
  {
116
  
117
472k
  if (fseek (fFile, (uint32) offset, SEEK_SET) != 0)
118
0
    {
119
    
120
0
    ThrowWriteFile ();
121
122
0
    }
123
  
124
472k
  uint32 bytesWritten = (uint32) fwrite (data, 1, count, fFile);
125
  
126
472k
  if (bytesWritten != count)
127
0
    {
128
    
129
0
    ThrowWriteFile ();
130
131
0
    }
132
  
133
472k
  }
134
    
135
/*****************************************************************************/