]> err.no Git - sope/blob - libFoundation/Foundation/NSFileHandle.m
fixed some NGMail framework build issue
[sope] / libFoundation / Foundation / NSFileHandle.m
1 /*
2    NSFileHandle.m
3
4    Copyright (C) 1995, 1996, 1997 Ovidiu Predescu and Mircea Oancea.
5    All rights reserved.
6
7    Author: Ovidiu Predescu <ovidiu@net-community.com>
8    Date: May 1997
9
10    This file is part of libFoundation.
11
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
16    documentation.
17
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.
24 */
25
26 #include <Foundation/common.h>
27
28 #if HAVE_SYS_STAT_H
29 # include <sys/stat.h>
30 #endif
31
32 #include <fcntl.h>
33 #include <sys/types.h>
34
35 #include <Foundation/NSFileHandle.h>
36 #include "NSConcreteFileHandle.h"
37
38 @implementation NSFileHandle
39
40 static NSFileHandle *nullDevice = nil;
41
42 + (void)initialize
43 {
44 #ifdef WIN32
45     static WSADATA wsaData;
46     WSAStartup(MAKEWORD(1, 1), &wsaData);
47 #endif
48 }
49
50 + (id)allocWithZone:(NSZone*)zone
51 {
52     return (self == [NSFileHandle class])
53         ? [NSConcreteFileHandle allocWithZone:zone] 
54         : NSAllocateObject(self, 0, zone);
55 }
56
57 + (id)fileHandleForReadingAtPath:(NSString*)path
58 {
59     return [NSConcreteFileHandle fileHandleForReadingAtPath:path];
60 }
61 + (id)fileHandleForWritingAtPath:(NSString*)path
62 {
63     return [NSConcreteFileHandle fileHandleForWritingAtPath:path];
64 }
65 + (id)fileHandleForUpdatingAtPath:(NSString*)path
66 {
67     return [NSConcreteFileHandle fileHandleForUpdatingAtPath:path];
68 }
69
70 #ifdef __MINGW32__
71
72 + (id)fileHandleWithStandardInput
73 {
74     return AUTORELEASE([[self alloc] initWithNativeHandle:
75                                          GetStdHandle(STD_INPUT_HANDLE)]);
76 }
77 + (id)fileHandleWithStandardOutput
78 {
79     return AUTORELEASE([[self alloc] initWithNativeHandle:
80                                          GetStdHandle(STD_OUTPUT_HANDLE)]);
81 }
82 + (id)fileHandleWithStandardError
83 {
84     return AUTORELEASE([[self alloc] initWithNativeHandle:
85                                          GetStdHandle(STD_ERROR_HANDLE)]);
86 }
87
88 #else /* !__MINGW32__ */
89
90 + (id)fileHandleWithStandardInput
91 {
92     return AUTORELEASE([[self alloc] initWithFileDescriptor:0]);
93 }
94
95 + (id)fileHandleWithStandardOutput
96 {
97     return AUTORELEASE([[self alloc] initWithFileDescriptor:1]);
98 }
99
100 + (id)fileHandleWithStandardError
101 {
102     return AUTORELEASE([[self alloc] initWithFileDescriptor:2]);
103 }
104
105 #endif /* !__MINGW32__ */
106
107 + (id)fileHandleWithNullDevice
108 {
109     if (!nullDevice)
110         nullDevice = [NSNullDeviceFileHandle new];
111
112     return nullDevice;
113 }
114
115 @end /* NSFileHandle */
116
117
118 LF_DECLARE NSString *NSFileHandleConnectionAcceptedNotification
119     = @"NSFileHandleConnectionAcceptedNotification";
120
121 LF_DECLARE NSString *NSFileHandleReadCompletionNotification
122     = @"NSFileHandleReadCompletionNotification";
123
124 LF_DECLARE NSString *NSFileHandleReadToEndOfFileCompletionNotification
125     = @"NSFileHandleReadToEndOfFileCompletionNotification";
126
127 LF_DECLARE NSString *NSFileHandleNotificationFileHandleItem
128     = @"NSFileHandleNotificationFileHandleItem";
129
130 LF_DECLARE NSString *NSFileHandleNotificationDataItem
131     = @"NSFileHandleNotificationDataItem";
132
133 NSString* NSFileHandleNotificationMonitorModes
134     = @"NSFileHandleNotificationMonitorModes";
135
136 /*
137   Local Variables:
138   c-basic-offset: 4
139   tab-width: 8
140   End:
141 */