PageRenderTime 27ms CodeModel.GetById 15ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/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
24/** \ingroup Gen */
25/*@{*/
26
27/*! \file globaldefs.c
28  \brief Functions used by the macros in globaldefs.h.
29
30  Implements a few functions used by the macros in globaldefs.h.
31*/
32
33#include "globaldefs.h"
34
35#if BDREMOTE_DEBUG
36#  include <assert.h>
37#  include <string.h>
38
39/** Handy macro to extract some part from time_t. */
40#  define getPart(PART) {                       \
41    struct tm* Tm = localtime(_ltime);          \
42    return Tm->PART;                            \
43  }
44
45int getHour(time_t* _ltime)
46{
47  getPart(tm_hour);
48}
49
50int getMinute(time_t* _ltime)
51{
52  getPart(tm_min);
53}
54
55int getSecond(time_t* _ltime)
56{
57  getPart(tm_sec);
58}
59
60const char* bdrGetFilename(const char* _filenameWithSlashes)
61{
62  int offset = 0;
63  int len    = 0;
64  int i      = 0;
65  assert(_filenameWithSlashes != NULL);
66
67  len = strlen(_filenameWithSlashes);
68
69  for (i = len; i >= 0; i--)
70    {
71      if (_filenameWithSlashes[i] == '/')
72	{
73	  offset = i;
74
75	  if ((offset+1) < len)
76	    {
77	      offset++;
78	    }
79	  break;
80	}
81      
82    }
83
84  return _filenameWithSlashes+offset;
85}
86
87#endif /* BDREMOTE_DEBUG */
88
89/*@}*/
90