source: trunk/pin/include/buffers.ch@ 25

Last change on this file since 25 was 1, checked in by bart, 18 years ago

Initial checkin of PIN.EXE source code
this contains memory fixes for larger PPD files

File size: 2.7 KB
Line 
1// included into convert.c
2// input file caching (buffering)
3// this is very important for speed, allows for major gain
4
5// @V4.CACHE Begin
6
7/*****************************************************************************\
8**
9** FUNCTION = fbseek
10**
11** DESCRIPTION = Simulates fseek for file buffer
12**
13\*****************************************************************************/
14
15long fbseek(PFILEBUFFER pfb, long offset, INT origin)
16{
17 long lCurPos;
18
19 if( !pfb->pbBuffer || !pfb->fhFile )
20 return TRUE;
21
22 lCurPos = pfb->lCurPos;
23
24 switch(origin)
25 {
26 case SEEK_SET:
27 lCurPos = offset;
28 break;
29 case SEEK_CUR:
30 lCurPos += offset;
31 break;
32 case SEEK_END:
33 lCurPos = pfb->lFileLen + offset;
34 break;
35 default:
36 return TRUE;
37 }
38 if( lCurPos>=0 && lCurPos<=pfb->lFileLen )
39 {
40 pfb->lCurPos = lCurPos;
41 return FALSE;
42 }
43 else
44 return TRUE;
45}
46
47/*****************************************************************************\
48**
49** FUNCTION = fbtell
50**
51** DESCRIPTION = Simulates ftell for file buffer
52**
53\*****************************************************************************/
54
55long fbtell(PFILEBUFFER pfb)
56{
57 if( !pfb->pbBuffer || !pfb->fhFile )
58 return -1;
59
60 if( pfb->lCurPos>=0 && pfb->lCurPos < pfb->lFileLen )
61 return pfb->lCurPos;
62 else
63 return -1;
64}
65
66/*****************************************************************************\
67**
68** FUNCTION = fbread
69**
70** DESCRIPTION = Simulates fread for file buffer
71**
72\*****************************************************************************/
73
74long fbread(void *buff, long size, long count, PFILEBUFFER pfb)
75{
76 long lRealCount;
77
78 if( !pfb->pbBuffer || !pfb->fhFile )
79 return 0;
80 if( size<=0 || count<=0)
81 return 0;
82
83 if( pfb->lCurPos>=0 && pfb->lCurPos < pfb->lFileLen )
84 {
85 if( pfb->lCurPos+size*count>pfb->lFileLen )
86 lRealCount = (pfb->lFileLen - pfb->lCurPos)/size;
87 else
88 lRealCount = count;
89
90 memcpy(buff, pfb->pbBuffer+pfb->lCurPos, lRealCount*size );
91 pfb->lCurPos += lRealCount*size;
92
93 return lRealCount;
94 }
95 else
96 return 0;
97}
98
99/*****************************************************************************\
100**
101** FUNCTION = fbclose
102**
103** DESCRIPTION = Simulates fbclose for file buffer
104**
105\*****************************************************************************/
106
107long fbclose(PFILEBUFFER pfb)
108{
109 if( pfb->pbBuffer && pfb->fhFile )
110 {
111 fclose(pfb->fhFile);
112 free(pfb->pbBuffer);
113 memset( pfb, 0, sizeof( FILEBUFFER ) );
114
115 return 0;
116 }
117 else
118 return -1;
119}
120
121// @V4.CACHE End
122
Note: See TracBrowser for help on using the repository browser.