error.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (C) 1995. Bill Brown <brown@gis.uiuc.edu> & Michael Shapiro
  3. *
  4. * This program is free software under the GPL (>=v2)
  5. * Read the file GPL.TXT coming with GRASS for details.
  6. */
  7. #include <string.h>
  8. static int err_code = 0;
  9. static char err_msg[1024];
  10. /*!
  11. * \brief
  12. *
  13. * record 'code' and 'msg' as
  14. * error code/msg (in static variables)
  15. * code==0 will clear the error (ie set msg=NULL)
  16. * returns 'code' so that it can be used like:
  17. \code
  18. return datetime_error (-1, "bad date");
  19. \endcode
  20. *
  21. * \param code
  22. * \param msg
  23. * \return int
  24. */
  25. int datetime_error(int code, char *msg)
  26. {
  27. err_code = code;
  28. *err_msg = 0;
  29. if (code != 0 && msg)
  30. strcpy(err_msg, msg); /* hope err_msg is big enough */
  31. return code;
  32. }
  33. /*!
  34. * \brief
  35. *
  36. * returns an error code
  37. *
  38. * \return int
  39. */
  40. int datetime_error_code(void)
  41. {
  42. return err_code;
  43. }
  44. /*!
  45. * \brief
  46. *
  47. * returns an error message
  48. *
  49. * \return char *
  50. */
  51. char *datetime_error_msg(void)
  52. {
  53. return err_msg;
  54. }
  55. /*!
  56. * \brief
  57. *
  58. * clears error code and message
  59. *
  60. * \return void
  61. */
  62. void datetime_clear_error(void)
  63. {
  64. err_code = 0;
  65. *err_msg = 0;
  66. }