1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
18 #include <OSD_Error.hxx>
19 #include <OSD_ErrorList.hxx>
20 #include <OSD_OSDError.hxx>
21 #include <TCollection_AsciiString.hxx>
24 /* Created by Stephan GARNAUD (ARM) 1992 for Matra Datavision */
25 OSD_Error::OSD_Error(){
30 void OSD_Error::Reset(){
34 Standard_Boolean OSD_Error::Failed()const{
35 if (myErrno == 0) return (Standard_False);
36 else return (Standard_True);
41 void OSD_Error::SetValue(const Standard_Integer errcode,
42 const Standard_Integer from,
43 const TCollection_AsciiString& message){
45 myCode = (OSD_WhoAmI)from;
51 Standard_Integer OSD_Error::Error()const{
56 void OSD_Error::Perror() {
57 TCollection_AsciiString buffer;
59 if (myErrno == 0) return;
62 extCode = ERR_SURPRISE;
68 buffer += "Invalid file descriptor or bad mode";
82 "The message waiting to be read on stream is not a data message";
83 extCode = ERR_FBADMSG;
94 buffer += "Can't unlink '.' or '..'";
95 extCode = ERR_FNINVAL;
98 buffer += "Invalid file descriptor";
102 buffer += "User error : Bad parameter";
107 #if !defined(sun) && !defined(SOLARIS)
113 buffer += "Exceed quota of disk blocks";
126 buffer += "Lock is already blocked by another process";
127 extCode = ERR_FDEADLK;
138 buffer += "No more file lock entries available";
139 extCode = ERR_FNOLCK;
148 buffer += "File descriptor doesn't refer to a file";
156 buffer += "Permission denied";
157 extCode = ERR_ACCESS;
162 buffer += "Still used by system or a process";
163 extCode = ERR_FNBUSY;
172 buffer += "Not enough or too many bytes written";
173 extCode = ERR_FRANGE;
182 buffer += "Permission denied";
186 buffer += "Permission denied or can't unlink directory";
190 buffer += "abnormal error : you modified OSD library";
199 buffer += "Read only file system";
211 buffer += "I/O error";
215 buffer += "I/O error or Hang up from terminal";
226 buffer += "The File is a Directory";
238 buffer += "File is locked";
239 extCode = ERR_FLOCKED;
251 buffer += "File is locked";
252 extCode = ERR_FLOCKED;
263 buffer += "No data ready to be read/written";
264 extCode = ERR_FAGAIN;
275 buffer += "A component of path is not a Directory";
276 extCode = ERR_NOTDIR;
285 buffer += "Too many links";
286 extCode = ERR_DMLINK;
297 buffer += "Too many symbolic links";
304 buffer += "User error : arguments point to an illegal address";
310 buffer += "Exceed process's file size limit or the maximum file size";
318 buffer += "operation breaked by a signal";
322 buffer += "Not enough memory";
328 buffer += "Too many file descriptors are currently in use by this process";
329 extCode = ERR_FMFILE;
336 buffer += "File name too long";
337 extCode = ERR_NAMETOOLONG;
342 buffer += "Too many files are currently open in the system";
343 extCode = ERR_FNFILE;
352 buffer += "The link named by path2 and the file named by path1 are\n";
353 buffer += "on different logical devices (file systems)";
354 extCode = ERR_FNXDEV;
364 if (myMessage != "Open") buffer += "File doesn't exist or";
365 buffer += "Invalid path (empty string)";
369 buffer += "A component of the path prefix of path does not exist";
370 extCode = ERR_DNOENT;
380 buffer += "No more free space on file system";
381 extCode = ERR_FNOSPC;
390 // AIX maps ENOTEMPTY to EEXIST. Move this case block to
391 // the EEXIST case block.
393 #if (!defined(_AIX)) && (!defined(AIX))
397 buffer += "Directory not empty";
398 extCode = ERR_FNNOTEMPTY;
409 buffer += "Directory not empty";
410 extCode = ERR_FNNOTEMPTY;
413 buffer += "OSD_Create and OSD_Exclude are set and the named file exists";
414 extCode = ERR_FEXIST;
417 buffer += "Identifier already exists for this key";
423 buffer += "Too many Semaphore/Shared memory for a process.";
424 buffer += "Reconfigure Kernel with greater values";
425 extCode = ERR_TOOBIG;
428 Standard_Character buf[255];
430 sprintf(buf,"%sUnknowm error #%d",buffer.ToCString(),myErrno);
431 TCollection_AsciiString interm(buf);
433 extCode = ERR_UNKNOWN;
437 OSD_OSDError::Raise (buffer.ToCString());
442 //------------------------------------------------------------------------
443 //------------------- Windows NT sources for OSD_Error ------------------
444 //------------------------------------------------------------------------
447 #include <OSD_Error.hxx>
448 #include <OSD_ErrorList.hxx>
449 #include <TCollection_ExtendedString.hxx>
454 typedef struct _error_table {
457 Standard_Integer csf_error;
461 static ERROR_TABLE commErrorTable [] = {
463 { ERROR_INVALID_FUNCTION, ERR_INVAL },
464 { ERROR_FILE_NOT_FOUND, ERR_NOENT },
465 { ERROR_PATH_NOT_FOUND, ERR_NOENT },
466 { ERROR_ACCESS_DENIED, ERR_ACCESS },
467 { ERROR_ARENA_TRASHED, ERR_NOMEM },
468 { ERROR_NOT_ENOUGH_MEMORY, ERR_NOMEM },
469 { ERROR_INVALID_BLOCK, ERR_NOMEM },
470 { ERROR_BAD_ENVIRONMENT, ERR_TOOBIG },
471 { ERROR_INVALID_ACCESS, ERR_INVAL },
472 { ERROR_INVALID_DATA, ERR_INVAL },
473 { ERROR_INVALID_DRIVE, ERR_NOENT },
474 { ERROR_CURRENT_DIRECTORY, ERR_ACCESS },
475 { ERROR_NO_MORE_FILES, ERR_NOENT },
476 { ERROR_LOCK_VIOLATION, ERR_ACCESS },
477 { ERROR_SHARING_VIOLATION, ERR_ACCESS },
478 { ERROR_BAD_NETPATH, ERR_NOENT },
479 { ERROR_NETWORK_ACCESS_DENIED, ERR_ACCESS },
480 { ERROR_BAD_NET_NAME, ERR_NOENT },
481 { ERROR_FILE_EXISTS, ERR_EXIST },
482 { ERROR_CANNOT_MAKE, ERR_ACCESS },
483 { ERROR_FAIL_I24, ERR_ACCESS },
484 { ERROR_INVALID_PARAMETER, ERR_INVAL },
485 { ERROR_DRIVE_LOCKED, ERR_ACCESS },
486 { ERROR_INVALID_HANDLE, ERR_INVAL },
487 { ERROR_NEGATIVE_SEEK, ERR_INVAL },
488 { ERROR_SEEK_ON_DEVICE, ERR_ACCESS },
489 { ERROR_NOT_LOCKED, ERR_ACCESS },
490 { ERROR_BAD_PATHNAME, ERR_NOENT },
491 { ERROR_LOCK_FAILED, ERR_ACCESS },
492 { ERROR_ALREADY_EXISTS, ERR_EXIST },
493 { ERROR_FILENAME_EXCED_RANGE, ERR_NOENT },
494 { ERROR_NOT_ENOUGH_QUOTA, ERR_QUOT },
495 { ERROR_IO_DEVICE, ERR_IO },
496 { ERROR_INVALID_BLOCK, ERR_FAULT },
497 { ERROR_BAD_THREADID_ADDR, ERR_FAULT },
498 { ERROR_INVALID_ADDRESS, ERR_FAULT },
499 { ERROR_MAPPED_ALIGNMENT, ERR_FAULT },
500 { ERROR_BUFFER_OVERFLOW, ERR_NAMETOOLONG }
504 #define COMM_ERR_TABLE_SIZE (int)(sizeof(commErrorTable) / sizeof(commErrorTable[0]))
506 static ERROR_TABLE dirErrorTable[] = {
508 { ERROR_FILE_NOT_FOUND, ERR_NOENT },
509 { ERROR_PATH_NOT_FOUND, ERR_NOENT },
510 { ERROR_INVALID_DRIVE, ERR_NOENT },
511 { ERROR_NO_MORE_FILES, ERR_NOENT },
512 { ERROR_BAD_NETPATH, ERR_NOENT },
513 { ERROR_BAD_NET_NAME, ERR_NOENT },
514 { ERROR_BAD_PATHNAME, ERR_NOENT },
515 { ERROR_FILENAME_EXCED_RANGE, ERR_NOENT }
519 #define DIR_ERR_TABLE_SIZE (int)(sizeof(dirErrorTable) / sizeof(dirErrorTable[0]))
521 static ERROR_TABLE fileErrorTable[] = {
523 { ERROR_INVALID_HANDLE, ERR_FBADF },
524 { ERROR_INVALID_TARGET_HANDLE, ERR_FBADF },
525 { ERROR_DIRECT_ACCESS_HANDLE, ERR_FBADF },
526 { ERROR_FILE_EXISTS, ERR_EXIST },
527 { ERROR_ALREADY_EXISTS, ERR_EXIST },
528 { ERROR_TOO_MANY_OPEN_FILES, ERR_FMFILE },
529 { ERROR_INVALID_FUNCTION, ERR_FINVAL },
530 { ERROR_INVALID_ACCESS, ERR_FINVAL },
531 { ERROR_INVALID_DATA, ERR_FINVAL },
532 { ERROR_INVALID_PARAMETER, ERR_FINVAL },
533 { ERROR_INVALID_HANDLE, ERR_FINVAL },
534 { ERROR_NEGATIVE_SEEK, ERR_FINVAL },
535 { ERROR_IO_PENDING, ERR_FAGAIN },
536 { ERROR_WRITE_FAULT, ERR_FIO },
537 { ERROR_READ_FAULT, ERR_FIO },
538 { ERROR_NET_WRITE_FAULT, ERR_FIO },
539 { ERROR_IO_DEVICE, ERR_FIO },
540 { ERROR_LOCK_VIOLATION, ERR_FLOCKED },
541 { ERROR_LOCK_FAILED, ERR_FLOCKED }
545 #define FILE_ERR_TABLE_SIZE (int)(sizeof(fileErrorTable) / sizeof(fileErrorTable[0]))
547 static ERROR_TABLE fileNodeErrorTable[] = {
549 { ERROR_INVALID_FUNCTION, ERR_FNINVAL },
550 { ERROR_INVALID_ACCESS, ERR_FNINVAL },
551 { ERROR_INVALID_DATA, ERR_FNINVAL },
552 { ERROR_INVALID_PARAMETER, ERR_FNINVAL },
553 { ERROR_INVALID_HANDLE, ERR_FNINVAL },
554 { ERROR_NEGATIVE_SEEK, ERR_FNINVAL },
555 { ERROR_DISK_FULL, ERR_FNOSPC },
556 { ERROR_DIR_NOT_EMPTY, ERR_FNNOTEMPTY },
557 { ERROR_NOT_SAME_DEVICE, ERR_FNXDEV }
561 #define FILE_NODE_ERR_TABLE_SIZE (int)(sizeof(fileNodeErrorTable) / sizeof(fileNodeErrorTable[0]))
563 static Standard_Integer _get_comm_error ( DWORD );
565 OSD_Error :: OSD_Error () :
566 myCode((OSD_WhoAmI)0),
570 } // end constructor ( 1 )
572 void OSD_Error :: Perror () {
576 StringCchCopyW(buff, _countof(buff), L"Error ( ");
580 case OSD_WDirectoryIterator:
581 StringCchCatW(buff, _countof(buff), L"OSD_DirectoryIterator");
585 StringCchCatW(buff, _countof(buff), L"OSD_Directory");
588 case OSD_WFileIterator:
589 StringCchCatW(buff, _countof(buff), L"OSD_FileIterator");
593 StringCchCatW(buff, _countof(buff), L"OSD_File");
597 StringCchCatW(buff, _countof(buff), L"OSD_FileNode");
601 StringCchCatW(buff, _countof(buff), L"OSD_Host");
605 StringCchCatW(buff, _countof(buff), L"OSD_Environment");
608 case OSD_WEnvironmentIterator:
609 StringCchCatW(buff, _countof(buff), L"OSD_EnvironmentIterator");
612 case OSD_WEnvironment:
613 StringCchCatW(buff, _countof(buff), L"OSD_Environment");
617 StringCchCatW(buff, _countof(buff), L"OSD_Disk");
621 StringCchCatW(buff, _countof(buff), L"Unknown");
625 StringCchCatW(buff, _countof(buff), L" )");
629 std::cerr << myMessage.ToCString() << std::endl << std::flush;
631 } // end OSD_Error :: Perror
633 void OSD_Error :: SetValue (
634 const Standard_Integer Errcode,
635 const Standard_Integer From,
636 const TCollection_AsciiString& Message
642 myCode = ( OSD_WhoAmI )From;
649 for ( i = 0; i < DIR_ERR_TABLE_SIZE; ++i )
651 if ( dirErrorTable[ i ].wnt_error == ( DWORD )Errcode ) {
653 extCode = dirErrorTable[ i ].csf_error;
658 if ( i == DIR_ERR_TABLE_SIZE ) extCode = _get_comm_error ( Errcode );
664 for ( i = 0; i < FILE_ERR_TABLE_SIZE; ++i )
666 if ( fileErrorTable[ i ].wnt_error == ( DWORD )Errcode ) {
668 extCode = fileErrorTable[ i ].csf_error;
673 if ( i == FILE_ERR_TABLE_SIZE ) extCode = _get_comm_error ( Errcode );
679 for ( i = 0; i < FILE_NODE_ERR_TABLE_SIZE; ++i )
681 if ( fileNodeErrorTable[ i ].wnt_error == ( DWORD )Errcode ) {
683 extCode = fileNodeErrorTable[ i ].csf_error;
688 if ( i == FILE_NODE_ERR_TABLE_SIZE ) extCode = _get_comm_error ( Errcode );
694 extCode = _get_comm_error ( Errcode );
698 } // end OSD_Error :: SetValue
700 Standard_Integer OSD_Error :: Error () const {
704 } // end OSD_Error :: Error
706 Standard_Boolean OSD_Error :: Failed () const {
708 return myErrno == ERROR_SUCCESS ? Standard_False : Standard_True;
710 } // end OSD_Error :: Failed
712 void OSD_Error :: Reset ()
714 myErrno = ERROR_SUCCESS;
715 } // end OSD_Error :: Reset
717 static Standard_Integer _get_comm_error ( DWORD dwCode ) {
720 Standard_Integer retVal = ERR_SURPRISE;
722 for ( i = 0; i < COMM_ERR_TABLE_SIZE; ++i )
724 if ( commErrorTable[ i ].wnt_error == ( DWORD )dwCode ) {
726 retVal = commErrorTable[ i ].csf_error;
733 } // end _get_comm_error