utility.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * Part of Very Secure FTPd
  3. * Licence: GPL v2
  4. * Author: Chris Evans
  5. * utility.c
  6. */
  7. #include "utility.h"
  8. #include "sysutil.h"
  9. #include "str.h"
  10. #include "defs.h"
  11. #define DIE_DEBUG
  12. void
  13. die(const char* p_text)
  14. {
  15. #ifdef DIE_DEBUG
  16. bug(p_text);
  17. #endif
  18. vsf_sysutil_exit(2);
  19. }
  20. void
  21. die2(const char* p_text1, const char* p_text2)
  22. {
  23. struct mystr die_str = INIT_MYSTR;
  24. str_alloc_text(&die_str, p_text1);
  25. if (p_text2)
  26. {
  27. str_append_text(&die_str, p_text2);
  28. }
  29. else
  30. {
  31. str_append_text(&die_str, "(null)");
  32. }
  33. die(str_getbuf(&die_str));
  34. }
  35. void
  36. bug(const char* p_text)
  37. {
  38. /* Rats. Try and write the reason to the network for diagnostics */
  39. vsf_sysutil_activate_noblock(VSFTP_COMMAND_FD);
  40. (void) vsf_sysutil_write_loop(VSFTP_COMMAND_FD, "500 OOPS: ", 10);
  41. (void) vsf_sysutil_write_loop(VSFTP_COMMAND_FD, p_text,
  42. vsf_sysutil_strlen(p_text));
  43. (void) vsf_sysutil_write_loop(VSFTP_COMMAND_FD, "\r\n", 2);
  44. vsf_sysutil_exit(2);
  45. }
  46. void
  47. vsf_exit(const char* p_text)
  48. {
  49. (void) vsf_sysutil_write_loop(VSFTP_COMMAND_FD, p_text,
  50. vsf_sysutil_strlen(p_text));
  51. vsf_sysutil_exit(0);
  52. }