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




76d2228e351497b8943485382c340e84bdafc809
1 // License information for this code is in license.txt
3 #include <windows.h>
4 #include <stdlib.h>
5 #include "SFTypes.h"
7 void WINAPI SFMemZero(LPVOID lpvDestination, DWORD dwLength)
8 {
9         DWORD dwPrevLen = dwLength;
10         LPDWORD lpdwDestination = (LPDWORD)lpvDestination;
11         LPBYTE lpbyDestination;
13         dwLength >>= 2;
15         while (dwLength--)
16                 *lpdwDestination++ = 0;
18         lpbyDestination = (LPBYTE)lpdwDestination;
20         dwLength = dwPrevLen;
21         dwLength &= 3;
23         while (dwLength--)
24                 *lpbyDestination++ = 0;
25 }
27 LPVOID WINAPI SFAlloc(DWORD dwSize)
28 {
29         LPVOID lpMemory = malloc(dwSize);
30         if (lpMemory) SFMemZero(lpMemory,dwSize);
31         return lpMemory;
32 }
34 void WINAPI SFFree(LPVOID lpvMemory)
35 {
36         if (lpvMemory) free(lpvMemory);
37 }
39 Int64 SFGetFileSize(HANDLE hFile)
40 {
41         IntConv FileSize;
43         FileSize.ui64 = 0;
45         FileSize.ui32[0] = ::GetFileSize(hFile, &FileSize.ui32[1]);
47         if (FileSize.ui32[0] == INVALID_FILE_SIZE) {
48                 if (::GetLastError() != NO_ERROR)
49                         return -1;
50         }
52         return FileSize.i64;
53 }
55 Int64 SFSetFilePointer(HANDLE hFile, Int64 nDistance, UInt32 dwMoveMethod)
56 {
57         IntConv FilePos;
59         FilePos.i64 = nDistance;
61         FilePos.i32[0] = ::SetFilePointer(hFile, FilePos.i32[0], &FilePos.i32[1], dwMoveMethod);
63         if (FilePos.i32[0] == INVALID_SET_FILE_POINTER) {
64                 if (::GetLastError() != NO_ERROR)
65                         return -1;
66         }
68         return FilePos.i64;
69 }
71 size_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 }
82 char *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 }