|
|
1.1 root 1: // This is a part of the Microsoft Foundation Classes C++ library.
2: // Copyright (C) 1992 Microsoft Corporation
3: // All rights reserved.
4: //
5: // This source code is only intended as a supplement to the
6: // Microsoft Foundation Classes Reference and Microsoft
7: // QuickHelp documentation provided with the library.
8: // See these sources for detailed information regarding the
9: // Microsoft Foundation Classes product.
10:
11: #include "afx.h"
12:
13: #pragma hdrstop
14:
15: #include <errno.h>
16:
17: #ifdef AFX_AUX_SEG
18: #pragma code_seg(AFX_AUX_SEG)
19: #endif
20:
21: #ifdef _DEBUG
22: #undef THIS_FILE
23: static char BASED_CODE THIS_FILE[] = __FILE__;
24: #endif
25:
26: #ifdef _DEBUG
27:
28: // character strings to use for dumping CFileException
29: static char BASED_CODE szNone[] = "none";
30: static char BASED_CODE szGeneric[] = "generic";
31: static char BASED_CODE szFileNotFound[] = "fileNotFound";
32: static char BASED_CODE szBadPath[] = "badPath";
33: static char BASED_CODE szTooManyOpenFiles[] = "tooManyOpenFiles";
34: static char BASED_CODE szAccessDenied[] = "accessDenied";
35: static char BASED_CODE szInvalidFile[] = "invalidFile";
36: static char BASED_CODE szRemoveCurrentDir[] = "removeCurrentDir";
37: static char BASED_CODE szDirectoryFull[] = "directoryFull";
38: static char BASED_CODE szBadSeek[] = "badSeek";
39: static char BASED_CODE szHardIO[] = "hardIO";
40: static char BASED_CODE szSharingViolation[] = "sharingViolation";
41: static char BASED_CODE szLockViolation[] = "lockViolation";
42: static char BASED_CODE szDiskFull[] = "diskFull";
43: static char BASED_CODE szEndOfFile[] = "endOfFile";
44:
45: static char FAR* BASED_CODE rgszCFileExceptionCause[] =
46: {
47: szNone,
48: szGeneric,
49: szFileNotFound,
50: szBadPath,
51: szTooManyOpenFiles,
52: szAccessDenied,
53: szInvalidFile,
54: szRemoveCurrentDir,
55: szDirectoryFull,
56: szBadSeek,
57: szHardIO,
58: szSharingViolation,
59: szLockViolation,
60: szDiskFull,
61: szEndOfFile,
62: };
63:
64: static char BASED_CODE szUnknown[] = "unknown";
65: #endif
66:
67: /////////////////////////////////////////////////////////////////////////////
68: // CFileException
69:
70: IMPLEMENT_DYNAMIC(CFileException, CException)
71:
72: void
73: CFileException::ThrowOsError(LONG lOsError)
74: {
75: if (lOsError != 0)
76: AfxThrowFileException(CFileException::OsErrorToException(lOsError),
77: lOsError);
78: }
79:
80: void
81: CFileException::ThrowErrno(int nErrno)
82: {
83: if (nErrno != 0)
84: AfxThrowFileException(CFileException::ErrnoToException(nErrno),
85: _doserrno);
86: }
87:
88:
89: #ifdef _DEBUG
90: void
91: CFileException::Dump(CDumpContext& dc) const
92: {
93: CObject::Dump(dc);
94: dc << " m_cause = ";
95:
96: if (m_cause >= 0 &&
97: m_cause < sizeof(rgszCFileExceptionCause) / sizeof(char FAR*))
98: {
99: dc << rgszCFileExceptionCause[m_cause];
100: }
101: else
102: {
103: dc << szUnknown;
104: }
105: dc << ", lOsError = " << m_lOsError;
106: }
107: #endif
108:
109: void
110: PASCAL AfxThrowFileException(int cause, LONG lOsError)
111: {
112: #ifdef _DEBUG
113: TRACE("CFile exception: ");
114: if (cause >= 0 &&
115: cause < sizeof(rgszCFileExceptionCause) / sizeof(char FAR*))
116: {
117: afxDump << (char FAR*)rgszCFileExceptionCause[cause];
118: }
119: else
120: {
121: afxDump << (char FAR*)szUnknown;
122: }
123: afxDump << ", OS error information = " << (void FAR*)lOsError << "\n";
124: #endif
125: THROW(new CFileException(cause, lOsError));
126: }
127:
128:
129: int
130: CFileException::ErrnoToException(int nErrno)
131: {
132: switch(nErrno)
133: {
134: case EPERM:
135: case EACCES:
136: return CFileException::accessDenied;
137: case EBADF: return CFileException::invalidFile;
138: case EDEADLOCK: return CFileException::sharingViolation;
139: case EMFILE: return CFileException::tooManyOpenFiles;
140: case ENOENT:
141: case ENFILE:
142: return CFileException::fileNotFound;
143: case ENOSPC: return CFileException::diskFull;
144: case EINVAL:
145: case EIO: return CFileException::hardIO;
146: default:
147: return CFileException::generic;
148: }
149: }
150:
151:
152: #ifdef _DOSWIN
153: int
154: CFileException::OsErrorToException(LONG lOsErr)
155: {
156: switch ((UINT)lOsErr)
157: {
158: // DOS Error codes
159: case 0x1: return CFileException::generic;
160: case 0x2: return CFileException::fileNotFound;
161: case 0x3: return CFileException::badPath;
162: case 0x4: return CFileException::tooManyOpenFiles;
163: case 0x5: return CFileException::accessDenied;
164: case 0x6: return CFileException::invalidFile;
165: case 0xf: return CFileException::badPath;
166: case 0x10: return CFileException::removeCurrentDir;
167: case 0x12: return CFileException::directoryFull;
168: case 0x19: return CFileException::badSeek;
169: case 0x1d: return CFileException::hardIO;
170: case 0x1e: return CFileException::hardIO;
171: case 0x1f: return CFileException::hardIO;
172: case 0x58: return CFileException::hardIO;
173: case 0x20: return CFileException::sharingViolation;
174: case 0x21: return CFileException::lockViolation;
175: case 0x23: return CFileException::tooManyOpenFiles;
176: case 0x24: return CFileException::sharingViolation;
177: case 0x41: return CFileException::accessDenied;
178: case 0x43: return CFileException::fileNotFound;
179: case 0x52: return CFileException::accessDenied;
180: default: return CFileException::generic;
181: }
182: }
183: #endif // _WINDOWS
184:
185: #ifdef _NTWIN
186: #include "winerror.h"
187: int
188: CFileException::OsErrorToException(LONG lOsErr)
189: {
190: switch ((UINT)lOsErr)
191: {
192: // NT Error codes
193: case NO_ERROR: return CFileException::none;
194: case ERROR_FILE_NOT_FOUND: return CFileException::fileNotFound;
195: case ERROR_PATH_NOT_FOUND: return CFileException::badPath;
196: case ERROR_TOO_MANY_OPEN_FILES: return CFileException::tooManyOpenFiles;
197: case ERROR_ACCESS_DENIED: return CFileException::accessDenied;
198: case ERROR_INVALID_HANDLE: return CFileException::fileNotFound;
199: case ERROR_BAD_FORMAT: return CFileException::invalidFile;
200: case ERROR_INVALID_ACCESS: return CFileException::accessDenied;
201: case ERROR_INVALID_DRIVE: return CFileException::badPath;
202: case ERROR_CURRENT_DIRECTORY: return CFileException::removeCurrentDir;
203: case ERROR_NOT_SAME_DEVICE: return CFileException::badPath;
204: case ERROR_NO_MORE_FILES: return CFileException::fileNotFound;
205: case ERROR_WRITE_PROTECT: return CFileException::accessDenied;
206: case ERROR_BAD_UNIT: return CFileException::hardIO;
207: case ERROR_NOT_READY: return CFileException::hardIO;
208: case ERROR_BAD_COMMAND: return CFileException::hardIO;
209: case ERROR_CRC: return CFileException::hardIO;
210: case ERROR_BAD_LENGTH: return CFileException::badSeek;
211: case ERROR_SEEK: return CFileException::badSeek;
212: case ERROR_NOT_DOS_DISK: return CFileException::invalidFile;
213: case ERROR_SECTOR_NOT_FOUND: return CFileException::badSeek;
214: case ERROR_WRITE_FAULT: return CFileException::accessDenied;
215: case ERROR_READ_FAULT: return CFileException::badSeek;
216: case ERROR_SHARING_VIOLATION: return CFileException::sharingViolation;
217: case ERROR_NOT_LOCKED: return CFileException::lockViolation;
218: case ERROR_LOCK_VIOLATION: return CFileException::lockViolation;
219: case ERROR_WRONG_DISK: return CFileException::badPath;
220: case ERROR_SHARING_BUFFER_EXCEEDED: return CFileException::tooManyOpenFiles;
221: case ERROR_HANDLE_EOF: return CFileException::endOfFile;
222: case ERROR_HANDLE_DISK_FULL: return CFileException::diskFull;
223: case ERROR_DUP_NAME: return CFileException::badPath;
224: case ERROR_BAD_NETPATH: return CFileException::badPath;
225: case ERROR_NETWORK_BUSY: return CFileException::accessDenied;
226: case ERROR_DEV_NOT_EXIST: return CFileException::badPath;
227: case ERROR_ADAP_HDW_ERR: return CFileException::hardIO;
228: case ERROR_BAD_NET_RESP: return CFileException::accessDenied;
229: case ERROR_UNEXP_NET_ERR: return CFileException::hardIO;
230: case ERROR_BAD_REM_ADAP: return CFileException::invalidFile;
231: case ERROR_NO_SPOOL_SPACE: return CFileException::directoryFull;
232: case ERROR_NETNAME_DELETED: return CFileException::accessDenied;
233: case ERROR_NETWORK_ACCESS_DENIED: return CFileException::accessDenied;
234: case ERROR_BAD_DEV_TYPE: return CFileException::invalidFile;
235: case ERROR_BAD_NET_NAME: return CFileException::badPath;
236: case ERROR_TOO_MANY_NAMES: return CFileException::tooManyOpenFiles;
237: case ERROR_SHARING_PAUSED: return CFileException::badPath;
238: case ERROR_REQ_NOT_ACCEP: return CFileException::accessDenied;
239: case ERROR_FILE_EXISTS: return CFileException::accessDenied;
240: case ERROR_CANNOT_MAKE: return CFileException::accessDenied;
241: case ERROR_ALREADY_ASSIGNED: return CFileException::badPath;
242: case ERROR_INVALID_PASSWORD: return CFileException::accessDenied;
243: case ERROR_NET_WRITE_FAULT: return CFileException::hardIO;
244: case ERROR_DISK_CHANGE: return CFileException::fileNotFound;
245: case ERROR_DRIVE_LOCKED: return CFileException::lockViolation;
246: case ERROR_BUFFER_OVERFLOW: return CFileException::badPath;
247: case ERROR_DISK_FULL: return CFileException::diskFull;
248: case ERROR_NO_MORE_SEARCH_HANDLES: return CFileException::tooManyOpenFiles;
249: case ERROR_INVALID_TARGET_HANDLE: return CFileException::invalidFile;
250: case ERROR_INVALID_CATEGORY: return CFileException::hardIO;
251: case ERROR_INVALID_NAME: return CFileException::badPath;
252: case ERROR_INVALID_LEVEL: return CFileException::badPath;
253: case ERROR_NO_VOLUME_LABEL: return CFileException::badPath;
254: case ERROR_NEGATIVE_SEEK: return CFileException::badSeek;
255: case ERROR_SEEK_ON_DEVICE: return CFileException::badSeek;
256: case ERROR_DIR_NOT_ROOT: return CFileException::badPath;
257: case ERROR_DIR_NOT_EMPTY: return CFileException::removeCurrentDir;
258: case ERROR_LABEL_TOO_LONG: return CFileException::badPath;
259: case ERROR_BAD_PATHNAME: return CFileException::badPath;
260: case ERROR_LOCK_FAILED: return CFileException::lockViolation;
261: case ERROR_BUSY: return CFileException::accessDenied;
262: case ERROR_INVALID_ORDINAL: return CFileException::invalidFile;
263: case ERROR_ALREADY_EXISTS: return CFileException::accessDenied;
264: case ERROR_INVALID_EXE_SIGNATURE: return CFileException::invalidFile;
265: case ERROR_BAD_EXE_FORMAT: return CFileException::invalidFile;
266: case ERROR_FILENAME_EXCED_RANGE: return CFileException::badPath;
267: case ERROR_META_EXPANSION_TOO_LONG: return CFileException::badPath;
268: case ERROR_DIRECTORY: return CFileException::badPath;
269: case ERROR_OPERATION_ABORTED: return CFileException::hardIO;
270: case ERROR_IO_INCOMPLETE: return CFileException::hardIO;
271: case ERROR_IO_PENDING: return CFileException::hardIO;
272: case ERROR_SWAPERROR: return CFileException::accessDenied;
273: default: return CFileException::generic;
274: }
275: }
276: #endif // _NTWIN
277:
278:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.