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
39Int64 SFGetFileSize(HANDLE hFile)
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)
49 return -1;
50 }
51
52 return FileSize.i64;
53}
54
55Int64 SFSetFilePointer(HANDLE hFile, Int64 nDistance, UInt32 dwMoveMethod)
56{
57 IntConv FilePos;
58
59 FilePos.i64 = nDistance;
60
61 FilePos.i32[0] = ::SetFilePointer(hFile, FilePos.i32[0], &FilePos.i32[1], dwMoveMethod);
62
a9570bb3 63#ifdef INVALID_SET_FILE_POINTER
41207b36 64 if (FilePos.ui32[0] == INVALID_SET_FILE_POINTER) {
a9570bb3 65#else
66 if (FilePos.ui32[0] == INVALID_FILE_SIZE) {
67#endif
7214af3e 68 if (::GetLastError() != NO_ERROR)
69 return -1;
70 }
71
72 return FilePos.i64;
73}
74
75size_t strlnlen(const char *strline)
76{
77 if (strline==0) return 0;
78 const char *strcr = strchr(strline,'\r');
79 const char *strlf = strchr(strline,'\n');
80 if (strcr==0 && strlf==0) return strlen(strline);
81 if (strcr!=0 && (strcr<strlf || strlf==0)) return strcr-strline;
82 if (strlf!=0 && (strlf<strcr || strcr==0)) return strlf-strline;
83 return strlen(strline);
84}
85
86char *nextline(const char *strline)
87{
88 if (strline==0) return 0;
89 const char *strcr = strchr(strline,'\r');
90 const char *strlf = strchr(strline,'\n');
91 if (strcr==0 && strlf==0) return 0;
41207b36 92 const char *streol = strlf;
7214af3e 93 if (strcr!=0 && (strcr<strlf || strlf==0)) streol = strcr;
94 if (strlf!=0 && (strlf<strcr || strcr==0)) streol = strlf;
95 do {
96 streol++;
97 } while (streol[0]=='\r' || streol[0]=='\n');
98 if (streol[0]==0) return 0;
99 return (char *)streol;
100}