File: os-types.h

package info (click to toggle)
p8-platform 2.1.0.1+dfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 504 kB
  • ctags: 1,296
  • sloc: cpp: 5,674; ansic: 766; makefile: 5
file content (209 lines) | stat: -rw-r--r-- 5,378 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#pragma once
/*
 * This file is part of the libCEC(R) library.
 *
 * libCEC(R) is Copyright (C) 2011-2012 Pulse-Eight Limited.  All rights reserved.
 * libCEC(R) is an original work, containing original code.
 *
 * libCEC(R) is a trademark of Pulse-Eight Limited.
 *
 * This program is dual-licensed; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 *
 * Alternatively, you can license this library under a commercial license,
 * please contact Pulse-Eight Licensing for more information.
 *
 * For more information contact:
 * Pulse-Eight Licensing       <license@pulse-eight.com>
 *     http://www.pulse-eight.com/
 *     http://www.pulse-eight.net/
 */

#define _FILE_OFFSET_BITS 64
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <sys/time.h>
#ifdef __linux__
#include <sys/prctl.h>
#endif
#include <pthread.h>
#include <poll.h>
#include <semaphore.h>
#include <stdint.h>

#include <inttypes.h>
#include <stdint.h>
#include <sys/types.h>
#include <sys/stat.h>
#if defined(__APPLE__)
// for HRESULT
#include <CoreFoundation/CFPlugInCOM.h>
#endif

#define LIBTYPE
#define DECLSPEC

typedef int socket_t;
typedef socket_t tcp_socket_t;
#define INVALID_SOCKET_VALUE        (-1)
typedef socket_t serial_socket_t;
#define INVALID_SERIAL_SOCKET_VALUE (-1)
typedef socket_t chardev_socket_t;
#define INVALID_CHARDEV_SOCKET_VALUE (-1)

typedef long LONG;
#if !defined(__APPLE__)
typedef LONG HRESULT;
#endif

#define _FILE_OFFSET_BITS 64
#define FILE_BEGIN              0
#define FILE_CURRENT            1
#define FILE_END                2

// Success codes
#ifndef S_OK
#define S_OK           0L
#endif

#ifndef S_FALSE
#define S_FALSE        1L
#endif

#ifndef FAILED
#define FAILED(Status) ((HRESULT)(Status)<0)
#endif

#ifndef SUCCEEDED
#define SUCCEEDED(hr) (((HRESULT)(hr)) >= 0)
#endif

// Error codes
#define ERROR_FILENAME_EXCED_RANGE 206L
#define ERROR_INVALID_NAME         123L

#ifndef E_OUTOFMEMORY
#define E_OUTOFMEMORY              0x8007000EL
#endif

#ifndef E_FAIL
#define E_FAIL                     0x8004005EL
#endif

#ifdef TARGET_LINUX
#include <limits.h>
#define MAX_PATH PATH_MAX
#elif defined TARGET_DARWIN || defined __FreeBSD__
#include <sys/syslimits.h>
#define MAX_PATH PATH_MAX
#else
#define MAX_PATH 256
#endif

#if defined(__APPLE__)
  #include <stdio.h> // for fpos_t
  #include <sched.h>
  #include <AvailabilityMacros.h>
  typedef int64_t   off64_t;
  typedef off_t     __off_t;
  typedef off64_t   __off64_t;
  typedef fpos_t fpos64_t;
  #define __stat64 stat
  #define stat64 stat
  #if defined(TARGET_DARWIN_IOS)
    #define statfs64 statfs
  #endif
  #define fstat64 fstat
#elif defined(__FreeBSD__)
  #include <stdio.h> // for fpos_t
  typedef int64_t   off64_t;
  typedef off_t     __off_t;
  typedef off64_t   __off64_t;
  typedef fpos_t fpos64_t;
  #define __stat64 stat
  #define stat64 stat
  #define statfs64 statfs
  #define fstat64 fstat
#else
  #define __stat64 stat64
#endif

#include <string.h>
#define strnicmp(X,Y,N) strncasecmp(X,Y,N)

typedef unsigned char byte;

/* Platform dependent path separator */
#ifndef PATH_SEPARATOR_CHAR
#define PATH_SEPARATOR_CHAR '/'
#define PATH_SEPARATOR_STRING "/"
#endif

#ifdef TARGET_LINUX
// Retrieve the number of milliseconds that have elapsed since the system was started
#include <time.h>
inline unsigned long GetTickCount(void)
{
  struct timespec ts;
  if(clock_gettime(CLOCK_MONOTONIC, &ts) != 0)
  {
    return 0;
  }
  return (unsigned long)( (ts.tv_sec * 1000) + (ts.tv_nsec / 1000000) );
};
#else
#include <time.h>
inline unsigned long GetTickCount(void)
{
  struct timeval tv;
  gettimeofday(&tv, NULL);
  return (unsigned long)( (tv.tv_sec * 1000) + (tv.tv_usec / 1000) );
};
#endif /* TARGET_LINUX || TARGET_DARWIN */

/* Handling of 2-byte Windows wchar strings on non-Windows targets
 * Used by The MediaPortal and ForTheRecord pvr addons 
 */
typedef uint16_t Wchar_t; /* sizeof(wchar_t) = 4 bytes on Linux, but the MediaPortal buffer files have 2-byte wchars */

/* This is a replacement of the Windows wcslen() function which assumes that
 * wchar_t is a 2-byte character.
 * It is used for processing Windows wchar strings
 */
inline size_t WcsLen(const Wchar_t *str)
{
  const unsigned short *eos = (const unsigned short*)str;
  while( *eos++ ) ;
  return( (size_t)(eos - (const unsigned short*)str) -1);
};

/* This is a replacement of the Windows wcstombs() function which assumes that
 * wchar_t is a 2-byte character.
 * It is used for processing Windows wchar strings
 */
inline size_t WcsToMbs(char *s, const Wchar_t *w, size_t n)
{
  size_t i = 0;
  const unsigned short *wc = (const unsigned short*) w;
  while(wc[i] && (i < n))
  {
    s[i] = wc[i];
    ++i;
  }
  if (i < n) s[i] = '\0';

  return (i);
};