Current News
Archived News
Search News
Discussion Forum


Old Forum
Install Programs More Downloads...
Troubleshooting
Source Code
Format Specs.
Misc. Information
Non-SF Stuff
Links




CommitLineData
7214af3e 1// License information for this code is in license.txt
2
3#include <windows.h>
4#include <stdlib.h>
5#include "SFTypes.h"
6
7void WINAPI SFMemZero(LPVOID lpvDestination, DWORD dwLength)
8{
9 DWORD dwPrevLen = dwLength;
10 LPDWORD lpdwDestination = (LPDWORD)lpvDestination;
11 LPBYTE lpbyDestination;
12
13 dwLength >>= 2;
14
15 while (dwLength--)
16 *lpdwDestination++ = 0;
17
18 lpbyDestination = (LPBYTE)lpdwDestination;
19
20 dwLength = dwPrevLen;
21 dwLength &= 3;
22
23 while (dwLength--)
24 *lpbyDestination++ = 0;
25}
26
27LPVOID WINAPI SFAlloc(DWORD dwSize)
28{
29 LPVOID lpMemory = malloc(dwSize);
30 if (lpMemory) SFMemZero(lpMemory,dwSize);
31 return lpMemory;
32}
33
34void WINAPI SFFree(LPVOID lpvMemory)
35{
36 if (lpvMemory) free(lpvMemory);
37}
38
a36705ea 39UInt64 SFGetFileSize(HANDLE hFile)
7214af3e 40{
41 IntConv FileSize;
42
43 FileSize.ui64 = 0;
44
45 FileSize.ui32[0] = ::GetFileSize(hFile, &FileSize.ui32[1]);
46
47 if (FileSize.ui32[0] == INVALID_FILE_SIZE) {
48 if (::GetLastError() != NO_ERROR)
a36705ea 49 return (UInt64)-1;
7214af3e 50 }
51
a36705ea 52 return FileSize.ui64;
7214af3e 53}
54
a36705ea 55UInt64 SFSetFilePointer(HANDLE hFile, Int64 nDistance, UInt32 dwMoveMethod)
7214af3e 56{
57 IntConv FilePos;
58
59 FilePos.i64 = nDistance;
60
a36705ea 61 FilePos.ui32[0] = ::SetFilePointer(hFile, FilePos.i32[0], &FilePos.i32[1], dwMoveMethod);
7214af3e 62
a36705ea 63 if (FilePos.ui32[0] == INVALID_SET_FILE_POINTER) {
7214af3e 64 if (::GetLastError() != NO_ERROR)
a36705ea 65 return (UInt64)-1;
7214af3e 66 }
67
a36705ea 68 return FilePos.ui64;
7214af3e 69}
70
71size_t strlnlen(const char *strline)
72{
73 if (strline==0) return 0;
74 const char *strcr = strchr(strline,'\r');
75 const char *strlf = strchr(strline,'\n');
76 if (strcr==0 && strlf==0) return strlen(strline);
77 if (strcr!=0 && (strcr<strlf || strlf==0)) return strcr-strline;
78 if (strlf!=0 && (strlf<strcr || strcr==0)) return strlf-strline;
79 return strlen(strline);
80}
81
82char *nextline(const char *strline)
83{
84 if (strline==0) return 0;
85 const char *strcr = strchr(strline,'\r');
86 const char *strlf = strchr(strline,'\n');
87 if (strcr==0 && strlf==0) return 0;
88 const char *streol;
89 if (strcr!=0 && (strcr<strlf || strlf==0)) streol = strcr;
90 if (strlf!=0 && (strlf<strcr || strcr==0)) streol = strlf;
91 do {
92 streol++;
93 } while (streol[0]=='\r' || streol[0]=='\n');
94 if (streol[0]==0) return 0;
95 return (char *)streol;
96}