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.
17 #include <OSD_Error.ixx>
18 #include <OSD_ErrorList.hxx>
21 /* Created by Stephan GARNAUD (ARM) 1992 for Matra Datavision */
23 OSD_Error::OSD_Error(){
28 void OSD_Error::Reset(){
32 Standard_Boolean OSD_Error::Failed()const{
33 if (myErrno == 0) return (Standard_False);
34 else return (Standard_True);
39 void OSD_Error::SetValue(const Standard_Integer errcode,
40 const Standard_Integer from,
41 const TCollection_AsciiString& message){
43 myCode = (OSD_WhoAmI)from;
49 Standard_Integer OSD_Error::Error()const{
54 void OSD_Error::Perror() {
55 TCollection_AsciiString buffer;
57 if (myErrno == 0) return;
60 extCode = ERR_SURPRISE;
66 buffer += "Invalid file descriptor or bad mode";
80 "The message waiting to be read on stream is not a data message";
81 extCode = ERR_FBADMSG;
92 buffer += "Can't unlink '.' or '..'";
93 extCode = ERR_FNINVAL;
96 buffer += "Invalid file descriptor";
100 buffer += "User error : Bad parameter";
105 #if !defined(sun) && !defined(SOLARIS)
111 buffer += "Exceed quota of disk blocks";
124 buffer += "Lock is already blocked by another process";
125 extCode = ERR_FDEADLK;
136 buffer += "No more file lock entries available";
137 extCode = ERR_FNOLCK;
146 buffer += "File descriptor doesn't refer to a file";
154 buffer += "Permission denied";
155 extCode = ERR_ACCESS;
160 buffer += "Still used by system or a process";
161 extCode = ERR_FNBUSY;
170 buffer += "Not enough or too many bytes written";
171 extCode = ERR_FRANGE;
180 buffer += "Permission denied";
184 buffer += "Permission denied or can't unlink directory";
188 buffer += "abnormal error : you modified OSD library";
197 buffer += "Read only file system";
209 buffer += "I/O error";
213 buffer += "I/O error or Hang up from terminal";
224 buffer += "The File is a Directory";
236 buffer += "File is locked";
237 extCode = ERR_FLOCKED;
249 buffer += "File is locked";
250 extCode = ERR_FLOCKED;
261 buffer += "No data ready to be read/written";
262 extCode = ERR_FAGAIN;
273 buffer += "A component of path is not a Directory";
274 extCode = ERR_NOTDIR;
283 buffer += "Too many links";
284 extCode = ERR_DMLINK;
295 buffer += "Too many symbolic links";
302 buffer += "User error : arguments point to an illegal address";
308 buffer += "Exceed process's file size limit or the maximum file size";
316 buffer += "operation breaked by a signal";
320 buffer += "Not enough memory";
326 buffer += "Too many file descriptors are currently in use by this process";
327 extCode = ERR_FMFILE;
334 buffer += "File name too long";
335 extCode = ERR_NAMETOOLONG;
340 buffer += "Too many files are currently open in the system";
341 extCode = ERR_FNFILE;
350 buffer += "The link named by path2 and the file named by path1 are\n";
351 buffer += "on different logical devices (file systems)";
352 extCode = ERR_FNXDEV;
362 if (myMessage != "Open") buffer += "File doesn't exist or";
363 buffer += "Invalid path (empty string)";
367 buffer += "A component of the path prefix of path does not exist";
368 extCode = ERR_DNOENT;
378 buffer += "No more free space on file system";
379 extCode = ERR_FNOSPC;
388 // AIX maps ENOTEMPTY to EEXIST. Move this case block to
389 // the EEXIST case block.
391 #if (!defined(_AIX)) && (!defined(AIX))
395 buffer += "Directory not empty";
396 extCode = ERR_FNNOTEMPTY;
407 buffer += "Directory not empty";
408 extCode = ERR_FNNOTEMPTY;
411 buffer += "OSD_Create and OSD_Exclude are set and the named file exists";
412 extCode = ERR_FEXIST;
415 buffer += "Identifier already exists for this key";
421 buffer += "Too many Semaphore/Shared memory for a process.";
422 buffer += "Reconfigure Kernel with greater values";
423 extCode = ERR_TOOBIG;
426 Standard_Character buf[255];
428 sprintf(buf,"%sUnknowm error #%d",buffer.ToCString(),myErrno);
429 TCollection_AsciiString interm(buf);
431 extCode = ERR_UNKNOWN;
435 OSD_OSDError::Raise (buffer.ToCString());
440 //------------------------------------------------------------------------
441 //------------------- Windows NT sources for OSD_Error ------------------
442 //------------------------------------------------------------------------
445 #include <OSD_Error.hxx>
446 #include <OSD_ErrorList.hxx>
447 #include <TCollection_ExtendedString.hxx>
451 typedef struct _error_table {
454 Standard_Integer csf_error;
458 static int fPrefix = 1;
459 static ostream* errorStream = &cerr;
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 () {
574 if (errorStream == NULL)
577 Standard_Character buff[ 32 ];
578 Standard_CString ptr;
582 lstrcpy ( buff, "Error ( " );
586 case OSD_WDirectoryIterator:
588 ptr = "OSD_DirectoryIterator";
594 ptr = "OSD_Directory";
598 case OSD_WFileIterator:
600 ptr = "OSD_FileIterator";
612 ptr = "OSD_FileNode";
624 ptr = "OSD_Environment";
628 case OSD_WEnvironmentIterator:
630 ptr = "OSD_EnvironmentIterator";
634 case OSD_WEnvironment:
636 ptr = "OSD_Environment";
652 lstrcat ( buff, ptr );
653 lstrcat ( buff, " )" );
654 ( *errorStream ) << buff;
656 } // end if ( fPrefix . . . )
658 TCollection_ExtendedString aMessageW(myMessage);
659 ( *errorStream ) << L": " << (const wchar_t*)aMessageW.ToExtString () << endl << flush;
661 } // end OSD_Error :: Perror
663 void OSD_Error :: SetValue (
664 const Standard_Integer Errcode,
665 const Standard_Integer From,
666 const TCollection_AsciiString& Message
672 myCode = ( OSD_WhoAmI )From;
679 for ( i = 0; i < DIR_ERR_TABLE_SIZE; ++i )
681 if ( dirErrorTable[ i ].wnt_error == ( DWORD )Errcode ) {
683 extCode = dirErrorTable[ i ].csf_error;
688 if ( i == DIR_ERR_TABLE_SIZE ) extCode = _get_comm_error ( Errcode );
694 for ( i = 0; i < FILE_ERR_TABLE_SIZE; ++i )
696 if ( fileErrorTable[ i ].wnt_error == ( DWORD )Errcode ) {
698 extCode = fileErrorTable[ i ].csf_error;
703 if ( i == FILE_ERR_TABLE_SIZE ) extCode = _get_comm_error ( Errcode );
709 for ( i = 0; i < FILE_NODE_ERR_TABLE_SIZE; ++i )
711 if ( fileNodeErrorTable[ i ].wnt_error == ( DWORD )Errcode ) {
713 extCode = fileNodeErrorTable[ i ].csf_error;
718 if ( i == FILE_NODE_ERR_TABLE_SIZE ) extCode = _get_comm_error ( Errcode );
724 extCode = _get_comm_error ( Errcode );
728 } // end OSD_Error :: SetValue
730 Standard_Integer OSD_Error :: Error () const {
734 } // end OSD_Error :: Error
736 Standard_Boolean OSD_Error :: Failed () const {
738 return myErrno == ERROR_SUCCESS ? Standard_False : Standard_True;
740 } // end OSD_Error :: Failed
742 void OSD_Error :: Reset () {
744 myErrno = ERROR_SUCCESS;
745 if (errorStream != NULL)
747 ( *errorStream ).clear ();
748 ( *errorStream ).seekp ( 0 );
749 ( *errorStream ).clear ();
752 } // end OSD_Error :: Reset
754 void SetErrorStream ( ostream* errStream ) {
756 errorStream = errStream;
758 } // end SetErrorStream
760 void EnablePrefix ( int fEnable ) {
764 } // end EnablePrefix
766 int ErrorPrefix ( void ) {
772 ostream* ErrorStream ( void ) {
778 static Standard_Integer _get_comm_error ( DWORD dwCode ) {
781 Standard_Integer retVal = ERR_SURPRISE;
783 for ( i = 0; i < COMM_ERR_TABLE_SIZE; ++i )
785 if ( commErrorTable[ i ].wnt_error == ( DWORD )dwCode ) {
787 retVal = commErrorTable[ i ].csf_error;
794 } // end _get_comm_error