Instrument Neutral Distributed Interface INDI 2.2.5
indiutility.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2020 by Pawel Soja <[email protected]>
3 Copyright (C) 2015 by Jasem Mutlaq <[email protected]>
4 Copyright (C) 2014 by geehalel <[email protected]>
5
6 Stream Recorder
7
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library 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 GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
22*/
23#pragma once
24
25
26#ifdef __cplusplus
27#include <string>
28#include <cstring>
29#include <sys/stat.h>
30#include <ctime>
31
32#include "indimacros.h"
33#else
34#include <string.h>
35#endif
36
37// C
38#ifdef __cplusplus
39extern "C"
40{
41#endif
46inline static size_t indi_strlcpy(char * dst, const char * src, size_t maxlen)
47{
48 const size_t srclen = strlen(src);
49 if (srclen + 1 < maxlen)
50 {
51 memcpy(dst, src, srclen + 1);
52 }
53 else if (maxlen != 0)
54 {
55 memcpy(dst, src, maxlen - 1);
56 dst[maxlen - 1] = '\0';
57 }
58 return srclen;
59}
60#ifdef __cplusplus
61}
62#endif
63
64// C++
65#ifdef __cplusplus
66
67// JM 2023.11.25: Not available in Vanilla Windows (Visual Studio 2022) but available with MINGW? How does this affect CYGWIN?
68#if defined (_WIN32) && !defined (__MINGW32__)
69typedef int mode_t;
70#endif
71
72namespace INDI
73{
77int mkdir(const char *path, mode_t mode);
78
82int mkpath(std::string path, mode_t mode);
83
87std::string format_time(const std::tm &tm, const char *format);
88
92void replace_all(std::string &subject, const std::string &search, const std::string &replace);
93
98inline size_t strlcpy(char * dst, const char * src, size_t maxlen)
99{
100 return indi_strlcpy(dst, src, maxlen);
101}
102
107template <size_t N>
108inline size_t strlcpy(char (&dst)[N], const char * src)
109{
110 return indi_strlcpy(dst, src, N);
111}
112
113}
114#endif
Namespace to encapsulate INDI client, drivers, and mediator classes.
int mkdir(const char *path, mode_t mode)
std::string format_time(const std::tm &tm, const char *format)
void replace_all(std::string &subject, const std::string &search, const std::string &replace)
int mkpath(std::string s, mode_t mode)