home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / lib / libc / src / plerror.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  4.3 KB  |  145 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. /*
  20. ** File:plerror.c
  21. ** Description: Simple routine to print translate the calling thread's
  22. **  error numbers and print them to "syserr".
  23. */
  24.  
  25. #include "plerror.h"
  26.  
  27. #include "prprf.h"
  28. #include "prerror.h"
  29.  
  30. PR_IMPLEMENT(void) PL_FPrintError(PRFileDesc *fd, const char *msg)
  31. {
  32. static const char *tags[] =
  33. {
  34.     "PR_OUT_OF_MEMORY_ERROR",
  35.     "PR_BAD_DESCRIPTOR_ERROR", 
  36.     "PR_WOULD_BLOCK_ERROR",
  37.     "PR_ACCESS_FAULT_ERROR", 
  38.     "PR_INVALID_METHOD_ERROR", 
  39.     "PR_ILLEGAL_ACCESS_ERROR", 
  40.     "PR_UNKNOWN_ERROR",
  41.     "PR_PENDING_INTERRUPT_ERROR",
  42.     "PR_NOT_IMPLEMENTED_ERROR",
  43.     "PR_IO_ERROR", 
  44.     "PR_IO_TIMEOUT_ERROR", 
  45.     "PR_IO_PENDING_ERROR", 
  46.     "PR_DIRECTORY_OPEN_ERROR", 
  47.     "PR_INVALID_ARGUMENT_ERROR", 
  48.     "PR_ADDRESS_NOT_AVAILABLE_ERROR",
  49.     "PR_ADDRESS_NOT_SUPPORTED_ERROR",
  50.     "PR_IS_CONNECTED_ERROR", 
  51.     "PR_BAD_ADDRESS_ERROR",
  52.     "PR_ADDRESS_IN_USE_ERROR", 
  53.     "PR_CONNECT_REFUSED_ERROR",
  54.     "PR_NETWORK_UNREACHABLE_ERROR",
  55.     "PR_CONNECT_TIMEOUT_ERROR",
  56.     "PR_NOT_CONNECTED_ERROR",
  57.     "PR_LOAD_LIBRARY_ERROR", 
  58.     "PR_UNLOAD_LIBRARY_ERROR", 
  59.     "PR_FIND_SYMBOL_ERROR",
  60.     "PR_INSUFFICIENT_RESOURCES_ERROR", 
  61.     "PR_DIRECTORY_LOOKUP_ERROR", 
  62.     "PR_TPD_RANGE_ERROR",
  63.     "PR_PROC_DESC_TABLE_FULL_ERROR", 
  64.     "PR_SYS_DESC_TABLE_FULL_ERROR",
  65.     "PR_NOT_SOCKET_ERROR", 
  66.     "PR_NOT_TCP_SOCKET_ERROR", 
  67.     "PR_SOCKET_ADDRESS_IS_BOUND_ERROR",
  68.     "PR_NO_ACCESS_RIGHTS_ERROR", 
  69.     "PR_OPERATION_NOT_SUPPORTED_ERROR",
  70.     "PR_PROTOCOL_NOT_SUPPORTED_ERROR", 
  71.     "PR_REMOTE_FILE_ERROR",
  72.     "PR_BUFFER_OVERFLOW_ERROR",
  73.     "PR_CONNECT_RESET_ERROR",
  74.     "PR_RANGE_ERROR",
  75.     "PR_DEADLOCK_ERROR", 
  76.     "PR_FILE_IS_LOCKED_ERROR", 
  77.     "PR_FILE_TOO_BIG_ERROR", 
  78.     "PR_NO_DEVICE_SPACE_ERROR",
  79.     "PR_PIPE_ERROR", 
  80.     "PR_NO_SEEK_DEVICE_ERROR", 
  81.     "PR_IS_DIRECTORY_ERROR", 
  82.     "PR_LOOP_ERROR", 
  83.     "PR_NAME_TOO_LONG_ERROR",
  84.     "PR_FILE_NOT_FOUND_ERROR", 
  85.     "PR_NOT_DIRECTORY_ERROR",
  86.     "PR_READ_ONLY_FILESYSTEM_ERROR", 
  87.     "PR_DIRECTORY_NOT_EMPTY_ERROR",
  88.     "PR_FILESYSTEM_MOUNTED_ERROR", 
  89.     "PR_NOT_SAME_DEVICE_ERROR",
  90.     "PR_DIRECTORY_CORRUPTED_ERROR",
  91.     "PR_FILE_EXISTS_ERROR",
  92.     "PR_MAX_DIRECTORY_ENTRIES_ERROR",
  93.     "PR_INVALID_DEVICE_STATE_ERROR", 
  94.     "PR_DEVICE_IS_LOCKED_ERROR", 
  95.     "PR_NO_MORE_FILES_ERROR",
  96.     "PR_END_OF_FILE_ERROR",
  97.     "PR_FILE_SEEK_ERROR",
  98.     "PR_FILE_IS_BUSY_ERROR", 
  99.     "PR_IN_PROGRESS_ERROR",
  100.     "PR_ALREADY_INITIATED_ERROR",
  101.     "PR_GROUP_EMPTY_ERROR",
  102.     "PR_INVALID_STATE_ERROR",
  103.     "PR_MAX_ERROR"
  104. };
  105.  
  106. PRErrorCode error = PR_GetError();
  107. PRInt32 oserror = PR_GetOSError();
  108. PRIntn thoseIKnowAbout = sizeof(tags) / sizeof(char*);
  109. PRIntn lastError = PR_NSPR_ERROR_BASE + thoseIKnowAbout;
  110.  
  111.     if (NULL != msg) PR_fprintf(fd, "%s: ", msg);
  112.     if ((error < PR_NSPR_ERROR_BASE) || (error > lastError))
  113.         PR_fprintf(
  114.             fd, " (%d)OUT OF RANGE, oserror = %d\n", error, oserror);
  115.     else
  116.         PR_fprintf(
  117.             fd, "%s(%d), oserror = %d\n",
  118.             tags[error - PR_NSPR_ERROR_BASE], error, oserror);
  119. }  /* PL_FPrintError */
  120.  
  121. PR_IMPLEMENT(void) PL_PrintError(const char *msg)
  122. {
  123.     static PRFileDesc *fd = NULL;
  124.     if (NULL == fd) fd = PR_GetSpecialFD(PR_StandardError);
  125.     PL_FPrintError(fd, msg);
  126. }  /* PL_PrintError */
  127.  
  128. #if defined(WIN16)
  129. /*
  130. ** libmain() is a required function for win16
  131. **
  132. */
  133. int CALLBACK LibMain( HINSTANCE hInst, WORD wDataSeg, 
  134.   WORD cbHeapSize, LPSTR lpszCmdLine )
  135. {
  136. return TRUE;
  137. }
  138. #endif /* WIN16 */
  139.  
  140.  
  141.  
  142.  
  143.  
  144. /* plerror.c */
  145.