aug_util.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * $Id$
  3. *
  4. * POSTGRES module, portions of this code were templated using
  5. * the mysql module, thus it's similarity.
  6. *
  7. *
  8. * Copyright (C) 2003 August.Net Services, LLC
  9. *
  10. * This file is part of ser, a free SIP server.
  11. *
  12. * ser is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version
  16. *
  17. * For a license to use the ser software under conditions
  18. * other than those described here, or to purchase support for this
  19. * software, please contact iptel.org by e-mail at the following addresses:
  20. * [email protected]
  21. *
  22. * ser is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program; if not, write to the Free Software
  29. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  30. *
  31. * ---
  32. *
  33. * History
  34. * -------
  35. * 2003-04-06 initial code written (Greg Fausak/Andy Fullford)
  36. *
  37. */
  38. /*
  39. ** ________________________________________________________________________
  40. **
  41. **
  42. ** $RCSfile$
  43. ** $Revision$
  44. **
  45. ** Last change $Date$
  46. ** Last change $Author$
  47. ** $State$
  48. ** $Locker$
  49. **
  50. ** Original author: Andrew Fullford
  51. **
  52. ** Copyright (C) August Associates 1995
  53. **
  54. ** ________________________________________________________________________
  55. */
  56. #include "aug_std.h"
  57. #include <stdlib.h>
  58. #include <stdio.h>
  59. #include <stdarg.h>
  60. #include <string.h>
  61. static char *aug_module_name = 0;
  62. /*
  63. ** May eventually add ``on exit'' function calls.
  64. */
  65. augExport void aug_exit(int exit_code)
  66. {
  67. DABNAME("aug_exit");
  68. DABTRACE("Exiting with code %d", exit_code);
  69. exit(exit_code);
  70. }
  71. augExport void aug_abort_va(char *file, int line, char *fmt, va_list ap)
  72. {
  73. DABNAME("aug_abort");
  74. DAB("ABORT from +%d %s", line, file);
  75. fflush(stdout);
  76. fprintf(stderr, "\r\n\n");
  77. if(aug_module_name)
  78. fprintf(stderr, "%s: ", aug_module_name);
  79. fprintf(stderr, "ABORT: ");
  80. vfprintf(stderr, fmt, ap);
  81. fprintf(stderr, " -- from +%d %s\r\n\n", line, file);
  82. if(DABLEVEL(DAB_TRACE))
  83. {
  84. fprintf(stderr, "Program terminating via abort()\r\n\n");
  85. abort();
  86. }
  87. aug_exit(augEXIT_ABORT);
  88. }
  89. augExport void aug_abort(char *file, int line, char *fmt, ...)
  90. {
  91. va_list ap;
  92. va_start(ap, fmt);
  93. aug_abort_va(file, line, fmt, ap);
  94. va_end(ap);
  95. }
  96. /*
  97. ** WARNING -- don't use DABs below here, aug_debug.c calls this code.
  98. */
  99. augExport void aug_setmodule(char *name)
  100. {
  101. char *prog;
  102. int len;
  103. if(!name)
  104. return;
  105. if((prog = strrchr(name, '/')) ||
  106. (prog = strrchr(name, '\\')))
  107. prog++;
  108. else
  109. prog = name;
  110. aug_module_name = malloc(strlen(prog) + 1);
  111. strcpy(aug_module_name, prog);
  112. }
  113. augExport char *aug_module(void)
  114. {
  115. return (aug_module_name ? aug_module_name : "");
  116. }