errors.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /* libanode: the Anode C reference implementation
  2. * Copyright (C) 2009-2010 Adam Ierymenko <[email protected]>
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>. */
  16. #include "anode.h"
  17. struct AnodeErrDesc
  18. {
  19. int code;
  20. const char *desc;
  21. };
  22. #define TOTAL_ERRORS 12
  23. static const struct AnodeErrDesc ANODE_ERRORS[TOTAL_ERRORS] = {
  24. { ANODE_ERR_NONE, "No error (success)" },
  25. { ANODE_ERR_INVALID_ARGUMENT, "Invalid argument" },
  26. { ANODE_ERR_OUT_OF_MEMORY, "Out of memory" },
  27. { ANODE_ERR_INVALID_URI, "Invalid URI" },
  28. { ANODE_ERR_BUFFER_TOO_SMALL, "Supplied buffer too small" },
  29. { ANODE_ERR_ADDRESS_INVALID, "Address invalid" },
  30. { ANODE_ERR_ADDRESS_TYPE_NOT_SUPPORTED, "Address type not supported"},
  31. { ANODE_ERR_CONNECTION_CLOSED, "Connection closed"},
  32. { ANODE_ERR_CONNECT_FAILED, "Connect failed"},
  33. { ANODE_ERR_UNABLE_TO_BIND, "Unable to bind to address"},
  34. { ANODE_ERR_TOO_MANY_OPEN_SOCKETS, "Too many open sockets"},
  35. { ANODE_ERR_DNS_NAME_NOT_FOUND_OR_TIMED_OUT, "DNS name not found or timed out"}
  36. };
  37. extern const char *Anode_strerror(int err)
  38. {
  39. int i;
  40. int negerr = -err;
  41. for(i=0;i<TOTAL_ERRORS;++i) {
  42. if ((ANODE_ERRORS[i].code == err)||(ANODE_ERRORS[i].code == negerr))
  43. return ANODE_ERRORS[i].desc;
  44. }
  45. return "Unknown error";
  46. }