Instrument Neutral Distributed Interface INDI  2.0.2
indiutility.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2020 by Pawel Soja <kernel32.pl@gmail.com>
3  Copyright (C) 2015 by Jasem Mutlaq <mutlaqja@ikarustech.com>
4  Copyright (C) 2014 by geehalel <geehalel@gmail.com>
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
39 extern "C"
40 {
41 #endif
46 inline 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 #ifdef _WINDOWS
68 typedef int mode_t;
69 #endif
70 
71 namespace INDI
72 {
76 int mkdir(const char *path, mode_t mode);
77 
81 int mkpath(std::string path, mode_t mode);
82 
86 std::string format_time(const std::tm &tm, const char *format);
87 
91 void replace_all(std::string &subject, const std::string &search, const std::string &replace);
92 
97 inline size_t strlcpy(char * dst, const char * src, size_t maxlen)
98 {
99  return indi_strlcpy(dst, src, maxlen);
100 }
101 
106 template <size_t N>
107 inline size_t strlcpy(char (&dst)[N], const char * src)
108 {
109  return indi_strlcpy(dst, src, N);
110 }
111 
112 }
113 #endif
Namespace to encapsulate INDI client, drivers, and mediator classes.
int mkdir(const char *path, mode_t mode)
Definition: indiutility.cpp:41
std::string format_time(const std::tm &tm, const char *format)
Definition: indiutility.cpp:86
void replace_all(std::string &subject, const std::string &search, const std::string &replace)
Definition: indiutility.cpp:95
int mkpath(std::string s, mode_t mode)
Definition: indiutility.cpp:51