summaryrefslogtreecommitdiffstats
path: root/private/nw/test/open.c
blob: fa39844385a4fb878864c5974884ad88a19f4f17 (plain) (blame)
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/*++

Copyright (c) 1993  Microsoft Corporation

Module Name:

    fileio.c

Abstract:

    User mode test program for the Microsoft Netware redir file system.

    This test program can be built from the command line using the
    command 'nmake UMTEST=open'.

Author:

    Manny Weiser (mannyw)   17-May-1993

Revision History:

--*/

#include <stdio.h>
#include <string.h>
#include <nt.h>
#include <ntrtl.h>
#include <nturtl.h>

//
// Local definitions
//

VOID
DisplayUsage(
    PSZ ProgramName
    );


BOOLEAN
OpenFile(
    PSZ Name,
    PHANDLE Handle
    );


cdecl
main(
    int argc,
    char *argv[],
    )
{
    HANDLE handle;
    BOOLEAN success;
    char *fileName;

    if ( argc == 1) {
        DisplayUsage( argv[0] );
        return( 1 );
    }

    fileName = argv[1];

    success = OpenFile( fileName, &handle );
    if ( !success) {
        return 1;
    }

    NtClose( handle );

    printf( "%s exiting\n", argv[0]);
    return 0;
}


VOID
DisplayUsage(
    PSZ ProgramName
    )
{
    printf( "Usage: %s [filename]", ProgramName);
}


BOOLEAN
OpenFile(
    PSZ Name,
    PHANDLE Handle
    )
{
    NTSTATUS status;
    OBJECT_ATTRIBUTES objectAttributes;
    IO_STATUS_BLOCK ioStatusBlock;
    STRING AnsiFileName;
    UNICODE_STRING FileName;

    RtlInitString( &AnsiFileName, Name );
    RtlOemStringToUnicodeString( &FileName, &AnsiFileName, TRUE );

    //
    //  Open the file
    //

    InitializeObjectAttributes(
        &objectAttributes,
        &FileName,
        OBJ_CASE_INSENSITIVE,
        NULL,
        NULL
        );

    status = NtOpenFile (
                Handle,
                FILE_GENERIC_READ,
                &objectAttributes,
                &ioStatusBlock,
                FILE_SHARE_WRITE | FILE_SHARE_READ,
                0L
                );

    if (!NT_SUCCESS(status) ) {
        printf( "Open status = %x for file %Z\n", status, &FileName );
    }

    RtlFreeHeap(RtlProcessHeap(), 0, FileName.Buffer );
    return ( (BOOLEAN) NT_SUCCESS( status ) );
}


DoSleep(
    IN ULONG time
    )
{
    ULONG ms;
    LARGE_INTEGER delayTime;

    ms = time * 100;
    delayTime = RtlEnlargedIntegerMultiply( ms, -10000 );
    NtDelayExecution( TRUE, (PLARGE_INTEGER)&delayTime );

    return( 0 );
}