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/* -------------------------------------------------------------------- */
37
39void CPL_DLL CPLVerifyConfiguration(void);
42bool CPL_DLL CPLIsDebugEnabled(void);
43
49#define CPL_NULL_VALUE "__CPL_NULL_VALUE__"
50
51const char CPL_DLL *CPL_STDCALL CPLGetConfigOption(const char *, const char *)
53const char CPL_DLL *CPL_STDCALL CPLGetThreadLocalConfigOption(
54 const char *, const char *) CPL_WARN_UNUSED_RESULT;
55const char CPL_DLL *CPL_STDCALL
56CPLGetGlobalConfigOption(const char *, const char *) CPL_WARN_UNUSED_RESULT;
57void CPL_DLL CPL_STDCALL CPLSetConfigOption(const char *, const char *);
58void CPL_DLL CPL_STDCALL CPLSetThreadLocalConfigOption(const char *pszKey,
59 const char *pszValue);
60void CPL_DLL CPLDeclareKnownConfigOption(const char *pszKey,
61 const char *pszDefinition);
62char CPL_DLL **CPLGetKnownConfigOptions(void);
63
65typedef void (*CPLSetConfigOptionSubscriber)(const char *pszKey,
66 const char *pszValue,
67 bool bThreadLocal,
68 void *pUserData);
70 CPLSetConfigOptionSubscriber pfnCallback, void *pUserData);
71void CPL_DLL CPLUnsubscribeToSetConfigOption(int nSubscriberId);
72
74void CPL_DLL CPL_STDCALL CPLFreeConfig(void);
76char CPL_DLL **CPLGetConfigOptions(void);
77void CPL_DLL CPLSetConfigOptions(const char *const *papszConfigOptions);
78char CPL_DLL **CPLGetThreadLocalConfigOptions(void);
79void CPL_DLL
80CPLSetThreadLocalConfigOptions(const char *const *papszConfigOptions);
81void CPL_DLL CPLLoadConfigOptionsFromFile(const char *pszFilename,
82 int bOverrideEnvVars);
84
85/* -------------------------------------------------------------------- */
86/* Safe malloc() API. Thin cover over VSI functions with fatal */
87/* error reporting if memory allocation fails. */
88/* -------------------------------------------------------------------- */
89void CPL_DLL *CPLMalloc(size_t) CPL_WARN_UNUSED_RESULT;
90void CPL_DLL *CPLCalloc(size_t, size_t) CPL_WARN_UNUSED_RESULT;
91void CPL_DLL *CPLRealloc(void *, size_t) CPL_WARN_UNUSED_RESULT;
92char CPL_DLL *
94char CPL_DLL *CPLStrlwr(char *);
95
97#define CPLFree VSIFree
98
99/* -------------------------------------------------------------------- */
100/* Read a line from a text file, and strip of CR/LF. */
101/* -------------------------------------------------------------------- */
102char CPL_DLL *CPLFGets(char *, int, FILE *);
103const char CPL_DLL *CPLReadLine(FILE *);
104const char CPL_DLL *CPLReadLineL(VSILFILE *);
105const char CPL_DLL *CPLReadLine2L(VSILFILE *, int, CSLConstList);
106const char CPL_DLL *CPLReadLine3L(VSILFILE *, int, int *, CSLConstList);
107
108/* -------------------------------------------------------------------- */
109/* Convert ASCII string to floating point number */
110/* (THESE FUNCTIONS ARE NOT LOCALE AWARE!). */
111/* -------------------------------------------------------------------- */
112double CPL_DLL CPLAtof(const char *);
113double CPL_DLL CPLAtofDelim(const char *, char);
114double CPL_DLL CPLStrtod(const char *, char **);
115double CPL_DLL CPLStrtodM(const char *, char **);
116double CPL_DLL CPLStrtodDelim(const char *, char **, char);
117float CPL_DLL CPLStrtof(const char *, char **);
118float CPL_DLL CPLStrtofDelim(const char *, char **, char);
119
120/* -------------------------------------------------------------------- */
121/* Convert number to string. This function is locale agnostic */
122/* (i.e. it will support "," or "." regardless of current locale) */
123/* -------------------------------------------------------------------- */
124double CPL_DLL CPLAtofM(const char *);
125
126/* -------------------------------------------------------------------- */
127/* Read a numeric value from an ASCII character string. */
128/* -------------------------------------------------------------------- */
129char CPL_DLL *CPLScanString(const char *, int, int, int);
130double CPL_DLL CPLScanDouble(const char *, int);
131long CPL_DLL CPLScanLong(const char *, int);
132unsigned long CPL_DLL CPLScanULong(const char *, int);
133GUIntBig CPL_DLL CPLScanUIntBig(const char *, int);
134GIntBig CPL_DLL CPLAtoGIntBig(const char *pszString);
135GIntBig CPL_DLL CPLAtoGIntBigEx(const char *pszString, int bWarn,
136 int *pbOverflow);
137void CPL_DLL *CPLScanPointer(const char *, int);
138
139/* -------------------------------------------------------------------- */
140/* Print a value to an ASCII character string. */
141/* -------------------------------------------------------------------- */
142int CPL_DLL CPLPrintString(char *, const char *, int);
143int CPL_DLL CPLPrintStringFill(char *, const char *, int);
144int CPL_DLL CPLPrintInt32(char *, GInt32, int);
145int CPL_DLL CPLPrintUIntBig(char *, GUIntBig, int);
146int CPL_DLL CPLPrintDouble(char *, const char *, double, const char *);
147int CPL_DLL CPLPrintTime(char *, int, const char *, const struct tm *,
148 const char *);
149int CPL_DLL CPLPrintPointer(char *, void *, int);
150
151#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
152extern "C++"
153{
154 std::string CPL_DLL CPLFormatReadableFileSize(uint64_t nSizeInBytes);
155 std::string CPL_DLL CPLFormatReadableFileSize(double dfSizeInBytes);
156}
157#endif
158
159/* -------------------------------------------------------------------- */
160/* Fetch a function from DLL / so. */
161/* -------------------------------------------------------------------- */
162
163void CPL_DLL *CPLGetSymbol(const char *, const char *);
164
165/* -------------------------------------------------------------------- */
166/* Fetch executable path. */
167/* -------------------------------------------------------------------- */
168int CPL_DLL CPLGetExecPath(char *pszPathBuf, int nMaxLength);
169
170/* -------------------------------------------------------------------- */
171/* Filename handling functions. */
172/* -------------------------------------------------------------------- */
173
174#if defined(DOXYGEN_SKIP) || !defined(__cplusplus) || \
175 !defined(GDAL_COMPILATION) || \
176 (defined(__cplusplus) && defined(ALLOW_DEPRECATED_CPL_PATH_FUNCTIONS))
177const char CPL_DLL *
179const char CPL_DLL *
181const char CPL_DLL *
183const char CPL_DLL *
185const char CPL_DLL *CPLFormFilename(
186 const char *pszPath, const char *pszBasename,
187 const char *pszExtension) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
188const char CPL_DLL *CPLFormCIFilename(
189 const char *pszPath, const char *pszBasename,
190 const char *pszExtension) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
191const char CPL_DLL *CPLResetExtension(const char *, const char *)
193const char CPL_DLL *CPLProjectRelativeFilename(const char *pszProjectDir,
194 const char *pszSecondaryFilename)
196const char CPL_DLL *
198const char CPL_DLL *CPLGenerateTempFilename(const char *pszStem)
200const char CPL_DLL *CPLExpandTilde(const char *pszFilename)
202const char CPL_DLL *
203CPLLaunderForFilename(const char *pszName,
204 const char *pszOutputPath) CPL_WARN_UNUSED_RESULT;
205#endif
206
207char CPL_DLL *CPLGetCurrentDir(void);
208const char CPL_DLL *
210int CPL_DLL CPLIsFilenameRelative(const char *pszFilename);
211const char CPL_DLL *CPLExtractRelativePath(const char *, const char *, int *)
213char CPL_DLL **
214CPLCorrespondingPaths(const char *pszOldFilename, const char *pszNewFilename,
216int CPL_DLL CPLCheckForFile(char *pszFilename, CSLConstList papszSiblingList);
217
218const char CPL_DLL *CPLGetHomeDir(void) CPL_WARN_UNUSED_RESULT;
219
220#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
221
222extern "C++"
223{
224 std::string CPL_DLL CPLGetPathSafe(const char *) CPL_WARN_UNUSED_RESULT;
225 std::string CPL_DLL CPLGetDirnameSafe(const char *) CPL_WARN_UNUSED_RESULT;
226 std::string CPL_DLL CPLGetBasenameSafe(const char *) CPL_WARN_UNUSED_RESULT;
227 std::string CPL_DLL CPLGetExtensionSafe(const char *)
229 std::string CPL_DLL CPLFormFilenameSafe(
230 const char *pszPath, const char *pszBasename,
231 const char *pszExtension = nullptr) CPL_WARN_UNUSED_RESULT;
232 std::string CPL_DLL CPLFormCIFilenameSafe(
233 const char *pszPath, const char *pszBasename,
234 const char *pszExtension = nullptr) CPL_WARN_UNUSED_RESULT;
235 std::string CPL_DLL CPLResetExtensionSafe(const char *, const char *)
237 std::string CPL_DLL CPLProjectRelativeFilenameSafe(
238 const char *pszProjectDir,
239 const char *pszSecondaryFilename) CPL_WARN_UNUSED_RESULT;
240 std::string CPL_DLL CPLCleanTrailingSlashSafe(const char *pszPath)
242 std::string CPL_DLL CPLGenerateTempFilenameSafe(const char *pszStem)
244 std::string CPL_DLL CPLExpandTildeSafe(const char *pszFilename)
246 std::string CPL_DLL CPLLaunderForFilenameSafe(
247 const char *pszName, const char *pszOutputPath) CPL_WARN_UNUSED_RESULT;
248 std::string CPL_DLL CPLLaunderForFilenameSafe(
249 const std::string &osName, char chReplacementChar = '_',
250 const char *pszExtraReservedCharacters = nullptr)
252
253#if defined(GDAL_COMPILATION) || __cplusplus >= 201703L
254 std::string
255 CPL_DLL CPLLexicallyNormalize(std::string_view svPath, char sep1,
256 char sep2 = 0) CPL_WARN_UNUSED_RESULT;
257#endif
258}
259
260#endif // defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
261
262bool CPL_DLL CPLHasPathTraversal(const char *pszFilename);
263bool CPL_DLL CPLHasUnbalancedPathTraversal(const char *pszFilename);
264
265/* -------------------------------------------------------------------- */
266/* Find File Function */
267/* -------------------------------------------------------------------- */
268
270typedef char const *(*CPLFileFinder)(const char *, const char *);
271
272const char CPL_DLL *CPLFindFile(const char *pszClass, const char *pszBasename);
273const char CPL_DLL *CPLDefaultFindFile(const char *pszClass,
274 const char *pszBasename);
275void CPL_DLL CPLPushFileFinder(CPLFileFinder pfnFinder);
276CPLFileFinder CPL_DLL CPLPopFileFinder(void);
277void CPL_DLL CPLPushFinderLocation(const char *);
278void CPL_DLL CPLPopFinderLocation(void);
279void CPL_DLL CPLFinderClean(void);
280
281/* -------------------------------------------------------------------- */
282/* Safe version of stat() that works properly on stuff like "C:". */
283/* -------------------------------------------------------------------- */
284int CPL_DLL CPLStat(const char *, VSIStatBuf *) CPL_WARN_UNUSED_RESULT;
285
286/* -------------------------------------------------------------------- */
287/* Reference counted file handle manager. Makes sharing file */
288/* handles more practical. */
289/* -------------------------------------------------------------------- */
290
292typedef struct
293{
294 FILE *fp;
296 int bLarge;
298 char *pszAccess;
300
301FILE CPL_DLL *CPLOpenShared(const char *, const char *, int);
302void CPL_DLL CPLCloseShared(FILE *);
303CPLSharedFileInfo CPL_DLL *CPLGetSharedList(int *);
304void CPL_DLL CPLDumpSharedList(FILE *);
306void CPL_DLL CPLCleanupSharedFileMutex(void);
309/* -------------------------------------------------------------------- */
310/* DMS to Dec to DMS conversion. */
311/* -------------------------------------------------------------------- */
312double CPL_DLL CPLDMSToDec(const char *is);
313const char CPL_DLL *CPLDecToDMS(double dfAngle, const char *pszAxis,
314 int nPrecision);
315double CPL_DLL CPLPackedDMSToDec(double);
316double CPL_DLL CPLDecToPackedDMS(double dfDec);
317
318CPLErr CPL_DLL CPLStringToComplex(const char *pszString, double *pdfReal,
319 double *pdfImag);
320
321/* -------------------------------------------------------------------- */
322/* Misc other functions. */
323/* -------------------------------------------------------------------- */
324int CPL_DLL CPLUnlinkTree(const char *);
325int CPL_DLL CPLCopyFile(const char *pszNewPath, const char *pszOldPath);
326int CPL_DLL CPLCopyTree(const char *pszNewPath, const char *pszOldPath);
327int CPL_DLL CPLMoveFile(const char *pszNewPath, const char *pszOldPath);
328int CPL_DLL CPLSymlink(const char *pszOldPath, const char *pszNewPath,
329 CSLConstList papszOptions);
330int CPL_DLL CPLGetRemainingFileDescriptorCount(void);
331
332/* -------------------------------------------------------------------- */
333/* Lock related functions. */
334/* -------------------------------------------------------------------- */
335
345
347typedef struct CPLLockFileStruct *CPLLockFileHandle;
348
349CPLLockFileStatus CPL_DLL CPLLockFileEx(const char *pszLockFileName,
350 CPLLockFileHandle *phLockFileHandle,
351 CSLConstList papszOptions);
352
353void CPL_DLL CPLUnlockFileEx(CPLLockFileHandle hLockFileHandle);
354
355/* -------------------------------------------------------------------- */
356/* ZIP Creation. */
357/* -------------------------------------------------------------------- */
358
360#define CPL_ZIP_API_OFFERED
362void CPL_DLL *CPLCreateZip(const char *pszZipFilename, char **papszOptions);
363CPLErr CPL_DLL CPLCreateFileInZip(void *hZip, const char *pszFilename,
364 char **papszOptions);
365CPLErr CPL_DLL CPLWriteFileInZip(void *hZip, const void *pBuffer,
366 int nBufferSize);
367CPLErr CPL_DLL CPLCloseFileInZip(void *hZip);
368CPLErr CPL_DLL CPLAddFileInZip(void *hZip, const char *pszArchiveFilename,
369 const char *pszInputFilename, VSILFILE *fpInput,
370 CSLConstList papszOptions,
371 GDALProgressFunc pProgressFunc,
372 void *pProgressData);
373CPLErr CPL_DLL CPLCloseZip(void *hZip);
374
375/* -------------------------------------------------------------------- */
376/* ZLib compression */
377/* -------------------------------------------------------------------- */
378
379void CPL_DLL *CPLZLibDeflate(const void *ptr, size_t nBytes, int nLevel,
380 void *outptr, size_t nOutAvailableBytes,
381 size_t *pnOutBytes);
382void CPL_DLL *CPLZLibInflate(const void *ptr, size_t nBytes, void *outptr,
383 size_t nOutAvailableBytes, size_t *pnOutBytes);
384void CPL_DLL *CPLZLibInflateEx(const void *ptr, size_t nBytes, void *outptr,
385 size_t nOutAvailableBytes,
386 bool bAllowResizeOutptr, size_t *pnOutBytes);
387
388/* -------------------------------------------------------------------- */
389/* XML validation. */
390/* -------------------------------------------------------------------- */
391int CPL_DLL CPLValidateXML(const char *pszXMLFilename,
392 const char *pszXSDFilename,
393 CSLConstList papszOptions);
394
395/* -------------------------------------------------------------------- */
396/* Locale handling. Prevents parallel executions of setlocale(). */
397/* -------------------------------------------------------------------- */
398char *CPLsetlocale(int category, const char *locale);
400void CPLCleanupSetlocaleMutex(void);
408int CPL_DLL CPLIsPowerOfTwo(unsigned int i);
409
410/* -------------------------------------------------------------------- */
411/* Terminal related */
412/* -------------------------------------------------------------------- */
413
414bool CPL_DLL CPLIsInteractive(FILE *f);
415
417
418/* -------------------------------------------------------------------- */
419/* C++ object for temporarily forcing a LC_NUMERIC locale to "C". */
420/* -------------------------------------------------------------------- */
421
423#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
424
425extern "C++"
426{
427 class CPL_DLL CPLLocaleC
428 {
429 CPL_DISALLOW_COPY_ASSIGN(CPLLocaleC)
430 public:
431 CPLLocaleC();
432 ~CPLLocaleC();
433
434 private:
435 char *pszOldLocale;
436 };
437
438 // Does the same as CPLLocaleC except that, when available, it tries to
439 // only affect the current thread. But code that would be dependent of
440 // setlocale(LC_NUMERIC, NULL) returning "C", such as current proj.4
441 // versions, will not work depending on the actual implementation
442 class CPLThreadLocaleCPrivate;
443
444 class CPL_DLL CPLThreadLocaleC
445 {
446 CPL_DISALLOW_COPY_ASSIGN(CPLThreadLocaleC)
447
448 public:
449 CPLThreadLocaleC();
450 ~CPLThreadLocaleC();
451
452 private:
453 CPLThreadLocaleCPrivate *m_private;
454 };
455}
456
457#endif /* def __cplusplus */
459
460/* -------------------------------------------------------------------- */
461/* C++ object for temporarily forcing a config option */
462/* -------------------------------------------------------------------- */
463
465#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
466
467extern "C++"
468{
469 class CPL_DLL CPLConfigOptionSetter
470 {
471 CPL_DISALLOW_COPY_ASSIGN(CPLConfigOptionSetter)
472 public:
473 CPLConfigOptionSetter(const char *pszKey, const char *pszValue,
474 bool bSetOnlyIfUndefined);
475 ~CPLConfigOptionSetter();
476
477 private:
478 char *m_pszKey;
479 char *m_pszOldValue;
480 bool m_bRestoreOldValue;
481 };
482}
483
484#endif /* def __cplusplus */
486
487#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
488
489extern "C++"
490{
491
492#ifndef DOXYGEN_SKIP
493#include <type_traits> // for std::is_base_of
494#endif
495
496 namespace cpl
497 {
507 template <typename To, typename From> inline To down_cast(From *f)
508 {
509 static_assert(
510 (std::is_base_of<From,
511 typename std::remove_pointer<To>::type>::value),
512 "target type not derived from source type");
513 CPLAssert(f == nullptr || dynamic_cast<To>(f) != nullptr);
514 return static_cast<To>(f);
515 }
516
518 template <class T, class U> inline T div_round_up(T a, U b)
519 {
520 return a / b + (((a % b) == 0) ? 0 : 1);
521 }
522
523 } // namespace cpl
524} // extern "C++"
525
526#endif /* def __cplusplus */
527
528#endif /* ndef CPL_CONV_H_INCLUDED */
std::string CPLFormatReadableFileSize(uint64_t nSizeInBytes)
Return a file size in a human readable way.
Definition cpl_conv.cpp:4002
std::string CPLGenerateTempFilenameSafe(const char *pszStem)
Generate temporary file name.
Definition cpl_path.cpp:1457
const char * CPLGetHomeDir(void)
Return the path to the home directory.
Definition cpl_path.cpp:1574
const char * CPLExpandTilde(const char *pszFilename)
Expands ~/ at start of filename.
Definition cpl_path.cpp:1553
void CPLDeclareKnownConfigOption(const char *pszKey, const char *pszDefinition)
Declare that the specified configuration option is known.
Definition cpl_conv.cpp:2002
void(* CPLSetConfigOptionSubscriber)(const char *pszKey, const char *pszValue, bool bThreadLocal, void *pUserData)
Callback for CPLSubscribeToSetConfigOption()
Definition cpl_conv.h:65
void * CPLCreateZip(const char *pszZipFilename, char **papszOptions)
Create ZIP file.
Definition cpl_conv.cpp:3652
double CPLAtofDelim(const char *, char)
Converts ASCII string to floating point number.
Definition cpl_strtod.cpp:58
int CPLPrintStringFill(char *, const char *, int)
Copy the string pointed to by pszSrc, NOT including the terminating ‘\0’ character,...
Definition cpl_conv.cpp:1282
void * CPLGetSymbol(const char *, const char *)
Fetch a function pointer from a shared library / DLL.
Definition cplgetsymbol.cpp:74
int CPLIsFilenameRelative(const char *pszFilename)
Is filename relative or absolute?
Definition cpl_path.cpp:1113
std::string CPLFormCIFilenameSafe(const char *pszPath, const char *pszBasename, const char *pszExtension=nullptr)
Case insensitive file searching, returning full path.
Definition cpl_path.cpp:896
const char * CPLReadLine2L(VSILFILE *, int, CSLConstList)
Simplified line reading from text file.
Definition cpl_conv.cpp:688
std::string CPLLaunderForFilenameSafe(const char *pszName, const char *pszOutputPath)
Launder a string to be compatible of a filename.
Definition cpl_path.cpp:1599
int CPLPrintUIntBig(char *, GUIntBig, int)
Print GUIntBig value into specified string buffer.
Definition cpl_conv.cpp:1365
std::string CPLProjectRelativeFilenameSafe(const char *pszProjectDir, const char *pszSecondaryFilename)
Find a file relative to a project file.
Definition cpl_path.cpp:1035
int CPLCopyTree(const char *pszNewPath, const char *pszOldPath)
Recursively copy a tree.
Definition cpl_conv.cpp:3266
void CPLCloseShared(FILE *)
Close shared file.
Definition cpl_conv.cpp:3023
float CPLStrtof(const char *, char **)
Converts ASCII string to floating point number.
Definition cpl_strtod.cpp:496
char * CPLsetlocale(int category, const char *locale)
Prevents parallel executions of setlocale().
Definition cpl_conv.cpp:3553
const char * CPLReadLine3L(VSILFILE *, int, int *, CSLConstList)
Simplified line reading from text file.
Definition cpl_conv.cpp:715
double CPLStrtod(const char *, char **)
Converts ASCII string to floating point number.
Definition cpl_strtod.cpp:388
T div_round_up(T a, U b)
Computes ceil(a/b) where a and b are integers.
Definition cpl_conv.h:518
struct CPLLockFileStruct * CPLLockFileHandle
Handle type returned by CPLLockFileEx().
Definition cpl_conv.h:347
const char * CPLGetExtension(const char *)
Extract filename extension from full filename.
Definition cpl_path.cpp:549
void CPLLoadConfigOptionsFromFile(const char *pszFilename, int bOverrideEnvVars)
Load configuration from a given configuration file.
Definition cpl_conv.cpp:2338
int CPLMoveFile(const char *pszNewPath, const char *pszOldPath)
Move a file.
Definition cpl_conv.cpp:3341
std::string CPLGetExtensionSafe(const char *)
Extract filename extension from full filename.
Definition cpl_path.cpp:498
std::string CPLResetExtensionSafe(const char *, const char *)
Replace the extension with the provided one.
Definition cpl_path.cpp:620
std::string CPLExpandTildeSafe(const char *pszFilename)
Expands ~/ at start of filename.
Definition cpl_path.cpp:1523
std::string CPLGetBasenameSafe(const char *)
Extract basename (non-directory, non-extension) portion of filename.
Definition cpl_path.cpp:423
char ** CPLGetThreadLocalConfigOptions(void)
Return the list of thread local configuration options as KEY=VALUE pairs.
Definition cpl_conv.cpp:2218
CPLLockFileStatus CPLLockFileEx(const char *pszLockFileName, CPLLockFileHandle *phLockFileHandle, CSLConstList papszOptions)
Create and acquire a lock file.
Definition cpl_conv.cpp:3821
int CPLPrintInt32(char *, GInt32, int)
Print GInt32 value into specified string buffer.
Definition cpl_conv.cpp:1326
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:944
std::string CPLGetDirnameSafe(const char *)
Extract directory path portion of filename.
Definition cpl_path.cpp:274
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:1781
void * CPLRealloc(void *, size_t)
Safe version of realloc().
Definition cpl_conv.cpp:255
char const *(* CPLFileFinder)(const char *, const char *)
Callback for CPLPushFileFinder.
Definition cpl_conv.h:270
float CPLStrtofDelim(const char *, char **, char)
Converts ASCII string to floating point number using specified delimiter.
Definition cpl_strtod.cpp:452
char ** CPLCorrespondingPaths(const char *pszOldFilename, const char *pszNewFilename, CSLConstList papszFileList)
Identify corresponding paths.
Definition cpl_path.cpp:1317
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:3688
int CPLSymlink(const char *pszOldPath, const char *pszNewPath, CSLConstList papszOptions)
Create a symbolic link.
Definition cpl_conv.cpp:3371
const char * CPLGetBasename(const char *)
Extract basename (non-directory, non-extension) portion of filename.
Definition cpl_path.cpp:468
const char * CPLLaunderForFilename(const char *pszName, const char *pszOutputPath)
Launder a string to be compatible of a filename.
Definition cpl_path.cpp:1702
void * CPLMalloc(size_t)
Safe version of malloc().
Definition cpl_conv.cpp:200
const char * CPLGetDirname(const char *)
Extract directory path portion of filename.
Definition cpl_path.cpp:362
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
int CPLGetExecPath(char *pszPathBuf, int nMaxLength)
Fetch path of executable.
Definition cpl_getexecpath.cpp:51
bool CPLHasPathTraversal(const char *pszFilename)
Return whether the filename contains a path traversal pattern.
Definition cpl_path.cpp:1728
const char * CPLFormCIFilename(const char *pszPath, const char *pszBasename, const char *pszExtension)
Case insensitive file searching, returning full path.
Definition cpl_path.cpp:995
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:884
bool CPLIsDebugEnabled(void)
Returns whether CPL_DEBUG is enabled.
Definition cpl_conv.cpp:1962
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:1515
void CPLFinderClean(void)
CPLFinderClean.
Definition cpl_findfile.cpp:117
bool CPLHasUnbalancedPathTraversal(const char *pszFilename)
Return whether the filename contains a unbalanced path traversal pattern.
Definition cpl_path.cpp:1770
void * CPLCalloc(size_t, size_t)
Safe version of calloc().
Definition cpl_conv.cpp:170
GIntBig CPLAtoGIntBigEx(const char *pszString, int bWarn, int *pbOverflow)
Convert a string to a 64 bit signed integer.
Definition cpl_conv.cpp:1072
void * CPLScanPointer(const char *, int)
Extract pointer from string.
Definition cpl_conv.cpp:1120
const char * CPLGenerateTempFilename(const char *pszStem)
Generate temporary file name.
Definition cpl_path.cpp:1500
const char * CPLGetPath(const char *)
Extract directory path portion of filename.
Definition cpl_path.cpp:242
CPLErr CPLStringToComplex(const char *pszString, double *pdfReal, double *pdfImag)
Fetch the real and imaginary part of a serialized complex number.
Definition cpl_conv.cpp:2850
char * CPLStrdup(const char *)
Safe version of strdup() function.
Definition cpl_conv.cpp:323
CPLErr CPLCreateFileInZip(void *hZip, const char *pszFilename, char **papszOptions)
Create a file in a ZIP file.
Definition cpl_conv.cpp:3660
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
void CPLLoadConfigOptionsFromPredefinedFiles(void)
Load configuration from a set of predefined files.
Definition cpl_conv.cpp:2534
char ** CPLGetConfigOptions(void)
Return the list of configuration options as KEY=VALUE pairs.
Definition cpl_conv.cpp:1756
double CPLStrtodM(const char *, char **)
Converts ASCII string to floating point number.
Definition cpl_strtod.cpp:415
double CPLDMSToDec(const char *is)
CPLDMSToDec.
Definition cpl_conv.cpp:2624
int CPLCheckForFile(char *pszFilename, CSLConstList papszSiblingList)
Check for file existence.
Definition cpl_conv.cpp:3614
const char * CPLCleanTrailingSlash(const char *)
Remove trailing forward/backward slash from the path for UNIX/Windows resp.
Definition cpl_path.cpp:1282
const char * CPLReadLineL(VSILFILE *)
Simplified line reading from text file.
Definition cpl_conv.cpp:664
const char * CPLReadLine(FILE *)
Simplified line reading from text file.
Definition cpl_conv.cpp:596
bool CPLIsInteractive(FILE *f)
Returns whether the provided file refers to a terminal.
Definition cpl_conv.cpp:3755
int CPLValidateXML(const char *pszXMLFilename, const char *pszXSDFilename, CSLConstList papszOptions)
Validate a XML file against a XML schema.
Definition cpl_xml_validate.cpp:1038
CPLErr CPLCloseZip(void *hZip)
Close ZIP file.
Definition cpl_conv.cpp:3675
std::string CPLGetPathSafe(const char *)
Extract directory path portion of filename.
Definition cpl_path.cpp:152
const char * CPLGetGlobalConfigOption(const char *, const char *)
Same as CPLGetConfigOption() but excludes environment variables and options set with CPLSetThreadLoca...
Definition cpl_conv.cpp:1834
const char * CPLResetExtension(const char *, const char *)
Replace the extension with the provided one.
Definition cpl_path.cpp:669
std::string CPLCleanTrailingSlashSafe(const char *pszPath)
Remove trailing forward/backward slash from the path for UNIX/Windows resp.
Definition cpl_path.cpp:1246
FILE * CPLOpenShared(const char *, const char *, int)
Open a shared file handle.
Definition cpl_conv.cpp:2951
void CPLPushFinderLocation(const char *)
CPLPushFinderLocation.
Definition cpl_findfile.cpp:235
char * CPLGetCurrentDir(void)
Get the current working directory name.
Definition cpl_path.cpp:599
void CPLPushFileFinder(CPLFileFinder pfnFinder)
CPLPushFileFinder.
Definition cpl_findfile.cpp:187
int CPLStat(const char *, VSIStatBuf *)
Same as VSIStat() except it works on "C:" as if it were "C:\".
Definition cpl_conv.cpp:2575
void CPLUnsubscribeToSetConfigOption(int nSubscriberId)
Remove a subscriber installed with CPLSubscribeToSetConfigOption()
Definition cpl_conv.cpp:1908
double CPLDecToPackedDMS(double dfDec)
Convert decimal degrees into packed DMS value (DDDMMMSSS.SS).
Definition cpl_conv.cpp:2833
const char * CPLExtractRelativePath(const char *, const char *, int *)
Get relative path from directory to target file.
Definition cpl_path.cpp:1155
const char * CPLGetThreadLocalConfigOption(const char *, const char *)
Same as CPLGetConfigOption() but only with options set with CPLSetThreadLocalConfigOption()
Definition cpl_conv.cpp:1795
void CPLPopFinderLocation(void)
CPLPopFinderLocation.
Definition cpl_findfile.cpp:274
double CPLAtofM(const char *)
Converts ASCII string to floating point number using any numeric locale.
Definition cpl_strtod.cpp:127
void CPLSetConfigOption(const char *, const char *)
Set a configuration option for GDAL/OGR use.
Definition cpl_conv.cpp:2111
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:395
GIntBig CPLAtoGIntBig(const char *pszString)
Convert a string to a 64 bit signed integer.
Definition cpl_conv.cpp:1027
double CPLPackedDMSToDec(double)
Convert a packed DMS value (DDDMMMSSS.SS) into decimal degrees.
Definition cpl_conv.cpp:2799
void CPLDumpSharedList(FILE *)
Report open shared files.
Definition cpl_conv.cpp:3136
int CPLUnlinkTree(const char *)
Recursively unlink a directory.
Definition cpl_conv.cpp:3170
int CPLSubscribeToSetConfigOption(CPLSetConfigOptionSubscriber pfnCallback, void *pUserData)
Install a callback that will be notified of calls to CPLSetConfigOption()/ CPLSetThreadLocalConfigOpt...
Definition cpl_conv.cpp:1876
const char * CPLProjectRelativeFilename(const char *pszProjectDir, const char *pszSecondaryFilename)
Find a file relative to a project file.
Definition cpl_path.cpp:1088
GUIntBig CPLScanUIntBig(const char *, int)
Extract big integer from string.
Definition cpl_conv.cpp:1002
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:2709
const char * CPLFindFile(const char *pszClass, const char *pszBasename)
CPLFindFile.
Definition cpl_findfile.cpp:164
double CPLScanDouble(const char *, int)
Extract double from string.
Definition cpl_conv.cpp:1186
int CPLIsPowerOfTwo(unsigned int i)
Definition cpl_conv.cpp:3579
const char * CPLGetConfigOption(const char *, const char *)
Get the value of a configuration option.
Definition cpl_conv.cpp:1705
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:972
void CPLSetThreadLocalConfigOption(const char *pszKey, const char *pszValue)
Set a configuration option for GDAL/OGR use.
Definition cpl_conv.cpp:2176
double CPLStrtodDelim(const char *, char **, char)
Converts ASCII string to floating point number using specified delimiter.
Definition cpl_strtod.cpp:218
void CPLUnlockFileEx(CPLLockFileHandle hLockFileHandle)
Release and delete a lock file.
Definition cpl_conv.cpp:3946
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:507
int CPLGetRemainingFileDescriptorCount(void)
Return the number of file descriptors that can still be opened by the current process.
Definition cpl_conv.cpp:4063
const char * CPLGetFilename(const char *)
Extract non-directory portion of filename.
Definition cpl_path.cpp:391
char * CPLStrlwr(char *)
Convert each characters of the string to lower case.
Definition cpl_conv.cpp:349
CPLLockFileStatus
Return code of CPLLockFileEx().
Definition cpl_conv.h:338
@ CLFS_OK
CPLLockFileEx() succeeded.
Definition cpl_conv.h:339
@ CLFS_LOCK_BUSY
Lock already taken (and still alive).
Definition cpl_conv.h:341
@ CLFS_CANNOT_CREATE_LOCK
Lock file creation failed.
Definition cpl_conv.h:340
@ CLFS_API_MISUSE
API misuse.
Definition cpl_conv.h:342
@ CLFS_THREAD_CREATION_FAILED
Thread creation failed.
Definition cpl_conv.h:343
int CPLCopyFile(const char *pszNewPath, const char *pszOldPath)
Copy a file.
Definition cpl_conv.cpp:3253
char ** CPLGetKnownConfigOptions(void)
Return the list of known configuration options.
Definition cpl_conv.cpp:2018
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:860
int CPLPrintDouble(char *, const char *, double, const char *)
Print double value into specified string buffer.
Definition cpl_conv.cpp:1457
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:3680
int CPLPrintString(char *, const char *, int)
Copy the string pointed to by pszSrc, NOT including the terminating ‘\0’ character,...
Definition cpl_conv.cpp:1238
CPLErr CPLCloseFileInZip(void *hZip)
Close current file inside ZIP file.
Definition cpl_conv.cpp:3670
const char * CPLDefaultFindFile(const char *pszClass, const char *pszBasename)
CPLDefaultFindFile.
Definition cpl_findfile.cpp:132
CPLErr CPLWriteFileInZip(void *hZip, const void *pBuffer, int nBufferSize)
Write in current file inside a ZIP file.
Definition cpl_conv.cpp:3665
CPLFileFinder CPLPopFileFinder(void)
CPLPopFileFinder.
Definition cpl_findfile.cpp:224
int CPLPrintPointer(char *, void *, int)
Print pointer value into specified string buffer.
Definition cpl_conv.cpp:1413
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:2247
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:5087
CPLSharedFileInfo * CPLGetSharedList(int *)
Fetch list of open shared files.
Definition cpl_conv.cpp:3114
double CPLAtof(const char *)
Converts ASCII string to floating point number.
Definition cpl_strtod.cpp:102
CPL error handling services.
#define CPLAssert(expr)
Assert on an expression.
Definition cpl_error.h:353
CPLErr
Error category / error level.
Definition cpl_error.h:45
Core portability definitions for CPL.
unsigned long long GUIntBig
Large unsigned integer type (generally 64-bit unsigned integer type).
Definition cpl_port.h:198
#define CPL_C_END
Macro to end a block of C symbols.
Definition cpl_port.h:279
#define CPL_C_START
Macro to start a block of C symbols.
Definition cpl_port.h:275
#define CPL_RETURNS_NONNULL
Qualifier for a function that does not return NULL.
Definition cpl_port.h:1073
#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:1101
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition cpl_port.h:1252
#define CPL_WARN_UNUSED_RESULT
Qualifier to warn when the return value of a function is not used.
Definition cpl_port.h:1035
int GInt32
Int32 type.
Definition cpl_port.h:155
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition cpl_port.h:195
Standard C Covers.
Information on a shared file.
Definition cpl_conv.h:293
char * pszAccess
Access mode.
Definition cpl_conv.h:298
FILE * fp
File pointer.
Definition cpl_conv.h:294
int nRefCount
Reference counter.
Definition cpl_conv.h:295
char * pszFilename
Filename.
Definition cpl_conv.h:297
int bLarge
Whether fp must be interpreted as VSIFILE*.
Definition cpl_conv.h:296
Virtual file handle.
Definition cpl_vsi_virtual.h:48