Translated using Weblate.
[gammu.git] / include / gammu-misc.h
blob0907cd527f20cb4a5aef829bd75a52ab3db9a265
1 /**
2 * \file gammu-misc.h
3 * \author Michal Čihař
5 * Miscellaneous helper functions.
6 */
7 #ifndef __gammu_misc_h
8 #define __gammu_misc_h
10 #ifdef WIN32
11 # define WIN32_LEAN_AND_MEAN
12 # include <windows.h>
13 #endif
15 #include <stdio.h>
16 #include <gammu-file.h>
17 #include <gammu-config.h>
18 #if defined(HAVE_UNISTD_H)
19 # include <unistd.h>
20 #endif
22 /**
23 * Reads single line from file.
25 * \param File File descriptor to read from.
26 * \param Line Buffer where t ostore result.
27 * \param count Maximal length of text which can be stored in buffer.
29 * \return Length of read line, -1 on error.
31 int GetLine(FILE * File, char *Line, int count);
33 /**
34 * Gets Gammu library version.
36 const char *GetGammuVersion(void);
38 /**
39 * Gets compiler which was used to compile Gammu library.
41 const char *GetCompiler(void);
43 /**
44 * Gets host OS.
46 const char *GetOS(void);
48 /**
49 * Returns path to Gammu locales.
51 const char *GetGammuLocalePath(void);
53 /**
54 * Initializes locales. This sets up things needed for proper string
55 * conversion from local charset as well as initializes gettext based
56 * translation.
58 * \param path Path to gettext translation. If NULL compiled in default
59 * is used.
61 extern void GSM_InitLocales(const char *path);
63 #undef MAX
64 #define MAX(a,b) ((a)>(b) ? (a) : (b))
65 #undef MIN
66 #define MIN(a,b) ((a)<(b) ? (a) : (b))
68 #ifdef WIN32
69 # if !defined(HAVE_UNISTD_H) || defined(__MINGW32__)
70 # define sleep(x) Sleep((x) * 1000)
71 # define usleep(x) Sleep(((x) < 1000) ? 1 : ((x) / 1000))
72 # endif /* HAVE_UNISTD_H */
73 #endif
75 /* Easy check for GCC */
76 #if defined __GNUC__ && defined __GNUC_MINOR__
77 # define GSM_GNUC_PREREQ(maj, min) \
78 ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
79 #else
80 # define GSM_GNUC_PREREQ(maj, min) 0
81 #endif
83 /* Various hints for compilers */
84 #if GSM_GNUC_PREREQ (2,8) || defined(__clang__)
85 #define PRINTF_STYLE(f, a) __attribute__ ((format(__printf__, f, a)))
86 #define SCANF_STYLE(f, a) __attribute__ ((format(__scanf__, f, a)))
87 #else
88 #define PRINTF_STYLE(f, a)
89 #define SCANF_STYLE(f, a)
90 #endif
92 #if GSM_GNUC_PREREQ (3,4) || defined(__clang__)
93 #define WARNUNUSED __attribute__ ((__warn_unused_result__))
94 #else
95 #define WARNUNUSED
96 #endif
98 #if GSM_GNUC_PREREQ (3,1) || defined(__clang__)
99 #define UNUSED __attribute__ ((unused))
100 #else
101 #define UNUSED
102 #endif
104 #if defined(__GNUC__) || defined(__clang__)
105 #define NORETURN __attribute__((__noreturn__))
106 #else
107 #define NORETURN
108 #endif
110 /* Clang has bug in handling inline functions */
111 #if defined(__GNUC__) && !defined(__clang__)
112 #define INLINE inline
113 #else
114 #define INLINE
115 #endif
117 /* Working snprintf on MSVC */
118 #ifdef _MSC_VER
119 #define snprintf _snprintf
120 #endif
122 /* Working __FUNCTION__ on BCC */
123 #ifndef HAVE_MACRO_FUNCTION
124 # ifdef HAVE_MACRO_FUNC
125 # define __FUNCTION__ __FUNC__
126 # define __FUNCTION__WORKING
127 # else
128 # define __FUNCTION__ "unknown"
129 # endif
130 #else
131 # define __FUNCTION__WORKING
132 #endif
134 /* strtoull for BCC (and maybe others) */
135 #ifndef HAVE_STRTOULL
136 /* MSVC provides same function under different name */
137 #if _MSC_VER >= 1300
138 #include <stdlib.h>
139 #define strtoull _strtoui64
140 #else
141 #define strtoull(A,B,C) strtoul((A),(B),(C))
142 #endif
143 #endif
145 /* ssize_t for compilers where it does not exist (BCC) */
146 #ifndef HAVE_SSIZE_T
147 typedef long ssize_t;
148 #endif
150 /* intptr_t for compilers where it does not exist (BCC) */
151 #ifndef HAVE_INTPTR_T
152 typedef int intptr_t;
153 #endif
156 * Encodes text to hexadecimal binary representation.
158 void EncodeHexBin(char *dest, const unsigned char *src, size_t len);
161 * Returns TRUE if firmware version is newer.
163 * \param latest_version String containing version (eg. latest available).
164 * \param current_version String containing version (eg. current one).
166 * \return True if latest_version > current_version.
168 gboolean GSM_IsNewerVersion(const char *latest_version,
169 const char *current_version);
170 #endif
172 /* Editor configuration
173 * vim: noexpandtab sw=8 ts=8 sts=8 tw=72: