GDAL

cpl_conv.h
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * Project: CPL - Common Portability Library
4 * Purpose: Convenience functions declarations.
5 * This is intended to remain light weight.
6 * Author: Frank Warmerdam, warmerdam@pobox.com
7 *
8 ******************************************************************************
9 * Copyright (c) 1998, Frank Warmerdam
10 * Copyright (c) 2007-2013, Even Rouault <even dot rouault at spatialys.com>
11 *
12 * SPDX-License-Identifier: MIT
13 ****************************************************************************/
14
15#ifndef CPL_CONV_H_INCLUDED
16#define CPL_CONV_H_INCLUDED
17
18#include "cpl_port.h"
19#include "cpl_vsi.h"
20#include "cpl_error.h"
21
22#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
23#include <cstdint>
24#endif
25
33/* -------------------------------------------------------------------- */
34/* Runtime check of various configuration items. */
35/* -------------------------------------------------------------------- */
36 CPL_C_START
37
39 void CPL_DLL CPLVerifyConfiguration(void);
42 bool CPL_DLL CPLIsDebugEnabled(void);
43
44 const char CPL_DLL *CPL_STDCALL CPLGetConfigOption(const char *, const char *)
45 CPL_WARN_UNUSED_RESULT;
46 const char CPL_DLL *CPL_STDCALL CPLGetThreadLocalConfigOption(
47 const char *, const char *) CPL_WARN_UNUSED_RESULT;
48 const char CPL_DLL *CPL_STDCALL
49 CPLGetGlobalConfigOption(const char *, const char *) CPL_WARN_UNUSED_RESULT;
50 void CPL_DLL CPL_STDCALL CPLSetConfigOption(const char *, const char *);
51 void CPL_DLL CPL_STDCALL CPLSetThreadLocalConfigOption(const char *pszKey,
52 const char *pszValue);
53 void CPL_DLL CPLDeclareKnownConfigOption(const char *pszKey,
54 const char *pszDefinition);
55 char CPL_DLL **CPLGetKnownConfigOptions(void);
56
58 typedef void (*CPLSetConfigOptionSubscriber)(const char *pszKey,
59 const char *pszValue,
60 bool bThreadLocal,
61 void *pUserData);
62 int CPL_DLL CPLSubscribeToSetConfigOption(
63 CPLSetConfigOptionSubscriber pfnCallback, void *pUserData);
64 void CPL_DLL CPLUnsubscribeToSetConfigOption(int nSubscriberId);
65
67 void CPL_DLL CPL_STDCALL CPLFreeConfig(void);
69 char CPL_DLL **CPLGetConfigOptions(void);
70 void CPL_DLL CPLSetConfigOptions(const char *const *papszConfigOptions);
71 char CPL_DLL **CPLGetThreadLocalConfigOptions(void);
72 void CPL_DLL
73 CPLSetThreadLocalConfigOptions(const char *const *papszConfigOptions);
74 void CPL_DLL CPLLoadConfigOptionsFromFile(const char *pszFilename,
75 int bOverrideEnvVars);
76 void CPL_DLL CPLLoadConfigOptionsFromPredefinedFiles(void);
77
78/* -------------------------------------------------------------------- */
79/* Safe malloc() API. Thin cover over VSI functions with fatal */
80/* error reporting if memory allocation fails. */
81/* -------------------------------------------------------------------- */
82 void CPL_DLL *CPLMalloc(size_t) CPL_WARN_UNUSED_RESULT;
83 void CPL_DLL *CPLCalloc(size_t, size_t) CPL_WARN_UNUSED_RESULT;
84 void CPL_DLL *CPLRealloc(void *, size_t) CPL_WARN_UNUSED_RESULT;
85 char CPL_DLL *
86 CPLStrdup(const char *) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
87 char CPL_DLL *CPLStrlwr(char *);
88
90#define CPLFree VSIFree
91
92/* -------------------------------------------------------------------- */
93/* Read a line from a text file, and strip of CR/LF. */
94/* -------------------------------------------------------------------- */
95 char CPL_DLL *CPLFGets(char *, int, FILE *);
96 const char CPL_DLL *CPLReadLine(FILE *);
97 const char CPL_DLL *CPLReadLineL(VSILFILE *);
98 const char CPL_DLL *CPLReadLine2L(VSILFILE *, int, CSLConstList);
99 const char CPL_DLL *CPLReadLine3L(VSILFILE *, int, int *, CSLConstList);
100
101/* -------------------------------------------------------------------- */
102/* Convert ASCII string to floating point number */
103/* (THESE FUNCTIONS ARE NOT LOCALE AWARE!). */
104/* -------------------------------------------------------------------- */
105 double CPL_DLL CPLAtof(const char *);
106 double CPL_DLL CPLAtofDelim(const char *, char);
107 double CPL_DLL CPLStrtod(const char *, char **);
108 double CPL_DLL CPLStrtodM(const char *, char **);
109 double CPL_DLL CPLStrtodDelim(const char *, char **, char);
110 float CPL_DLL CPLStrtof(const char *, char **);
111 float CPL_DLL CPLStrtofDelim(const char *, char **, char);
112
113/* -------------------------------------------------------------------- */
114/* Convert number to string. This function is locale agnostic */
115/* (i.e. it will support "," or "." regardless of current locale) */
116/* -------------------------------------------------------------------- */
117 double CPL_DLL CPLAtofM(const char *);
118
119/* -------------------------------------------------------------------- */
120/* Read a numeric value from an ASCII character string. */
121/* -------------------------------------------------------------------- */
122 char CPL_DLL *CPLScanString(const char *, int, int, int);
123 double CPL_DLL CPLScanDouble(const char *, int);
124 long CPL_DLL CPLScanLong(const char *, int);
125 unsigned long CPL_DLL CPLScanULong(const char *, int);
126 GUIntBig CPL_DLL CPLScanUIntBig(const char *, int);
127 GIntBig CPL_DLL CPLAtoGIntBig(const char *pszString);
128 GIntBig CPL_DLL CPLAtoGIntBigEx(const char *pszString, int bWarn,
129 int *pbOverflow);
130 void CPL_DLL *CPLScanPointer(const char *, int);
131
132/* -------------------------------------------------------------------- */
133/* Print a value to an ASCII character string. */
134/* -------------------------------------------------------------------- */
135 int CPL_DLL CPLPrintString(char *, const char *, int);
136 int CPL_DLL CPLPrintStringFill(char *, const char *, int);
137 int CPL_DLL CPLPrintInt32(char *, GInt32, int);
138 int CPL_DLL CPLPrintUIntBig(char *, GUIntBig, int);
139 int CPL_DLL CPLPrintDouble(char *, const char *, double, const char *);
140 int CPL_DLL CPLPrintTime(char *, int, const char *, const struct tm *,
141 const char *);
142 int CPL_DLL CPLPrintPointer(char *, void *, int);
143
144#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
145 extern "C++"
146{
147 std::string CPL_DLL CPLFormatReadableFileSize(uint64_t nSizeInBytes);
148 std::string CPL_DLL CPLFormatReadableFileSize(double dfSizeInBytes);
149}
150#endif
151
152/* -------------------------------------------------------------------- */
153/* Fetch a function from DLL / so. */
154/* -------------------------------------------------------------------- */
155
156 void CPL_DLL *CPLGetSymbol(const char *, const char *);
157
158/* -------------------------------------------------------------------- */
159/* Fetch executable path. */
160/* -------------------------------------------------------------------- */
161 int CPL_DLL CPLGetExecPath(char *pszPathBuf, int nMaxLength);
162
163/* -------------------------------------------------------------------- */
164/* Filename handling functions. */
165/* -------------------------------------------------------------------- */
166
167#if defined(DOXYGEN_SKIP) || !defined(__cplusplus) || \
168 !defined(GDAL_COMPILATION) || \
169 (defined(__cplusplus) && defined(ALLOW_DEPRECATED_CPL_PATH_FUNCTIONS))
170 const char CPL_DLL *
171 CPLGetPath(const char *) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
172 const char CPL_DLL *
173 CPLGetDirname(const char *) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
174 const char CPL_DLL *
175 CPLGetBasename(const char *) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
176 const char CPL_DLL *
177 CPLGetExtension(const char *) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
178 const char CPL_DLL *CPLFormFilename(
179 const char *pszPath, const char *pszBasename,
180 const char *pszExtension) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
181 const char CPL_DLL *CPLFormCIFilename(
182 const char *pszPath, const char *pszBasename,
183 const char *pszExtension) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
184 const char CPL_DLL *CPLResetExtension(const char *, const char *)
185 CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
186 const char CPL_DLL *CPLProjectRelativeFilename(const char *pszProjectDir,
187 const char *pszSecondaryFilename)
188 CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
189 const char CPL_DLL *
190 CPLCleanTrailingSlash(const char *) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
191 const char CPL_DLL *CPLGenerateTempFilename(const char *pszStem)
192 CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
193 const char CPL_DLL *CPLExpandTilde(const char *pszFilename)
194 CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
195 const char CPL_DLL *
196 CPLLaunderForFilename(const char *pszName,
197 const char *pszOutputPath) CPL_WARN_UNUSED_RESULT;
198#endif
199
200 char CPL_DLL *CPLGetCurrentDir(void);
201 const char CPL_DLL *
202 CPLGetFilename(const char *) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
203 int CPL_DLL CPLIsFilenameRelative(const char *pszFilename);
204 const char CPL_DLL *CPLExtractRelativePath(const char *, const char *, int *)
205 CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
206 char CPL_DLL **
207 CPLCorrespondingPaths(const char *pszOldFilename, const char *pszNewFilename,
208 CSLConstList papszFileList) CPL_WARN_UNUSED_RESULT;
209 int CPL_DLL CPLCheckForFile(char *pszFilename, CSLConstList papszSiblingList);
210
211 const char CPL_DLL *CPLGetHomeDir(void) CPL_WARN_UNUSED_RESULT;
212
213#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
214
215 extern "C++"
216{
217 std::string CPL_DLL CPLGetPathSafe(const char *) CPL_WARN_UNUSED_RESULT;
218 std::string CPL_DLL CPLGetDirnameSafe(const char *) CPL_WARN_UNUSED_RESULT;
219 std::string CPL_DLL CPLGetBasenameSafe(const char *) CPL_WARN_UNUSED_RESULT;
220 std::string CPL_DLL CPLGetExtensionSafe(const char *)
221 CPL_WARN_UNUSED_RESULT;
222 std::string CPL_DLL CPLFormFilenameSafe(
223 const char *pszPath, const char *pszBasename,
224 const char *pszExtension = nullptr) CPL_WARN_UNUSED_RESULT;
225 std::string CPL_DLL CPLFormCIFilenameSafe(
226 const char *pszPath, const char *pszBasename,
227 const char *pszExtension = nullptr) CPL_WARN_UNUSED_RESULT;
228 std::string CPL_DLL CPLResetExtensionSafe(const char *, const char *)
229 CPL_WARN_UNUSED_RESULT;
230 std::string CPL_DLL CPLProjectRelativeFilenameSafe(
231 const char *pszProjectDir,
232 const char *pszSecondaryFilename) CPL_WARN_UNUSED_RESULT;
233 std::string CPL_DLL CPLCleanTrailingSlashSafe(const char *pszPath)
234 CPL_WARN_UNUSED_RESULT;
235 std::string CPL_DLL CPLGenerateTempFilenameSafe(const char *pszStem)
236 CPL_WARN_UNUSED_RESULT;
237 std::string CPL_DLL CPLExpandTildeSafe(const char *pszFilename)
238 CPL_WARN_UNUSED_RESULT;
239 std::string CPL_DLL CPLLaunderForFilenameSafe(
240 const char *pszName, const char *pszOutputPath) CPL_WARN_UNUSED_RESULT;
241
242#if defined(GDAL_COMPILATION) || __cplusplus >= 201703L
243 std::string CPL_DLL CPLLexicallyNormalize(std::string_view svPath,
244 char sep1, char sep2 = 0)
245 CPL_WARN_UNUSED_RESULT;
246#endif
247}
248
249#endif // defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
250
251 bool CPL_DLL CPLHasPathTraversal(const char *pszFilename);
252 bool CPL_DLL CPLHasUnbalancedPathTraversal(const char *pszFilename);
253
254/* -------------------------------------------------------------------- */
255/* Find File Function */
256/* -------------------------------------------------------------------- */
257
259 typedef char const *(*CPLFileFinder)(const char *, const char *);
260
261 const char CPL_DLL *CPLFindFile(const char *pszClass, const char *pszBasename);
262 const char CPL_DLL *CPLDefaultFindFile(const char *pszClass,
263 const char *pszBasename);
264 void CPL_DLL CPLPushFileFinder(CPLFileFinder pfnFinder);
265 CPLFileFinder CPL_DLL CPLPopFileFinder(void);
266 void CPL_DLL CPLPushFinderLocation(const char *);
267 void CPL_DLL CPLPopFinderLocation(void);
268 void CPL_DLL CPLFinderClean(void);
269
270/* -------------------------------------------------------------------- */
271/* Safe version of stat() that works properly on stuff like "C:". */
272/* -------------------------------------------------------------------- */
273 int CPL_DLL CPLStat(const char *, VSIStatBuf *) CPL_WARN_UNUSED_RESULT;
274
275/* -------------------------------------------------------------------- */
276/* Reference counted file handle manager. Makes sharing file */
277/* handles more practical. */
278/* -------------------------------------------------------------------- */
279
281 typedef struct
282{
283 FILE *fp;
284 int nRefCount;
285 int bLarge;
286 char *pszFilename;
287 char *pszAccess;
288} CPLSharedFileInfo;
289
290FILE CPL_DLL *CPLOpenShared(const char *, const char *, int);
291 void CPL_DLL CPLCloseShared(FILE *);
292 CPLSharedFileInfo CPL_DLL *CPLGetSharedList(int *);
293 void CPL_DLL CPLDumpSharedList(FILE *);
295 void CPL_DLL CPLCleanupSharedFileMutex(void);
298/* -------------------------------------------------------------------- */
299/* DMS to Dec to DMS conversion. */
300/* -------------------------------------------------------------------- */
301 double CPL_DLL CPLDMSToDec(const char *is);
302 const char CPL_DLL *CPLDecToDMS(double dfAngle, const char *pszAxis,
303 int nPrecision);
304 double CPL_DLL CPLPackedDMSToDec(double);
305 double CPL_DLL CPLDecToPackedDMS(double dfDec);
306
307 CPLErr CPL_DLL CPLStringToComplex(const char *pszString, double *pdfReal,
308 double *pdfImag);
309
310/* -------------------------------------------------------------------- */
311/* Misc other functions. */
312/* -------------------------------------------------------------------- */
313 int CPL_DLL CPLUnlinkTree(const char *);
314 int CPL_DLL CPLCopyFile(const char *pszNewPath, const char *pszOldPath);
315 int CPL_DLL CPLCopyTree(const char *pszNewPath, const char *pszOldPath);
316 int CPL_DLL CPLMoveFile(const char *pszNewPath, const char *pszOldPath);
317 int CPL_DLL CPLSymlink(const char *pszOldPath, const char *pszNewPath,
318 CSLConstList papszOptions);
319 int CPL_DLL CPLGetRemainingFileDescriptorCount(void);
320
321/* -------------------------------------------------------------------- */
322/* Lock related functions. */
323/* -------------------------------------------------------------------- */
324
326 typedef enum
327{
328 CLFS_OK,
329 CLFS_CANNOT_CREATE_LOCK,
330 CLFS_LOCK_BUSY,
331 CLFS_API_MISUSE,
332 CLFS_THREAD_CREATION_FAILED,
333} CPLLockFileStatus;
334
336 typedef struct CPLLockFileStruct *CPLLockFileHandle;
337
338 CPLLockFileStatus CPL_DLL CPLLockFileEx(const char *pszLockFileName,
339 CPLLockFileHandle *phLockFileHandle,
340 CSLConstList papszOptions);
341
342 void CPL_DLL CPLUnlockFileEx(CPLLockFileHandle hLockFileHandle);
343
344/* -------------------------------------------------------------------- */
345/* ZIP Creation. */
346/* -------------------------------------------------------------------- */
347
349#define CPL_ZIP_API_OFFERED
351 void CPL_DLL *CPLCreateZip(const char *pszZipFilename, char **papszOptions);
352 CPLErr CPL_DLL CPLCreateFileInZip(void *hZip, const char *pszFilename,
353 char **papszOptions);
354 CPLErr CPL_DLL CPLWriteFileInZip(void *hZip, const void *pBuffer,
355 int nBufferSize);
356 CPLErr CPL_DLL CPLCloseFileInZip(void *hZip);
357 CPLErr CPL_DLL CPLAddFileInZip(void *hZip, const char *pszArchiveFilename,
358 const char *pszInputFilename, VSILFILE *fpInput,
359 CSLConstList papszOptions,
360 GDALProgressFunc pProgressFunc,
361 void *pProgressData);
362 CPLErr CPL_DLL CPLCloseZip(void *hZip);
363
364/* -------------------------------------------------------------------- */
365/* ZLib compression */
366/* -------------------------------------------------------------------- */
367
368 void CPL_DLL *CPLZLibDeflate(const void *ptr, size_t nBytes, int nLevel,
369 void *outptr, size_t nOutAvailableBytes,
370 size_t *pnOutBytes);
371 void CPL_DLL *CPLZLibInflate(const void *ptr, size_t nBytes, void *outptr,
372 size_t nOutAvailableBytes, size_t *pnOutBytes);
373 void CPL_DLL *CPLZLibInflateEx(const void *ptr, size_t nBytes, void *outptr,
374 size_t nOutAvailableBytes,
375 bool bAllowResizeOutptr, size_t *pnOutBytes);
376
377/* -------------------------------------------------------------------- */
378/* XML validation. */
379/* -------------------------------------------------------------------- */
380 int CPL_DLL CPLValidateXML(const char *pszXMLFilename,
381 const char *pszXSDFilename,
382 CSLConstList papszOptions);
383
384/* -------------------------------------------------------------------- */
385/* Locale handling. Prevents parallel executions of setlocale(). */
386/* -------------------------------------------------------------------- */
387 char *CPLsetlocale(int category, const char *locale);
389 void CPLCleanupSetlocaleMutex(void);
397 int CPL_DLL CPLIsPowerOfTwo(unsigned int i);
398
399/* -------------------------------------------------------------------- */
400/* Terminal related */
401/* -------------------------------------------------------------------- */
402
403 bool CPL_DLL CPLIsInteractive(FILE *f);
404
405 CPL_C_END
406
407/* -------------------------------------------------------------------- */
408/* C++ object for temporarily forcing a LC_NUMERIC locale to "C". */
409/* -------------------------------------------------------------------- */
410
412#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
413
414 extern "C++"
415{
416 class CPL_DLL CPLLocaleC
417 {
418 CPL_DISALLOW_COPY_ASSIGN(CPLLocaleC)
419 public:
420 CPLLocaleC();
421 ~CPLLocaleC();
422
423 private:
424 char *pszOldLocale;
425 };
426
427 // Does the same as CPLLocaleC except that, when available, it tries to
428 // only affect the current thread. But code that would be dependent of
429 // setlocale(LC_NUMERIC, NULL) returning "C", such as current proj.4
430 // versions, will not work depending on the actual implementation
431 class CPLThreadLocaleCPrivate;
432
433 class CPL_DLL CPLThreadLocaleC
434 {
435 CPL_DISALLOW_COPY_ASSIGN(CPLThreadLocaleC)
436
437 public:
438 CPLThreadLocaleC();
439 ~CPLThreadLocaleC();
440
441 private:
442 CPLThreadLocaleCPrivate *m_private;
443 };
444}
445
446#endif /* def __cplusplus */
448
449/* -------------------------------------------------------------------- */
450/* C++ object for temporarily forcing a config option */
451/* -------------------------------------------------------------------- */
452
454#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
455
456 extern "C++"
457{
458 class CPL_DLL CPLConfigOptionSetter
459 {
460 CPL_DISALLOW_COPY_ASSIGN(CPLConfigOptionSetter)
461 public:
462 CPLConfigOptionSetter(const char *pszKey, const char *pszValue,
463 bool bSetOnlyIfUndefined);
464 ~CPLConfigOptionSetter();
465
466 private:
467 char *m_pszKey;
468 char *m_pszOldValue;
469 bool m_bRestoreOldValue;
470 };
471}
472
473#endif /* def __cplusplus */
475
476#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
477
478 extern "C++"
479{
480
481#ifndef DOXYGEN_SKIP
482#include <type_traits> // for std::is_base_of
483#endif
484
485 namespace cpl
486 {
496 template <typename To, typename From> inline To down_cast(From *f)
497 {
498 static_assert(
499 (std::is_base_of<From,
500 typename std::remove_pointer<To>::type>::value),
501 "target type not derived from source type");
502 CPLAssert(f == nullptr || dynamic_cast<To>(f) != nullptr);
503 return static_cast<To>(f);
504 }
505
507 template <class T, class U> inline T div_round_up(T a, U b)
508 {
509 return a / b + (((a % b) == 0) ? 0 : 1);
510 }
511
512 } // namespace cpl
513} // extern "C++"
514
515#endif /* def __cplusplus */
516
517#endif /* ndef CPL_CONV_H_INCLUDED */
CPLFormatReadableFileSize
std::string CPLFormatReadableFileSize(uint64_t nSizeInBytes)
Return a file size in a human readable way.
Definition cpl_conv.cpp:3956
CPLGenerateTempFilenameSafe
std::string CPLGenerateTempFilenameSafe(const char *pszStem)
Generate temporary file name.
Definition cpl_path.cpp:1459
CPLGetHomeDir
const char * CPLGetHomeDir(void)
Return the path to the home directory.
Definition cpl_path.cpp:1576
CPLExpandTilde
const char * CPLExpandTilde(const char *pszFilename)
Expands ~/ at start of filename.
Definition cpl_path.cpp:1555
CPLDeclareKnownConfigOption
void CPLDeclareKnownConfigOption(const char *pszKey, const char *pszDefinition)
Declare that the specified configuration option is known.
Definition cpl_conv.cpp:1974
CPLSetConfigOptionSubscriber
void(* CPLSetConfigOptionSubscriber)(const char *pszKey, const char *pszValue, bool bThreadLocal, void *pUserData)
Callback for CPLSubscribeToSetConfigOption()
Definition cpl_conv.h:58
CPLCreateZip
void * CPLCreateZip(const char *pszZipFilename, char **papszOptions)
Create ZIP file.
Definition cpl_conv.cpp:3607
CPLAtofDelim
double CPLAtofDelim(const char *, char)
Converts ASCII string to floating point number.
Definition cpl_strtod.cpp:58
CPLPrintStringFill
int CPLPrintStringFill(char *, const char *, int)
Copy the string pointed to by pszSrc, NOT including the terminating ‘\0’ character,...
Definition cpl_conv.cpp:1274
CPLGetSymbol
void * CPLGetSymbol(const char *, const char *)
Fetch a function pointer from a shared library / DLL.
Definition cplgetsymbol.cpp:74
CPLIsFilenameRelative
int CPLIsFilenameRelative(const char *pszFilename)
Is filename relative or absolute?
Definition cpl_path.cpp:1116
CPLFormCIFilenameSafe
std::string CPLFormCIFilenameSafe(const char *pszPath, const char *pszBasename, const char *pszExtension=nullptr)
Case insensitive file searching, returning full path.
Definition cpl_path.cpp:899
CPLReadLine2L
const char * CPLReadLine2L(VSILFILE *, int, CSLConstList)
Simplified line reading from text file.
Definition cpl_conv.cpp:680
CPLLaunderForFilenameSafe
std::string CPLLaunderForFilenameSafe(const char *pszName, const char *pszOutputPath)
Launder a string to be compatible of a filename.
Definition cpl_path.cpp:1601
CPLPrintUIntBig
int CPLPrintUIntBig(char *, GUIntBig, int)
Print GUIntBig value into specified string buffer.
Definition cpl_conv.cpp:1357
CPLProjectRelativeFilenameSafe
std::string CPLProjectRelativeFilenameSafe(const char *pszProjectDir, const char *pszSecondaryFilename)
Find a file relative to a project file.
Definition cpl_path.cpp:1038
CPLCopyTree
int CPLCopyTree(const char *pszNewPath, const char *pszOldPath)
Recursively copy a tree.
Definition cpl_conv.cpp:3221
CPLCloseShared
void CPLCloseShared(FILE *)
Close shared file.
Definition cpl_conv.cpp:2978
CPLStrtof
float CPLStrtof(const char *, char **)
Converts ASCII string to floating point number.
Definition cpl_strtod.cpp:496
CPLsetlocale
char * CPLsetlocale(int category, const char *locale)
Prevents parallel executions of setlocale().
Definition cpl_conv.cpp:3508
CPLReadLine3L
const char * CPLReadLine3L(VSILFILE *, int, int *, CSLConstList)
Simplified line reading from text file.
Definition cpl_conv.cpp:707
CPLStrtod
double CPLStrtod(const char *, char **)
Converts ASCII string to floating point number.
Definition cpl_strtod.cpp:388
cpl::div_round_up
T div_round_up(T a, U b)
Computes ceil(a/b) where a and b are integers.
Definition cpl_conv.h:507
CPLLockFileHandle
struct CPLLockFileStruct * CPLLockFileHandle
Handle type returned by CPLLockFileEx().
Definition cpl_conv.h:336
CPLGetExtension
const char * CPLGetExtension(const char *)
Extract filename extension from full filename.
Definition cpl_path.cpp:549
CPLLoadConfigOptionsFromFile
void CPLLoadConfigOptionsFromFile(const char *pszFilename, int bOverrideEnvVars)
Load configuration from a given configuration file.
Definition cpl_conv.cpp:2293
CPLMoveFile
int CPLMoveFile(const char *pszNewPath, const char *pszOldPath)
Move a file.
Definition cpl_conv.cpp:3296
CPLGetExtensionSafe
std::string CPLGetExtensionSafe(const char *)
Extract filename extension from full filename.
Definition cpl_path.cpp:498
CPLResetExtensionSafe
std::string CPLResetExtensionSafe(const char *, const char *)
Replace the extension with the provided one.
Definition cpl_path.cpp:620
CPLExpandTildeSafe
std::string CPLExpandTildeSafe(const char *pszFilename)
Expands ~/ at start of filename.
Definition cpl_path.cpp:1525
CPLGetBasenameSafe
std::string CPLGetBasenameSafe(const char *)
Extract basename (non-directory, non-extension) portion of filename.
Definition cpl_path.cpp:423
CPLGetThreadLocalConfigOptions
char ** CPLGetThreadLocalConfigOptions(void)
Return the list of thread local configuration options as KEY=VALUE pairs.
Definition cpl_conv.cpp:2173
CPLLockFileEx
CPLLockFileStatus CPLLockFileEx(const char *pszLockFileName, CPLLockFileHandle *phLockFileHandle, CSLConstList papszOptions)
Create and acquire a lock file.
Definition cpl_conv.cpp:3775
CPLPrintInt32
int CPLPrintInt32(char *, GInt32, int)
Print GInt32 value into specified string buffer.
Definition cpl_conv.cpp:1318
CPLScanLong
long CPLScanLong(const char *, int)
Scan up to a maximum number of characters from a string and convert the result to a long.
Definition cpl_conv.cpp:936
CPLGetDirnameSafe
std::string CPLGetDirnameSafe(const char *)
Extract directory path portion of filename.
Definition cpl_path.cpp:274
CPLSetConfigOptions
void CPLSetConfigOptions(const char *const *papszConfigOptions)
Replace the full list of configuration options with the passed list of KEY=VALUE pairs.
Definition cpl_conv.cpp:1771
CPLRealloc
void * CPLRealloc(void *, size_t)
Safe version of realloc().
Definition cpl_conv.cpp:247
CPLFileFinder
char const *(* CPLFileFinder)(const char *, const char *)
Callback for CPLPushFileFinder.
Definition cpl_conv.h:259
CPLStrtofDelim
float CPLStrtofDelim(const char *, char **, char)
Converts ASCII string to floating point number using specified delimiter.
Definition cpl_strtod.cpp:452
CPLCorrespondingPaths
char ** CPLCorrespondingPaths(const char *pszOldFilename, const char *pszNewFilename, CSLConstList papszFileList)
Identify corresponding paths.
Definition cpl_path.cpp:1320
CPLZLibInflate
void * CPLZLibInflate(const void *ptr, size_t nBytes, void *outptr, size_t nOutAvailableBytes, size_t *pnOutBytes)
Uncompress a buffer compressed with ZLib compression.
Definition cpl_conv.cpp:3643
CPLSymlink
int CPLSymlink(const char *pszOldPath, const char *pszNewPath, CSLConstList papszOptions)
Create a symbolic link.
Definition cpl_conv.cpp:3326
CPLGetBasename
const char * CPLGetBasename(const char *)
Extract basename (non-directory, non-extension) portion of filename.
Definition cpl_path.cpp:468
CPLLaunderForFilename
const char * CPLLaunderForFilename(const char *pszName, const char *pszOutputPath)
Launder a string to be compatible of a filename.
Definition cpl_path.cpp:1634
CPLMalloc
void * CPLMalloc(size_t)
Safe version of malloc().
Definition cpl_conv.cpp:192
CPLGetDirname
const char * CPLGetDirname(const char *)
Extract directory path portion of filename.
Definition cpl_path.cpp:362
CPLAddFileInZip
CPLErr CPLAddFileInZip(void *hZip, const char *pszArchiveFilename, const char *pszInputFilename, VSILFILE *fpInput, CSLConstList papszOptions, GDALProgressFunc pProgressFunc, void *pProgressData)
Add a file inside a ZIP file opened/created with CPLCreateZip().
Definition cpl_minizip_zip.cpp:2360
CPLGetExecPath
int CPLGetExecPath(char *pszPathBuf, int nMaxLength)
Fetch path of executable.
Definition cpl_getexecpath.cpp:51
CPLHasPathTraversal
bool CPLHasPathTraversal(const char *pszFilename)
Return whether the filename contains a path traversal pattern.
Definition cpl_path.cpp:1660
CPLFormCIFilename
const char * CPLFormCIFilename(const char *pszPath, const char *pszBasename, const char *pszExtension)
Case insensitive file searching, returning full path.
Definition cpl_path.cpp:998
CPLScanString
char * CPLScanString(const char *, int, int, int)
Scan up to a maximum number of characters from a given string, allocate a buffer for a new string and...
Definition cpl_conv.cpp:876
CPLIsDebugEnabled
bool CPLIsDebugEnabled(void)
Returns whether CPL_DEBUG is enabled.
Definition cpl_conv.cpp:1934
CPLPrintTime
int CPLPrintTime(char *, int, const char *, const struct tm *, const char *)
Print specified time value accordingly to the format options and specified locale name.
Definition cpl_conv.cpp:1507
CPLFinderClean
void CPLFinderClean(void)
CPLFinderClean.
Definition cpl_findfile.cpp:117
CPLHasUnbalancedPathTraversal
bool CPLHasUnbalancedPathTraversal(const char *pszFilename)
Return whether the filename contains a unbalanced path traversal pattern.
Definition cpl_path.cpp:1702
CPLCalloc
void * CPLCalloc(size_t, size_t)
Safe version of calloc().
Definition cpl_conv.cpp:162
CPLAtoGIntBigEx
GIntBig CPLAtoGIntBigEx(const char *pszString, int bWarn, int *pbOverflow)
Convert a string to a 64 bit signed integer.
Definition cpl_conv.cpp:1064
CPLScanPointer
void * CPLScanPointer(const char *, int)
Extract pointer from string.
Definition cpl_conv.cpp:1112
CPLGenerateTempFilename
const char * CPLGenerateTempFilename(const char *pszStem)
Generate temporary file name.
Definition cpl_path.cpp:1502
CPLGetPath
const char * CPLGetPath(const char *)
Extract directory path portion of filename.
Definition cpl_path.cpp:242
CPLStringToComplex
CPLErr CPLStringToComplex(const char *pszString, double *pdfReal, double *pdfImag)
Fetch the real and imaginary part of a serialized complex number.
Definition cpl_conv.cpp:2805
CPLStrdup
char * CPLStrdup(const char *)
Safe version of strdup() function.
Definition cpl_conv.cpp:315
CPLCreateFileInZip
CPLErr CPLCreateFileInZip(void *hZip, const char *pszFilename, char **papszOptions)
Create a file in a ZIP file.
Definition cpl_conv.cpp:3615
CPLFormFilenameSafe
std::string CPLFormFilenameSafe(const char *pszPath, const char *pszBasename, const char *pszExtension=nullptr)
Build a full file path from a passed path, file basename and extension.
Definition cpl_path.cpp:709
CPLLoadConfigOptionsFromPredefinedFiles
void CPLLoadConfigOptionsFromPredefinedFiles(void)
Load configuration from a set of predefined files.
Definition cpl_conv.cpp:2489
CPLGetConfigOptions
char ** CPLGetConfigOptions(void)
Return the list of configuration options as KEY=VALUE pairs.
Definition cpl_conv.cpp:1746
CPLStrtodM
double CPLStrtodM(const char *, char **)
Converts ASCII string to floating point number.
Definition cpl_strtod.cpp:415
CPLDMSToDec
double CPLDMSToDec(const char *is)
CPLDMSToDec.
Definition cpl_conv.cpp:2579
CPLCheckForFile
int CPLCheckForFile(char *pszFilename, CSLConstList papszSiblingList)
Check for file existence.
Definition cpl_conv.cpp:3569
CPLCleanTrailingSlash
const char * CPLCleanTrailingSlash(const char *)
Remove trailing forward/backward slash from the path for UNIX/Windows resp.
Definition cpl_path.cpp:1285
CPLReadLineL
const char * CPLReadLineL(VSILFILE *)
Simplified line reading from text file.
Definition cpl_conv.cpp:656
CPLReadLine
const char * CPLReadLine(FILE *)
Simplified line reading from text file.
Definition cpl_conv.cpp:588
CPLIsInteractive
bool CPLIsInteractive(FILE *f)
Returns whether the provided file refers to a terminal.
Definition cpl_conv.cpp:3709
CPLValidateXML
int CPLValidateXML(const char *pszXMLFilename, const char *pszXSDFilename, CSLConstList papszOptions)
Validate a XML file against a XML schema.
Definition cpl_xml_validate.cpp:1038
CPLCloseZip
CPLErr CPLCloseZip(void *hZip)
Close ZIP file.
Definition cpl_conv.cpp:3630
CPLGetPathSafe
std::string CPLGetPathSafe(const char *)
Extract directory path portion of filename.
Definition cpl_path.cpp:152
CPLGetGlobalConfigOption
const char * CPLGetGlobalConfigOption(const char *, const char *)
Same as CPLGetConfigOption() but excludes environment variables and options set with CPLSetThreadLoca...
Definition cpl_conv.cpp:1816
CPLResetExtension
const char * CPLResetExtension(const char *, const char *)
Replace the extension with the provided one.
Definition cpl_path.cpp:669
CPLCleanTrailingSlashSafe
std::string CPLCleanTrailingSlashSafe(const char *pszPath)
Remove trailing forward/backward slash from the path for UNIX/Windows resp.
Definition cpl_path.cpp:1249
CPLOpenShared
FILE * CPLOpenShared(const char *, const char *, int)
Open a shared file handle.
Definition cpl_conv.cpp:2906
CPLPushFinderLocation
void CPLPushFinderLocation(const char *)
CPLPushFinderLocation.
Definition cpl_findfile.cpp:235
CPLGetCurrentDir
char * CPLGetCurrentDir(void)
Get the current working directory name.
Definition cpl_path.cpp:599
CPLPushFileFinder
void CPLPushFileFinder(CPLFileFinder pfnFinder)
CPLPushFileFinder.
Definition cpl_findfile.cpp:187
CPLStat
int CPLStat(const char *, VSIStatBuf *)
Same as VSIStat() except it works on "C:" as if it were "C:\".
Definition cpl_conv.cpp:2530
CPLUnsubscribeToSetConfigOption
void CPLUnsubscribeToSetConfigOption(int nSubscriberId)
Remove a subscriber installed with CPLSubscribeToSetConfigOption()
Definition cpl_conv.cpp:1880
CPLDecToPackedDMS
double CPLDecToPackedDMS(double dfDec)
Convert decimal degrees into packed DMS value (DDDMMMSSS.SS).
Definition cpl_conv.cpp:2788
CPLExtractRelativePath
const char * CPLExtractRelativePath(const char *, const char *, int *)
Get relative path from directory to target file.
Definition cpl_path.cpp:1158
CPLGetThreadLocalConfigOption
const char * CPLGetThreadLocalConfigOption(const char *, const char *)
Same as CPLGetConfigOption() but only with options set with CPLSetThreadLocalConfigOption()
Definition cpl_conv.cpp:1785
CPLPopFinderLocation
void CPLPopFinderLocation(void)
CPLPopFinderLocation.
Definition cpl_findfile.cpp:274
CPLAtofM
double CPLAtofM(const char *)
Converts ASCII string to floating point number using any numeric locale.
Definition cpl_strtod.cpp:127
CPLSetConfigOption
void CPLSetConfigOption(const char *, const char *)
Set a configuration option for GDAL/OGR use.
Definition cpl_conv.cpp:2075
CPLFGets
char * CPLFGets(char *, int, FILE *)
Reads in at most one less than nBufferSize characters from the fp stream and stores them into the buf...
Definition cpl_conv.cpp:387
CPLAtoGIntBig
GIntBig CPLAtoGIntBig(const char *pszString)
Convert a string to a 64 bit signed integer.
Definition cpl_conv.cpp:1019
CPLPackedDMSToDec
double CPLPackedDMSToDec(double)
Convert a packed DMS value (DDDMMMSSS.SS) into decimal degrees.
Definition cpl_conv.cpp:2754
CPLDumpSharedList
void CPLDumpSharedList(FILE *)
Report open shared files.
Definition cpl_conv.cpp:3091
CPLUnlinkTree
int CPLUnlinkTree(const char *)
Recursively unlink a directory.
Definition cpl_conv.cpp:3125
CPLSubscribeToSetConfigOption
int CPLSubscribeToSetConfigOption(CPLSetConfigOptionSubscriber pfnCallback, void *pUserData)
Install a callback that will be notified of calls to CPLSetConfigOption()/ CPLSetThreadLocalConfigOpt...
Definition cpl_conv.cpp:1848
CPLProjectRelativeFilename
const char * CPLProjectRelativeFilename(const char *pszProjectDir, const char *pszSecondaryFilename)
Find a file relative to a project file.
Definition cpl_path.cpp:1091
CPLScanUIntBig
GUIntBig CPLScanUIntBig(const char *, int)
Extract big integer from string.
Definition cpl_conv.cpp:994
CPLDecToDMS
const char * CPLDecToDMS(double dfAngle, const char *pszAxis, int nPrecision)
Translate a decimal degrees value to a DMS string with hemisphere.
Definition cpl_conv.cpp:2664
CPLFindFile
const char * CPLFindFile(const char *pszClass, const char *pszBasename)
CPLFindFile.
Definition cpl_findfile.cpp:164
CPLScanDouble
double CPLScanDouble(const char *, int)
Extract double from string.
Definition cpl_conv.cpp:1178
CPLIsPowerOfTwo
int CPLIsPowerOfTwo(unsigned int i)
Definition cpl_conv.cpp:3534
CPLGetConfigOption
const char * CPLGetConfigOption(const char *, const char *)
Get the value of a configuration option.
Definition cpl_conv.cpp:1697
CPLScanULong
unsigned long CPLScanULong(const char *, int)
Scan up to a maximum number of characters from a string and convert the result to a unsigned long.
Definition cpl_conv.cpp:964
CPLSetThreadLocalConfigOption
void CPLSetThreadLocalConfigOption(const char *pszKey, const char *pszValue)
Set a configuration option for GDAL/OGR use.
Definition cpl_conv.cpp:2131
CPLStrtodDelim
double CPLStrtodDelim(const char *, char **, char)
Converts ASCII string to floating point number using specified delimiter.
Definition cpl_strtod.cpp:218
CPLUnlockFileEx
void CPLUnlockFileEx(CPLLockFileHandle hLockFileHandle)
Release and delete a lock file.
Definition cpl_conv.cpp:3900
cpl::down_cast
To down_cast(From *f)
Use cpl::down_cast<Derived*>(pointer_to_base) as equivalent of static_cast<Derived*>(pointer_to_base)...
Definition cpl_conv.h:496
CPLGetRemainingFileDescriptorCount
int CPLGetRemainingFileDescriptorCount(void)
Return the number of file descriptors that can still be opened by the current process.
Definition cpl_conv.cpp:4017
CPLGetFilename
const char * CPLGetFilename(const char *)
Extract non-directory portion of filename.
Definition cpl_path.cpp:391
CPLStrlwr
char * CPLStrlwr(char *)
Convert each characters of the string to lower case.
Definition cpl_conv.cpp:341
CPLLockFileStatus
CPLLockFileStatus
Return code of CPLLockFileEx().
Definition cpl_conv.h:327
CLFS_OK
@ CLFS_OK
CPLLockFileEx() succeeded.
Definition cpl_conv.h:328
CLFS_LOCK_BUSY
@ CLFS_LOCK_BUSY
Lock already taken (and still alive).
Definition cpl_conv.h:330
CLFS_CANNOT_CREATE_LOCK
@ CLFS_CANNOT_CREATE_LOCK
Lock file creation failed.
Definition cpl_conv.h:329
CLFS_API_MISUSE
@ CLFS_API_MISUSE
API misuse.
Definition cpl_conv.h:331
CLFS_THREAD_CREATION_FAILED
@ CLFS_THREAD_CREATION_FAILED
Thread creation failed.
Definition cpl_conv.h:332
CPLCopyFile
int CPLCopyFile(const char *pszNewPath, const char *pszOldPath)
Copy a file.
Definition cpl_conv.cpp:3208
CPLGetKnownConfigOptions
char ** CPLGetKnownConfigOptions(void)
Return the list of known configuration options.
Definition cpl_conv.cpp:1990
CPLFormFilename
const char * CPLFormFilename(const char *pszPath, const char *pszBasename, const char *pszExtension)
Build a full file path from a passed path, file basename and extension.
Definition cpl_path.cpp:863
CPLPrintDouble
int CPLPrintDouble(char *, const char *, double, const char *)
Print double value into specified string buffer.
Definition cpl_conv.cpp:1449
CPLZLibDeflate
void * CPLZLibDeflate(const void *ptr, size_t nBytes, int nLevel, void *outptr, size_t nOutAvailableBytes, size_t *pnOutBytes)
Compress a buffer with ZLib compression.
Definition cpl_conv.cpp:3635
CPLPrintString
int CPLPrintString(char *, const char *, int)
Copy the string pointed to by pszSrc, NOT including the terminating ‘\0’ character,...
Definition cpl_conv.cpp:1230
CPLCloseFileInZip
CPLErr CPLCloseFileInZip(void *hZip)
Close current file inside ZIP file.
Definition cpl_conv.cpp:3625
CPLDefaultFindFile
const char * CPLDefaultFindFile(const char *pszClass, const char *pszBasename)
CPLDefaultFindFile.
Definition cpl_findfile.cpp:132
CPLWriteFileInZip
CPLErr CPLWriteFileInZip(void *hZip, const void *pBuffer, int nBufferSize)
Write in current file inside a ZIP file.
Definition cpl_conv.cpp:3620
CPLPopFileFinder
CPLFileFinder CPLPopFileFinder(void)
CPLPopFileFinder.
Definition cpl_findfile.cpp:224
CPLPrintPointer
int CPLPrintPointer(char *, void *, int)
Print pointer value into specified string buffer.
Definition cpl_conv.cpp:1405
CPLSetThreadLocalConfigOptions
void CPLSetThreadLocalConfigOptions(const char *const *papszConfigOptions)
Replace the full list of thread local configuration options with the passed list of KEY=VALUE pairs.
Definition cpl_conv.cpp:2202
CPLZLibInflateEx
void * CPLZLibInflateEx(const void *ptr, size_t nBytes, void *outptr, size_t nOutAvailableBytes, bool bAllowResizeOutptr, size_t *pnOutBytes)
Uncompress a buffer compressed with ZLib compression.
Definition cpl_vsil_gzip.cpp:5114
CPLGetSharedList
CPLSharedFileInfo * CPLGetSharedList(int *)
Fetch list of open shared files.
Definition cpl_conv.cpp:3069
CPLAtof
double CPLAtof(const char *)
Converts ASCII string to floating point number.
Definition cpl_strtod.cpp:102
cpl_error.h
CPL error handling services.
CPLAssert
#define CPLAssert(expr)
Assert on an expression.
Definition cpl_error.h:330
CPLErr
CPLErr
Error category.
Definition cpl_error.h:37
cpl_port.h
Core portability definitions for CPL.
GUIntBig
unsigned long long GUIntBig
Large unsigned integer type (generally 64-bit unsigned integer type).
Definition cpl_port.h:208
CPL_C_END
#define CPL_C_END
Macro to end a block of C symbols.
Definition cpl_port.h:289
CPL_C_START
#define CPL_C_START
Macro to start a block of C symbols.
Definition cpl_port.h:285
CPL_RETURNS_NONNULL
#define CPL_RETURNS_NONNULL
Qualifier for a function that does not return NULL.
Definition cpl_port.h:908
CPL_DISALLOW_COPY_ASSIGN
#define CPL_DISALLOW_COPY_ASSIGN(ClassName)
Helper to remove the copy and assignment constructors so that the compiler will not generate the defa...
Definition cpl_port.h:936
CSLConstList
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition cpl_port.h:1087
CPL_WARN_UNUSED_RESULT
#define CPL_WARN_UNUSED_RESULT
Qualifier to warn when the return value of a function is not used.
Definition cpl_port.h:870
GInt32
int GInt32
Int32 type.
Definition cpl_port.h:165
GIntBig
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition cpl_port.h:205
cpl_vsi.h
Standard C Covers.
CPLSharedFileInfo
Information on a shared file.
Definition cpl_conv.h:282
CPLSharedFileInfo::pszAccess
char * pszAccess
Access mode.
Definition cpl_conv.h:287
CPLSharedFileInfo::fp
FILE * fp
File pointer.
Definition cpl_conv.h:283
CPLSharedFileInfo::nRefCount
int nRefCount
Reference counter.
Definition cpl_conv.h:284
CPLSharedFileInfo::pszFilename
char * pszFilename
Filename.
Definition cpl_conv.h:286
CPLSharedFileInfo::bLarge
int bLarge
Whether fp must be interpreted as VSIFILE*.
Definition cpl_conv.h:285
VSIVirtualHandle
Virtual file handle.
Definition cpl_vsi_virtual.h:48