From: <lab...@us...> - 2004-03-15 08:08:13
|
Update of /cvsroot/opengtoolkit/pipe/c_source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6420/c_source Modified Files: pipes.c Log Message: Added error code translation Index: pipes.c =================================================================== RCS file: /cvsroot/opengtoolkit/pipe/c_source/pipes.c,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** pipes.c 11 Mar 2004 23:44:05 -0000 1.2 --- pipes.c 15 Mar 2004 07:59:06 -0000 1.3 *************** *** 266,282 **** } #if defined(MSWin) static MgErr Win32ToLVErr(DWORD error) { ! /* No translation yet */ ! return error; } #elif defined(Unix) static MgErr UnixToLVErr(int32 errno) { ! /* No translation yet */ ! return error; } #endif \ No newline at end of file --- 266,462 ---- } + /* size of the table */ + #define ERRTABLESIZE (sizeof(errtable)/sizeof(errtable[0])) + #if defined(MSWin) + struct errentry { + unsigned long oscode; /* OS return value */ + MgErr err; /* LabVIEW error code */ + }; + + static struct errentry errtable[] = { + {ERROR_INVALID_FUNCTION, mgArgErr }, /* 1 */ + {ERROR_FILE_NOT_FOUND, fNotFound }, /* 2 */ + {ERROR_PATH_NOT_FOUND, fNotFound }, /* 3 */ + {ERROR_TOO_MANY_OPEN_FILES, fTMFOpen }, /* 4 */ + {ERROR_ACCESS_DENIED, fNoPerm }, /* 5 */ + {ERROR_INVALID_HANDLE, mgArgErr }, /* 6 */ + {ERROR_ARENA_TRASHED, mFullErr }, /* 7 */ + {ERROR_NOT_ENOUGH_MEMORY, mFullErr }, /* 8 */ + {ERROR_INVALID_BLOCK, mFullErr }, /* 9 */ + {ERROR_BAD_ENVIRONMENT, fNotEnabled }, /* 10 */ + {ERROR_BAD_FORMAT, fNotEnabled }, /* 11 */ + {ERROR_INVALID_ACCESS, mgArgErr }, /* 12 */ + {ERROR_INVALID_DATA, mgArgErr }, /* 13 */ + {ERROR_INVALID_DRIVE, fNotFound }, /* 15 */ + {ERROR_CURRENT_DIRECTORY, fNoPerm }, /* 16 */ + {ERROR_NOT_SAME_DEVICE, fIOErr }, /* 17 */ + {ERROR_NO_MORE_FILES, fNotFound }, /* 18 */ + {ERROR_LOCK_VIOLATION, fNoPerm }, /* 33 */ + {ERROR_BAD_NETPATH, fNotFound }, /* 53 */ + {ERROR_NETWORK_ACCESS_DENIED, fNoPerm }, /* 65 */ + {ERROR_BAD_NET_NAME, fNotFound }, /* 67 */ + {ERROR_FILE_EXISTS, fDupPath }, /* 80 */ + {ERROR_CANNOT_MAKE, fNoPerm }, /* 82 */ + {ERROR_FAIL_I24, fNoPerm }, /* 83 */ + {ERROR_INVALID_PARAMETER, mgArgErr }, /* 87 */ + {ERROR_NO_PROC_SLOTS, mFullErr }, /* 89 */ + {ERROR_DRIVE_LOCKED, fNoPerm }, /* 108 */ + {ERROR_BROKEN_PIPE, fIOErr }, /* 109 */ + {ERROR_DISK_FULL, fDiskFull }, /* 112 */ + {ERROR_INVALID_TARGET_HANDLE, mgArgErr }, /* 114 */ + {ERROR_INVALID_HANDLE, mgArgErr }, /* 124 */ + {ERROR_WAIT_NO_CHILDREN, fNotEnabled }, /* 128 */ + {ERROR_CHILD_NOT_COMPLETE, fNotEnabled }, /* 129 */ + {ERROR_DIRECT_ACCESS_HANDLE, mgArgErr }, /* 130 */ + {ERROR_NEGATIVE_SEEK, mgArgErr }, /* 131 */ + {ERROR_SEEK_ON_DEVICE, fNoPerm }, /* 132 */ + {ERROR_DIR_NOT_EMPTY, fNoPerm }, /* 145 */ + {ERROR_NOT_LOCKED, fNoPerm }, /* 158 */ + {ERROR_BAD_PATHNAME, fNotFound }, /* 161 */ + {ERROR_MAX_THRDS_REACHED, mFullErr }, /* 164 */ + {ERROR_LOCK_FAILED, fNoPerm }, /* 167 */ + {ERROR_ALREADY_EXISTS, fDupPath }, /* 183 */ + {ERROR_FILENAME_EXCED_RANGE, fNotFound }, /* 206 */ + {ERROR_NESTING_NOT_ALLOWED, mFullErr }, /* 215 */ + {ERROR_NOT_ENOUGH_QUOTA, mFullErr } /* 1816 */ + }; + static MgErr Win32ToLVErr(DWORD error) { ! int i; ! ! /* check the table for the OS error code */ ! for (i = 0; i < ERRTABLESIZE; ++i) ! { ! if (error == errtable[i].oscode) ! { ! return errtable[i].err; ! } ! } ! ! /* The error code wasn't in the table. We check for a range of */ ! /* EACCES errors or exec failure errors (ENOEXEC). Otherwise */ ! /* EINVAL is returned. */ ! ! if (error >= MIN_EACCES_RANGE && error <= MAX_EACCES_RANGE) ! return fNoPerm; ! else if (error >= MIN_EXEC_ERROR && error <= MAX_EXEC_ERROR) ! return mgArgErr; ! return mgArgErr } #elif defined(Unix) + struct errentry { + int errnocode; /* System V error code */ + MgErr err; /* LabVIEW error code */ + }; + + static struct errentry errtable[] = { + {EINVAL, mgArgErr }, + {ENOENT, fNotFound }, + {EMFILE, fTMFOpen }, + {EACCES, fNoPerm }, + {EBADF, mgArgErr }, + {ENOMEM, mFullErr }, + {E2BIG, fNotEnabled }, + {ENOEXEC, fNotEnabled }, + {EXDEV, fIOErr }, + {EEXIST, fDupPath }, + {EAGAIN, mFullErr }, + {EPIPE, fIOErr }, + {ENOSPC, fDiskFull }, + {ECHILD, fNotEnabled }, + {ENOTEMPTY, fNoPerm }, + }; + static MgErr UnixToLVErr(int32 errno) { ! int i; ! ! /* check the table for the OS error code */ ! for (i = 0; i < ERRTABLESIZE; ++i) ! { ! if (errno == errtable[i].oscode) ! { ! return errtable[i].err; ! } ! } ! ! /* The error code wasn't in the table. */ ! return mgArgErr } + #elif defined (Mac) + struct errentry { + short maccode; /* MAC return value */ + MgErr err; /* LabVIEW error code */ + }; + + static struct errentry errtable[] = { + {ioErr, fIOErr }, /*I/O error (bummers)*/ + {paramErr, mgArgErr }, /*error in user parameter list */ + {dirFulErr, fDiskFull }, /*Directory full*/ + {dskFulErr, fDiskFull }, /*disk full*/ + {nsvErr, fNotFound }, /*no such volume*/ + {bdNamErr, mgArgErr }, /*there may be no bad names in the final system!*/ + {fnOpnErr, fNoPerm }, /*File not open*/ + {eofErr, fEOF }, /*End of file*/ + {posErr, mgArgErr }, /*tried to position to before start of file (r/w)*/ + {mFulErr, mFullErr }, /*memory full (open) or file won't fit (load)*/ + {tmfoErr, fTMFOpen }, /*too many files open*/ + {fnfErr, fNotFound }, /*File not found*/ + {wPrErr, fNoPerm }, /*diskette is write protected.*/ + {fLckdErr, fNoPerm }, /*file is locked*/ + {vLckdErr, fNoPerm }, /*volume is locked*/ + {fBsyErr, fNoPerm }, /*File is busy (delete)*/ + {dupFNErr, fDupPath }, /*duplicate filename (rename)*/ + {opWrErr, fNoPerm }, /*file already open with with write permission*/ + {rfNumErr, mgArgErr }, /*refnum error*/ + {gfpErr, mgArgErr }, /*get file position error*/ + {volOffLinErr, mgArgErr }, /*volume not on line error (was Ejected)*/ + {permErr, fNoPerm }, /*permissions error (on file open)*/ + {volOnLinErr, mgArgErr }, /*drive volume already on-line at MountVol*/ + {nsDrvErr, mgArgErr }, /*no such drive (tried to mount a bad drive num)*/ + {noMacDskErr, mgArgErr }, /*not a mac diskette (sig bytes are wrong)*/ + {extFSErr, mgArgErr }, /*volume in question belongs to an external fs*/ + {fsRnErr, mgArgErr }, /*file system internal error:during rename the old + entry was deleted but could not be restored.*/ + {badMDBErr, mgArgErr }, /*bad master directory block*/ + {wrPermErr, fNoPerm }, /*write permissions error*/ + {dirNFErr, fNotFound }, /*Directory not found*/ + {tmwdoErr, fTMFOpen }, /*No free WDCB available*/ + {badMovErr, mgArgErr }, /*Move into offspring error*/ + {wrgVolTypErr, mgArgErr }, /*Wrong volume type error [operation not supported for MFS]*/ + {volGoneErr, mgArgErr }, /*Server volume has been disconnected.*/ + {fidNotFound, mgArgErr }, /*no file thread exists.*/ + {fidExists, fDupPath }, /*file id already exists*/ + {notAFileErr, mgArgErr }, /*directory specified*/ + {diffVolErr, mgArgErr }, /*files on different volumes*/ + {catChangedErr, mgArgErr }, /*the catalog has been modified*/ + {desktopDamagedErr, mgArgErr }, /*desktop database files are corrupted*/ + {sameFileErr, mgArgErr }, /*can't exchange a file with itself*/ + {badFidErr, mgArgErr }, /*file id is dangling or doesn't match with the file number*/ + {afpRangeOverlap, fNoPerm }, /*locking error*/ + {afpRangeNotLocked, fNoPerm }, /*unlocking error*/ + {afpObjectTypeErr, fNoPerm }, /*file is a directory*/ + {afpAccessDenied, fNoPerm }, /*user does not have correct acces to the file*/ + }; + + static MgErr MacToLVErr(OSErr osErr) + { + int i; + + /* check the table for the OS error code */ + for (i = 0; i < ERRTABLESIZE; ++i) + { + if (osErr == errtable[i].oscode) + { + return errtable[i].err; + } + } + + /* The error code wasn't in the table. */ + return mgArgErr + } #endif \ No newline at end of file |