/src/globaldefs.c

http://bdremote-ng.googlecode.com/ · C · 90 lines · 42 code · 17 blank · 31 comment · 5 complexity · c219570e9d2bb53238a3b27321f8a62e MD5 · raw file

  1. /*
  2. * bdremoteng - helper daemon for Sony(R) BD Remote Control
  3. * Based on bdremoted, written by Anton Starikov <antst@mail.ru>.
  4. *
  5. * Copyright (C) 2009 Michael Wojciechowski <wojci@wojci.dk>
  6. *
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  21. *
  22. */
  23. /** \ingroup Gen */
  24. /*@{*/
  25. /*! \file globaldefs.c
  26. \brief Functions used by the macros in globaldefs.h.
  27. Implements a few functions used by the macros in globaldefs.h.
  28. */
  29. #include "globaldefs.h"
  30. #if BDREMOTE_DEBUG
  31. # include <assert.h>
  32. # include <string.h>
  33. /** Handy macro to extract some part from time_t. */
  34. # define getPart(PART) { \
  35. struct tm* Tm = localtime(_ltime); \
  36. return Tm->PART; \
  37. }
  38. int getHour(time_t* _ltime)
  39. {
  40. getPart(tm_hour);
  41. }
  42. int getMinute(time_t* _ltime)
  43. {
  44. getPart(tm_min);
  45. }
  46. int getSecond(time_t* _ltime)
  47. {
  48. getPart(tm_sec);
  49. }
  50. const char* bdrGetFilename(const char* _filenameWithSlashes)
  51. {
  52. int offset = 0;
  53. int len = 0;
  54. int i = 0;
  55. assert(_filenameWithSlashes != NULL);
  56. len = strlen(_filenameWithSlashes);
  57. for (i = len; i >= 0; i--)
  58. {
  59. if (_filenameWithSlashes[i] == '/')
  60. {
  61. offset = i;
  62. if ((offset+1) < len)
  63. {
  64. offset++;
  65. }
  66. break;
  67. }
  68. }
  69. return _filenameWithSlashes+offset;
  70. }
  71. #endif /* BDREMOTE_DEBUG */
  72. /*@}*/