ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/BasiliskII/src/Windows/util_windows.cpp
Revision: 1.3
Committed: 2005-01-30T21:42:15Z (19 years, 4 months ago) by gbeauche
Branch: MAIN
Changes since 1.2: +1 -1 lines
Log Message:
Happy New Year!

File Contents

# Content
1 /*
2 * util_windows.cpp - Miscellaneous utilities for Win32
3 *
4 * Basilisk II (C) 1997-2005 Christian Bauer
5 *
6 * Windows platform specific code copyright (C) Lauri Pesonen
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22
23 #include "sysdeps.h"
24 #include "util_windows.h"
25
26 BOOL exists( const char *path )
27 {
28 HFILE h;
29 bool ret = false;
30
31 h = _lopen( path, OF_READ );
32 if(h != HFILE_ERROR) {
33 ret = true;
34 _lclose(h);
35 }
36 return(ret);
37 }
38
39 BOOL create_file( const char *path, DWORD size )
40 {
41 HANDLE h;
42 bool ok = false;
43
44 h = CreateFile( path,
45 GENERIC_READ | GENERIC_WRITE,
46 0, NULL, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, NULL
47 );
48 if(h != INVALID_HANDLE_VALUE) {
49 if(size == 0) {
50 ok = true;
51 } else if(SetFilePointer( h, size, NULL, FILE_BEGIN) != 0xFFFFFFFF) {
52 if(SetEndOfFile(h)) {
53 ok = true;
54 if(SetFilePointer( h, 0, NULL, FILE_BEGIN) != 0xFFFFFFFF) {
55 DWORD written, zeroed_size = min(1024*1024,size);
56 char *b = (char *)malloc(zeroed_size);
57 if(b) {
58 memset( b, 0, zeroed_size );
59 WriteFile( h, b, zeroed_size, &written, NULL );
60 free(b);
61 }
62 }
63 }
64 }
65 CloseHandle(h);
66 }
67 if(!ok) DeleteFile(path);
68 return(ok);
69 }
70
71 int32 get_file_size( const char *path )
72 {
73 HANDLE h;
74 DWORD size = 0;
75
76 h = CreateFile( path,
77 GENERIC_READ,
78 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL
79 );
80 if(h != INVALID_HANDLE_VALUE) {
81 size = GetFileSize( h, NULL );
82 CloseHandle(h);
83 }
84 return(size);
85 }
86
87
88 /*
89 * Thread wrappers
90 */
91
92 HANDLE create_thread(LPTHREAD_START_ROUTINE start_routine, void *arg)
93 {
94 DWORD dwThreadId;
95 return CreateThread(NULL, 0, start_routine, arg, 0, &dwThreadId);
96 }
97
98 void wait_thread(HANDLE thread)
99 {
100 WaitForSingleObject(thread, INFINITE);
101 CloseHandle(thread);
102 }
103
104 void kill_thread(HANDLE thread)
105 {
106 TerminateThread(thread, 0);
107 }