home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / src / misc / prerror.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  2.6 KB  |  90 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. #include "primpl.h"
  20.  
  21. #include <memory.h>
  22. #include <string.h>
  23. #include <stdlib.h>
  24.  
  25. PR_IMPLEMENT(PRErrorCode) PR_GetError()
  26. {
  27.     PRThread *thread = PR_GetCurrentThread();
  28.     return thread->errorCode;
  29. }
  30.  
  31. PR_IMPLEMENT(PRInt32) PR_GetOSError()
  32. {
  33.     PRThread *thread = PR_GetCurrentThread();
  34.     return thread->osErrorCode;
  35. }
  36.  
  37. PR_IMPLEMENT(const char*) PR_GetErrorString()
  38. {
  39.     PRThread *thread = PR_GetCurrentThread();
  40.     return thread->errorString;
  41. }
  42.  
  43. PR_IMPLEMENT(void) PR_SetError(PRErrorCode code, PRInt32 osErr)
  44. {
  45.     PRThread *thread = PR_GetCurrentThread();
  46.     thread->errorCode = code;
  47.     thread->osErrorCode = osErr;
  48.     thread->errorStringSize = 0;
  49.     PR_DELETE(thread->errorString);
  50. }
  51.  
  52. PR_IMPLEMENT(void) PR_SetErrorText(PRIntn textLength, const char *text)
  53. {
  54.     PRThread *thread = PR_GetCurrentThread();
  55.  
  56.     if (0 == textLength)
  57.     {
  58.         if (NULL != thread->errorString)
  59.             PR_DELETE(thread->errorString);
  60.     }
  61.     else
  62.     {
  63.         PRIntn size = textLength + 1;  /* actual length to allocate */
  64.         if (thread->errorStringSize < textLength)  /* do we have room? */
  65.         {
  66.             if (NULL != thread->errorString)
  67.                 PR_DELETE(thread->errorString);
  68.             thread->errorString = (char*)PR_MALLOC(size);
  69.         }
  70.         memcpy(thread->errorString, text, size);
  71.     }
  72.     thread->errorStringSize = textLength;
  73. }
  74.  
  75. PR_IMPLEMENT(PRInt32) PR_GetErrorTextLength(void)
  76. {
  77.     PRThread *thread = PR_GetCurrentThread();
  78.     return thread->errorStringSize;
  79. }  /* PR_GetErrorTextLength */
  80.  
  81. PR_IMPLEMENT(PRInt32) PR_GetErrorText(char *text)
  82. {
  83.     PRThread *thread = PR_GetCurrentThread();
  84.     if (0 != thread->errorStringSize)
  85.         memcpy(text, thread->errorString, thread->errorStringSize + 1);
  86.     return thread->errorStringSize;
  87. }  /* PR_GetErrorText */
  88.  
  89.  
  90.