4 Copyright (C) 1995, 1996, 1997 Ovidiu Predescu and Mircea Oancea.
7 Author: Ovidiu Predescu <ovidiu@net-community.com>
10 This file is part of libFoundation.
12 Permission to use, copy, modify, and distribute this software and its
13 documentation for any purpose and without fee is hereby granted, provided
14 that the above copyright notice appear in all copies and that both that
15 copyright notice and this permission notice appear in supporting
18 We disclaim all warranties with regard to this software, including all
19 implied warranties of merchantability and fitness, in no event shall
20 we be liable for any special, indirect or consequential damages or any
21 damages whatsoever resulting from loss of use, data or profits, whether in
22 an action of contract, negligence or other tortious action, arising out of
23 or in connection with the use or performance of this software.
26 #include <Foundation/common.h>
29 # include <sys/stat.h>
33 #include <sys/types.h>
35 #include <Foundation/NSFileHandle.h>
36 #include "NSConcreteFileHandle.h"
38 @implementation NSFileHandle
40 static NSFileHandle *nullDevice = nil;
45 static WSADATA wsaData;
46 WSAStartup(MAKEWORD(1, 1), &wsaData);
50 + (id)allocWithZone:(NSZone*)zone
52 return (self == [NSFileHandle class])
53 ? [NSConcreteFileHandle allocWithZone:zone]
54 : NSAllocateObject(self, 0, zone);
57 + (id)fileHandleForReadingAtPath:(NSString*)path
59 return [NSConcreteFileHandle fileHandleForReadingAtPath:path];
61 + (id)fileHandleForWritingAtPath:(NSString*)path
63 return [NSConcreteFileHandle fileHandleForWritingAtPath:path];
65 + (id)fileHandleForUpdatingAtPath:(NSString*)path
67 return [NSConcreteFileHandle fileHandleForUpdatingAtPath:path];
72 + (id)fileHandleWithStandardInput
74 return AUTORELEASE([[self alloc] initWithNativeHandle:
75 GetStdHandle(STD_INPUT_HANDLE)]);
77 + (id)fileHandleWithStandardOutput
79 return AUTORELEASE([[self alloc] initWithNativeHandle:
80 GetStdHandle(STD_OUTPUT_HANDLE)]);
82 + (id)fileHandleWithStandardError
84 return AUTORELEASE([[self alloc] initWithNativeHandle:
85 GetStdHandle(STD_ERROR_HANDLE)]);
88 #else /* !__MINGW32__ */
90 + (id)fileHandleWithStandardInput
92 return AUTORELEASE([[self alloc] initWithFileDescriptor:0]);
95 + (id)fileHandleWithStandardOutput
97 return AUTORELEASE([[self alloc] initWithFileDescriptor:1]);
100 + (id)fileHandleWithStandardError
102 return AUTORELEASE([[self alloc] initWithFileDescriptor:2]);
105 #endif /* !__MINGW32__ */
107 + (id)fileHandleWithNullDevice
110 nullDevice = [NSNullDeviceFileHandle new];
115 @end /* NSFileHandle */
118 LF_DECLARE NSString *NSFileHandleConnectionAcceptedNotification
119 = @"NSFileHandleConnectionAcceptedNotification";
121 LF_DECLARE NSString *NSFileHandleReadCompletionNotification
122 = @"NSFileHandleReadCompletionNotification";
124 LF_DECLARE NSString *NSFileHandleReadToEndOfFileCompletionNotification
125 = @"NSFileHandleReadToEndOfFileCompletionNotification";
127 LF_DECLARE NSString *NSFileHandleNotificationFileHandleItem
128 = @"NSFileHandleNotificationFileHandleItem";
130 LF_DECLARE NSString *NSFileHandleNotificationDataItem
131 = @"NSFileHandleNotificationDataItem";
133 NSString* NSFileHandleNotificationMonitorModes
134 = @"NSFileHandleNotificationMonitorModes";