summaryrefslogtreecommitdiff
path: root/os_compat.h
blob: 4dbe9de334dfc5e7b43771fe7e8b729d7b81acce (plain)
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
/*
 * This file is Copyright (c) 2017 by the GPSD project
 * BSD terms apply: see the file COPYING in the distribution root for details.
 *
 * This is the header for os_compat.c, which contains functions dealing with
 * compatibility issues across OSes.
 */
#ifndef _GPSD_OS_COMPAT_H_
#define _GPSD_OS_COMPAT_H_

/* Determine which of these functions we need */
#include "gpsd_config.h"

# ifdef __cplusplus
extern "C" {
# endif

#ifndef HAVE_CLOCK_GETTIME

#include <time.h>

#ifndef CLOCKID_T_DEFINED
typedef int clockid_t;
#define CLOCKID_T_DEFINED
#endif /* !CLOCKID_T_DEFINED */

/*
 * OS X 10.5 and later use _STRUCT_TIMESPEC (like other OSes)
 * 10.4 uses _TIMESPEC
 * 10.3 and earlier use _TIMESPEC_DECLARED
 */
#if !defined(_STRUCT_TIMESPEC) && \
    !defined(_TIMESPEC) && \
    !defined(_TIMESPEC_DECLARED) && \
    !defined(__timespec_defined)
#define _STRUCT_TIMESPEC
struct timespec {
    time_t  tv_sec;
    long    tv_nsec;
};
#endif /* !_STRUCT_TIMESPEC ... */

/* OS X does not have clock_gettime */
#define CLOCK_REALTIME 0
int clock_gettime(clockid_t, struct timespec *);

#endif /* !HAVE_CLOCK_GETTIME */

#ifndef HAVE_STRLCAT

#include <string.h>
size_t strlcat(char *dst, const char *src, size_t size);

#endif /* !HAVE_STRLCAT */

#ifndef HAVE_STRLCPY

#include <string.h>
size_t strlcpy(char *dst, const char *src, size_t size);

#endif /* !HAVE_STRLCPY */

# ifdef __cplusplus
}
# endif

#endif /* _GPSD_OS_COMPAT_H_ */