forked from orbcode/orbuculum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstream_file_win32.c
65 lines (53 loc) · 2.52 KB
/
stream_file_win32.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "stream_win32.h"
#include <stdlib.h>
#include <stdio.h>
#include <Windows.h>
#include "generics.h"
struct Win32FileStream
{
struct Win32Stream base;
};
#define SELF( stream ) ( ( struct Win32FileStream* )( stream ) )
// ====================================================================================================
// ====================================================================================================
// ====================================================================================================
// Private routines
// ====================================================================================================
// ====================================================================================================
// ====================================================================================================
// ====================================================================================================
static HANDLE _win32FileStreamCreate( const char *file )
{
HANDLE h = CreateFile(
file,
GENERIC_READ,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED,
NULL
);
return h;
}
// ====================================================================================================
// ====================================================================================================
// ====================================================================================================
// Publicly available routines
// ====================================================================================================
// ====================================================================================================
// ====================================================================================================
// ====================================================================================================
struct Stream *streamCreateFile( const char *file )
{
struct Win32FileStream *stream = SELF( calloc( 1, sizeof( struct Win32FileStream ) ) );
if ( stream == NULL )
{
return NULL;
}
if ( !streamWin32Initialize( ( struct Win32Stream * )stream, _win32FileStreamCreate( file ) ) )
{
free( stream );
return NULL;
}
return &stream->base.base;
}