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
32
33/* -------------------------------------------------------------------- */
34/* Runtime check of various configuration items. */
35/* -------------------------------------------------------------------- */
37
39void CPL_DLL CPLVerifyConfiguration(void);
41
42bool CPL_DLL CPLIsDebugEnabled(void);
43
44const char CPL_DLL *CPL_STDCALL CPLGetConfigOption(const char *, const char *)
46const char CPL_DLL *CPL_STDCALL CPLGetThreadLocalConfigOption(
47 const char *, const char *) CPL_WARN_UNUSED_RESULT;
48const char CPL_DLL *CPL_STDCALL
49CPLGetGlobalConfigOption(const char *, const char *) CPL_WARN_UNUSED_RESULT;
50void CPL_DLL CPL_STDCALL CPLSetConfigOption(const char *, const char *);
51void CPL_DLL CPL_STDCALL CPLSetThreadLocalConfigOption(const char *pszKey,
52 const char *pszValue);
53void CPL_DLL CPLDeclareKnownConfigOption(const char *pszKey,
54 const char *pszDefinition);
55char CPL_DLL **CPLGetKnownConfigOptions(void);
56
58typedef void (*CPLSetConfigOptionSubscriber)(const char *pszKey,
59 const char *pszValue,
60 bool bThreadLocal,
61 void *pUserData);
63 CPLSetConfigOptionSubscriber pfnCallback, void *pUserData);
64void CPL_DLL CPLUnsubscribeToSetConfigOption(int nSubscriberId);
65
67void CPL_DLL CPL_STDCALL CPLFreeConfig(void);
69char CPL_DLL **CPLGetConfigOptions(void);
70void CPL_DLL CPLSetConfigOptions(const char *const *papszConfigOptions);
71char CPL_DLL **CPLGetThreadLocalConfigOptions(void);
72void CPL_DLL
73CPLSetThreadLocalConfigOptions(const char *const *papszConfigOptions);
74void CPL_DLL CPLLoadConfigOptionsFromFile(const char *pszFilename,
75 int bOverrideEnvVars);
77
78/* -------------------------------------------------------------------- */
79/* Safe malloc() API. Thin cover over VSI functions with fatal */
80/* error reporting if memory allocation fails. */
81/* -------------------------------------------------------------------- */
82void CPL_DLL *CPLMalloc(size_t) CPL_WARN_UNUSED_RESULT;
83void CPL_DLL *CPLCalloc(size_t, size_t) CPL_WARN_UNUSED_RESULT;
84void CPL_DLL *CPLRealloc(void *, size_t) CPL_WARN_UNUSED_RESULT;
85char CPL_DLL *
87char 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/* -------------------------------------------------------------------- */
95char CPL_DLL *CPLFGets(char *, int, FILE *);
96const char CPL_DLL *CPLReadLine(FILE *);
97const char CPL_DLL *CPLReadLineL(VSILFILE *);
98const char CPL_DLL *CPLReadLine2L(VSILFILE *, int, CSLConstList);
99const 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/* -------------------------------------------------------------------- */
105double CPL_DLL CPLAtof(const char *);
106double CPL_DLL CPLAtofDelim(const char *, char);
107double CPL_DLL CPLStrtod(const char *, char **);
108double CPL_DLL CPLStrtodM(const char *, char **);
109double CPL_DLL CPLStrtodDelim(const char *, char **, char);
110float CPL_DLL CPLStrtof(const char *, char **);
111float 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/* -------------------------------------------------------------------- */
117double CPL_DLL CPLAtofM(const char *);
118
119/* -------------------------------------------------------------------- */
120/* Read a numeric value from an ASCII character string. */
121/* -------------------------------------------------------------------- */
122char CPL_DLL *CPLScanString(const char *, int, int, int);
123double CPL_DLL CPLScanDouble(const char *, int);
124long CPL_DLL CPLScanLong(const char *, int);
125unsigned long CPL_DLL CPLScanULong(const char *, int);
126GUIntBig CPL_DLL CPLScanUIntBig(const char *, int);
127GIntBig CPL_DLL CPLAtoGIntBig(const char *pszString);
128GIntBig CPL_DLL CPLAtoGIntBigEx(const char *pszString, int bWarn,
129 int *pbOverflow);
130void CPL_DLL *CPLScanPointer(const char *, int);
131
132/* -------------------------------------------------------------------- */
133/* Print a value to an ASCII character string. */
134/* -------------------------------------------------------------------- */
135int CPL_DLL CPLPrintString(char *, const char *, int);
136int CPL_DLL CPLPrintStringFill(char *, const char *, int);
137int CPL_DLL CPLPrintInt32(char *, GInt32, int);
138int CPL_DLL CPLPrintUIntBig(char *, GUIntBig, int);
139int CPL_DLL CPLPrintDouble(char *, const char *, double, const char *);
140int CPL_DLL CPLPrintTime(char *, int, const char *, const struct tm *,
141 const char *);
142int CPL_DLL CPLPrintPointer(char *, void *, int);
143
144#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
145extern "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
156void CPL_DLL *CPLGetSymbol(const char *, const char *);
157
158/* -------------------------------------------------------------------- */
159/* Fetch executable path. */
160/* -------------------------------------------------------------------- */
161int 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))
170const char CPL_DLL *
172const char CPL_DLL *
174const char CPL_DLL *
176const char CPL_DLL *
178const char CPL_DLL *CPLFormFilename(
179 const char *pszPath, const char *pszBasename,
180 const char *pszExtension) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
181const char CPL_DLL *CPLFormCIFilename(
182 const char *pszPath, const char *pszBasename,
183 const char *pszExtension) CPL_WARN_UNUSED_RESULT CPL_RETURNS_NONNULL;
184const char CPL_DLL *CPLResetExtension(const char *, const char *)
186const char CPL_DLL *CPLProjectRelativeFilename(const char *pszProjectDir,
187 const char *pszSecondaryFilename)
189const char CPL_DLL *
191const char CPL_DLL *CPLGenerateTempFilename(const char *pszStem)
193const char CPL_DLL *CPLExpandTilde(const char *pszFilename)
195const char CPL_DLL *
196CPLLaunderForFilename(const char *pszName,
197 const char *pszOutputPath) CPL_WARN_UNUSED_RESULT;
198#endif
199
200char CPL_DLL *CPLGetCurrentDir(void);
201const char CPL_DLL *
203int CPL_DLL CPLIsFilenameRelative(const char *pszFilename);
204const char CPL_DLL *CPLExtractRelativePath(const char *, const char *, int *)
206char CPL_DLL **
207CPLCorrespondingPaths(const char *pszOldFilename, const char *pszNewFilename,
208 char **papszFileList) CPL_WARN_UNUSED_RESULT;
209int CPL_DLL CPLCheckForFile(char *pszFilename, CSLConstList papszSiblingList);
210
211const char CPL_DLL *CPLGetHomeDir(void) CPL_WARN_UNUSED_RESULT;
212
213#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
214
215extern "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 *)
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 *)
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)
235 std::string CPL_DLL CPLGenerateTempFilenameSafe(const char *pszStem)
237 std::string CPL_DLL CPLExpandTildeSafe(const char *pszFilename)
239 std::string CPL_DLL CPLLaunderForFilenameSafe(
240 const char *pszName, const char *pszOutputPath) CPL_WARN_UNUSED_RESULT;
241}
242
243#endif // defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
244
245bool CPL_DLL CPLHasPathTraversal(const char *pszFilename);
246bool CPL_DLL CPLHasUnbalancedPathTraversal(const char *pszFilename);
247
248/* -------------------------------------------------------------------- */
249/* Find File Function */
250/* -------------------------------------------------------------------- */
251
253typedef char const *(*CPLFileFinder)(const char *, const char *);
254
255const char CPL_DLL *CPLFindFile(const char *pszClass, const char *pszBasename);
256const char CPL_DLL *CPLDefaultFindFile(const char *pszClass,
257 const char *pszBasename);
258void CPL_DLL CPLPushFileFinder(CPLFileFinder pfnFinder);
259CPLFileFinder CPL_DLL CPLPopFileFinder(void);
260void CPL_DLL CPLPushFinderLocation(const char *);
261void CPL_DLL CPLPopFinderLocation(void);
262void CPL_DLL CPLFinderClean(void);
263
264/* -------------------------------------------------------------------- */
265/* Safe version of stat() that works properly on stuff like "C:". */
266/* -------------------------------------------------------------------- */
267int CPL_DLL CPLStat(const char *, VSIStatBuf *) CPL_WARN_UNUSED_RESULT;
268
269/* -------------------------------------------------------------------- */
270/* Reference counted file handle manager. Makes sharing file */
271/* handles more practical. */
272/* -------------------------------------------------------------------- */
273
275typedef struct
276{
277 FILE *fp;
279 int bLarge;
281 char *pszAccess;
283
284FILE CPL_DLL *CPLOpenShared(const char *, const char *, int);
285void CPL_DLL CPLCloseShared(FILE *);
286CPLSharedFileInfo CPL_DLL *CPLGetSharedList(int *);
287void CPL_DLL CPLDumpSharedList(FILE *);
289void CPL_DLL CPLCleanupSharedFileMutex(void);
291
292/* -------------------------------------------------------------------- */
293/* DMS to Dec to DMS conversion. */
294/* -------------------------------------------------------------------- */
295double CPL_DLL CPLDMSToDec(const char *is);
296const char CPL_DLL *CPLDecToDMS(double dfAngle, const char *pszAxis,
297 int nPrecision);
298double CPL_DLL CPLPackedDMSToDec(double);
299double CPL_DLL CPLDecToPackedDMS(double dfDec);
300
301CPLErr CPL_DLL CPLStringToComplex(const char *pszString, double *pdfReal,
302 double *pdfImag);
303
304/* -------------------------------------------------------------------- */
305/* Misc other functions. */
306/* -------------------------------------------------------------------- */
307int CPL_DLL CPLUnlinkTree(const char *);
308int CPL_DLL CPLCopyFile(const char *pszNewPath, const char *pszOldPath);
309int CPL_DLL CPLCopyTree(const char *pszNewPath, const char *pszOldPath);
310int CPL_DLL CPLMoveFile(const char *pszNewPath, const char *pszOldPath);
311int CPL_DLL CPLSymlink(const char *pszOldPath, const char *pszNewPath,
312 CSLConstList papszOptions);
313int CPL_DLL CPLGetRemainingFileDescriptorCount(void);
314
315/* -------------------------------------------------------------------- */
316/* Lock related functions. */
317/* -------------------------------------------------------------------- */
318
328
330typedef struct CPLLockFileStruct *CPLLockFileHandle;
331
332CPLLockFileStatus CPL_DLL CPLLockFileEx(const char *pszLockFileName,
333 CPLLockFileHandle *phLockFileHandle,
334 CSLConstList papszOptions);
335
336void CPL_DLL CPLUnlockFileEx(CPLLockFileHandle hLockFileHandle);
337
338/* -------------------------------------------------------------------- */
339/* ZIP Creation. */
340/* -------------------------------------------------------------------- */
341
343#define CPL_ZIP_API_OFFERED
345void CPL_DLL *CPLCreateZip(const char *pszZipFilename, char **papszOptions);
346CPLErr CPL_DLL CPLCreateFileInZip(void *hZip, const char *pszFilename,
347 char **papszOptions);
348CPLErr CPL_DLL CPLWriteFileInZip(void *hZip, const void *pBuffer,
349 int nBufferSize);
350CPLErr CPL_DLL CPLCloseFileInZip(void *hZip);
351CPLErr CPL_DLL CPLAddFileInZip(void *hZip, const char *pszArchiveFilename,
352 const char *pszInputFilename, VSILFILE *fpInput,
353 CSLConstList papszOptions,
354 GDALProgressFunc pProgressFunc,
355 void *pProgressData);
356CPLErr CPL_DLL CPLCloseZip(void *hZip);
357
358/* -------------------------------------------------------------------- */
359/* ZLib compression */
360/* -------------------------------------------------------------------- */
361
362void CPL_DLL *CPLZLibDeflate(const void *ptr, size_t nBytes, int nLevel,
363 void *outptr, size_t nOutAvailableBytes,
364 size_t *pnOutBytes);
365void CPL_DLL *CPLZLibInflate(const void *ptr, size_t nBytes, void *outptr,
366 size_t nOutAvailableBytes, size_t *pnOutBytes);
367void CPL_DLL *CPLZLibInflateEx(const void *ptr, size_t nBytes, void *outptr,
368 size_t nOutAvailableBytes,
369 bool bAllowResizeOutptr, size_t *pnOutBytes);
370
371/* -------------------------------------------------------------------- */
372/* XML validation. */
373/* -------------------------------------------------------------------- */
374int CPL_DLL CPLValidateXML(const char *pszXMLFilename,
375 const char *pszXSDFilename,
376 CSLConstList papszOptions);
377
378/* -------------------------------------------------------------------- */
379/* Locale handling. Prevents parallel executions of setlocale(). */
380/* -------------------------------------------------------------------- */
381char *CPLsetlocale(int category, const char *locale);
383void CPLCleanupSetlocaleMutex(void);
385
391int CPL_DLL CPLIsPowerOfTwo(unsigned int i);
392
393/* -------------------------------------------------------------------- */
394/* Terminal related */
395/* -------------------------------------------------------------------- */
396
397bool CPL_DLL CPLIsInteractive(FILE *f);
398
400
401/* -------------------------------------------------------------------- */
402/* C++ object for temporarily forcing a LC_NUMERIC locale to "C". */
403/* -------------------------------------------------------------------- */
404
406#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
407
408extern "C++"
409{
410 class CPL_DLL CPLLocaleC
411 {
412 CPL_DISALLOW_COPY_ASSIGN(CPLLocaleC)
413 public:
414 CPLLocaleC();
415 ~CPLLocaleC();
416
417 private:
418 char *pszOldLocale;
419 };
420
421 // Does the same as CPLLocaleC except that, when available, it tries to
422 // only affect the current thread. But code that would be dependent of
423 // setlocale(LC_NUMERIC, NULL) returning "C", such as current proj.4
424 // versions, will not work depending on the actual implementation
425 class CPLThreadLocaleCPrivate;
426
427 class CPL_DLL CPLThreadLocaleC
428 {
429 CPL_DISALLOW_COPY_ASSIGN(CPLThreadLocaleC)
430
431 public:
432 CPLThreadLocaleC();
433 ~CPLThreadLocaleC();
434
435 private:
436 CPLThreadLocaleCPrivate *m_private;
437 };
438}
439
440#endif /* def __cplusplus */
442
443/* -------------------------------------------------------------------- */
444/* C++ object for temporarily forcing a config option */
445/* -------------------------------------------------------------------- */
446
448#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
449
450extern "C++"
451{
452 class CPL_DLL CPLConfigOptionSetter
453 {
454 CPL_DISALLOW_COPY_ASSIGN(CPLConfigOptionSetter)
455 public:
456 CPLConfigOptionSetter(const char *pszKey, const char *pszValue,
457 bool bSetOnlyIfUndefined);
458 ~CPLConfigOptionSetter();
459
460 private:
461 char *m_pszKey;
462 char *m_pszOldValue;
463 bool m_bRestoreOldValue;
464 };
465}
466
467#endif /* def __cplusplus */
469
470#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
471
472extern "C++"
473{
474
475#ifndef DOXYGEN_SKIP
476#include <type_traits> // for std::is_base_of
477#endif
478
479 namespace cpl
480 {
490 template <typename To, typename From> inline To down_cast(From *f)
491 {
492 static_assert(
493 (std::is_base_of<From,
494 typename std::remove_pointer<To>::type>::value),
495 "target type not derived from source type");
496 CPLAssert(f == nullptr || dynamic_cast<To>(f) != nullptr);
497 return static_cast<To>(f);
498 }
499
501 template <class T, class U> inline T div_round_up(T a, U b)
502 {
503 return a / b + (((a % b) == 0) ? 0 : 1);
504 }
505
506 } // namespace cpl
507} // extern "C++"
508
509#endif /* def __cplusplus */
510
511#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:3948
std::string CPLGenerateTempFilenameSafe(const char *pszStem)
Generate temporary file name.
Definition cpl_path.cpp:1428
const char * CPLGetHomeDir(void)
Return the path to the home directory.
Definition cpl_path.cpp:1545
const char * CPLExpandTilde(const char *pszFilename)
Expands ~/ at start of filename.
Definition cpl_path.cpp:1524
void CPLDeclareKnownConfigOption(const char *pszKey, const char *pszDefinition)
Declare that the specified configuration option is known.
Definition cpl_conv.cpp:1972
void(* CPLSetConfigOptionSubscriber)(const char *pszKey, const char *pszValue, bool bThreadLocal, void *pUserData)
Callback for CPLSubscribeToSetConfigOption().
Definition cpl_conv.h:58
void * CPLCreateZip(const char *pszZipFilename, char **papszOptions)
Create ZIP file.
Definition cpl_conv.cpp:3599
double CPLAtofDelim(const char *, char)
Converts ASCII string to floating point number.
Definition cpl_strtod.cpp:58
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:1115
std::string CPLFormCIFilenameSafe(const char *pszPath, const char *pszBasename, const char *pszExtension=nullptr)
Case insensitive file searching, returning full path.
Definition cpl_path.cpp:898
const char * CPLReadLine2L(VSILFILE *, int, CSLConstList)
Simplified line reading from text file.
Definition cpl_conv.cpp:680
std::string CPLLaunderForFilenameSafe(const char *pszName, const char *pszOutputPath)
Launder a string to be compatible of a filename.
Definition cpl_path.cpp:1570
int CPLPrintUIntBig(char *, GUIntBig, int)
Print GUIntBig value into specified string buffer.
Definition cpl_conv.cpp:1357
std::string CPLProjectRelativeFilenameSafe(const char *pszProjectDir, const char *pszSecondaryFilename)
Find a file relative to a project file.
Definition cpl_path.cpp:1037
int CPLCopyTree(const char *pszNewPath, const char *pszOldPath)
Recursively copy a tree.
Definition cpl_conv.cpp:3219
void CPLCloseShared(FILE *)
Close shared file.
Definition cpl_conv.cpp:2976
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:3500
const char * CPLReadLine3L(VSILFILE *, int, int *, CSLConstList)
Simplified line reading from text file.
Definition cpl_conv.cpp:707
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:501
struct CPLLockFileStruct * CPLLockFileHandle
Handle type returned by CPLLockFileEx().
Definition cpl_conv.h:330
const char * CPLGetExtension(const char *)
Extract filename extension from full filename.
Definition cpl_path.cpp:548
void CPLLoadConfigOptionsFromFile(const char *pszFilename, int bOverrideEnvVars)
Load configuration from a given configuration file.
Definition cpl_conv.cpp:2291
int CPLMoveFile(const char *pszNewPath, const char *pszOldPath)
Move a file.
Definition cpl_conv.cpp:3294
std::string CPLGetExtensionSafe(const char *)
Extract filename extension from full filename.
Definition cpl_path.cpp:497
std::string CPLResetExtensionSafe(const char *, const char *)
Replace the extension with the provided one.
Definition cpl_path.cpp:619
std::string CPLExpandTildeSafe(const char *pszFilename)
Expands ~/ at start of filename.
Definition cpl_path.cpp:1494
std::string CPLGetBasenameSafe(const char *)
Extract basename (non-directory, non-extension) portion of filename.
Definition cpl_path.cpp:422
char ** CPLGetThreadLocalConfigOptions(void)
Return the list of thread local configuration options as KEY=VALUE pairs.
Definition cpl_conv.cpp:2171
CPLLockFileStatus CPLLockFileEx(const char *pszLockFileName, CPLLockFileHandle *phLockFileHandle, CSLConstList papszOptions)
Create and acquire a lock file.
Definition cpl_conv.cpp:3767
int CPLPrintInt32(char *, GInt32, int)
Copy the string pointed to by pszSrc, NOT including the terminating `\0' character,...
Definition cpl_conv.cpp:1318
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
std::string CPLGetDirnameSafe(const char *)
Extract directory path portion of filename.
Definition cpl_path.cpp:273
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:1769
void * CPLRealloc(void *, size_t)
Safe version of realloc().
Definition cpl_conv.cpp:247
char const *(* CPLFileFinder)(const char *, const char *)
Callback for CPLPushFileFinder.
Definition cpl_conv.h:253
float CPLStrtofDelim(const char *, char **, char)
Converts ASCII string to floating point number using specified delimiter.
Definition cpl_strtod.cpp:452
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:3635
int CPLSymlink(const char *pszOldPath, const char *pszNewPath, CSLConstList papszOptions)
Create a symbolic link.
Definition cpl_conv.cpp:3318
const char * CPLGetBasename(const char *)
Extract basename (non-directory, non-extension) portion of filename.
Definition cpl_path.cpp:467
const char * CPLLaunderForFilename(const char *pszName, const char *pszOutputPath)
Launder a string to be compatible of a filename.
Definition cpl_path.cpp:1603
void * CPLMalloc(size_t)
Safe version of malloc().
Definition cpl_conv.cpp:192
const char * CPLGetDirname(const char *)
Extract directory path portion of filename.
Definition cpl_path.cpp:361
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:1629
const char * CPLFormCIFilename(const char *pszPath, const char *pszBasename, const char *pszExtension)
Case insensitive file searching, returning full path.
Definition cpl_path.cpp:997
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
bool CPLIsDebugEnabled(void)
Returns whether CPL_DEBUG is enabled.
Definition cpl_conv.cpp:1932
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
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:1671
void * CPLCalloc(size_t, size_t)
Safe version of calloc().
Definition cpl_conv.cpp:162
GIntBig CPLAtoGIntBigEx(const char *pszString, int bWarn, int *pbOverflow)
Convert a string to a 64 bit signed integer.
Definition cpl_conv.cpp:1064
void * CPLScanPointer(const char *, int)
Extract pointer from string.
Definition cpl_conv.cpp:1112
const char * CPLGenerateTempFilename(const char *pszStem)
Generate temporary file name.
Definition cpl_path.cpp:1471
const char * CPLGetPath(const char *)
Extract directory path portion of filename.
Definition cpl_path.cpp:241
char ** CPLCorrespondingPaths(const char *pszOldFilename, const char *pszNewFilename, char **papszFileList)
Identify corresponding paths.
Definition cpl_path.cpp:1319
CPLErr CPLStringToComplex(const char *pszString, double *pdfReal, double *pdfImag)
Fetch the real and imaginary part of a serialized complex number.
Definition cpl_conv.cpp:2803
char * CPLStrdup(const char *)
Safe version of strdup() function.
Definition cpl_conv.cpp:315
CPLErr CPLCreateFileInZip(void *hZip, const char *pszFilename, char **papszOptions)
Create a file in a ZIP file.
Definition cpl_conv.cpp:3607
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:708
void CPLLoadConfigOptionsFromPredefinedFiles(void)
Load configuration from a set of predefined files.
Definition cpl_conv.cpp:2487
char ** CPLGetConfigOptions(void)
Return the list of configuration options as KEY=VALUE pairs.
Definition cpl_conv.cpp:1744
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:2577
int CPLCheckForFile(char *pszFilename, CSLConstList papszSiblingList)
Check for file existence.
Definition cpl_conv.cpp:3561
const char * CPLCleanTrailingSlash(const char *)
Remove trailing forward/backward slash from the path for UNIX/Windows resp.
Definition cpl_path.cpp:1284
const char * CPLReadLineL(VSILFILE *)
Simplified line reading from text file.
Definition cpl_conv.cpp:656
const char * CPLReadLine(FILE *)
Simplified line reading from text file.
Definition cpl_conv.cpp:588
bool CPLIsInteractive(FILE *f)
Returns whether the provided file refers to a terminal.
Definition cpl_conv.cpp:3701
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:3622
std::string CPLGetPathSafe(const char *)
Extract directory path portion of filename.
Definition cpl_path.cpp:151
const char * CPLGetGlobalConfigOption(const char *, const char *)
Same as CPLGetConfigOption() but excludes environment variables and options set with CPLSetThreadLoca...
Definition cpl_conv.cpp:1814
const char * CPLResetExtension(const char *, const char *)
Replace the extension with the provided one.
Definition cpl_path.cpp:668
std::string CPLCleanTrailingSlashSafe(const char *pszPath)
Remove trailing forward/backward slash from the path for UNIX/Windows resp.
Definition cpl_path.cpp:1248
FILE * CPLOpenShared(const char *, const char *, int)
Open a shared file handle.
Definition cpl_conv.cpp:2904
void CPLPushFinderLocation(const char *)
CPLPushFinderLocation.
Definition cpl_findfile.cpp:235
char * CPLGetCurrentDir(void)
Get the current working directory name.
Definition cpl_path.cpp:598
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:2528
void CPLUnsubscribeToSetConfigOption(int nSubscriberId)
Remove a subscriber installed with CPLSubscribeToSetConfigOption().
Definition cpl_conv.cpp:1878
double CPLDecToPackedDMS(double dfDec)
Convert decimal degrees into packed DMS value (DDDMMMSSS.SS).
Definition cpl_conv.cpp:2786
const char * CPLExtractRelativePath(const char *, const char *, int *)
Get relative path from directory to target file.
Definition cpl_path.cpp:1157
const char * CPLGetThreadLocalConfigOption(const char *, const char *)
Same as CPLGetConfigOption() but only with options set with CPLSetThreadLocalConfigOption().
Definition cpl_conv.cpp:1783
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:2073
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
GIntBig CPLAtoGIntBig(const char *pszString)
Convert a string to a 64 bit signed integer.
Definition cpl_conv.cpp:1019
double CPLPackedDMSToDec(double)
Convert a packed DMS value (DDDMMMSSS.SS) into decimal degrees.
Definition cpl_conv.cpp:2752
void CPLDumpSharedList(FILE *)
Report open shared files.
Definition cpl_conv.cpp:3089
int CPLUnlinkTree(const char *)
Recursively unlink a directory.
Definition cpl_conv.cpp:3123
int CPLSubscribeToSetConfigOption(CPLSetConfigOptionSubscriber pfnCallback, void *pUserData)
Install a callback that will be notified of calls to CPLSetConfigOption()/ CPLSetThreadLocalConfigOpt...
Definition cpl_conv.cpp:1846
const char * CPLProjectRelativeFilename(const char *pszProjectDir, const char *pszSecondaryFilename)
Find a file relative to a project file.
Definition cpl_path.cpp:1090
GUIntBig CPLScanUIntBig(const char *, int)
Extract big integer from string.
Definition cpl_conv.cpp:994
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:2662
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:1178
int CPLIsPowerOfTwo(unsigned int i)
Definition cpl_conv.cpp:3526
const char * CPLGetConfigOption(const char *, const char *)
Get the value of a configuration option.
Definition cpl_conv.cpp:1697
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
void CPLSetThreadLocalConfigOption(const char *pszKey, const char *pszValue)
Set a configuration option for GDAL/OGR use.
Definition cpl_conv.cpp:2129
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:3892
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:490
int CPLGetRemainingFileDescriptorCount(void)
Return the number of file descriptors that can still be opened by the current process.
Definition cpl_conv.cpp:4009
const char * CPLGetFilename(const char *)
Extract non-directory portion of filename.
Definition cpl_path.cpp:390
char * CPLStrlwr(char *)
Convert each characters of the string to lower case.
Definition cpl_conv.cpp:341
CPLLockFileStatus
Return code of CPLLockFileEx().
Definition cpl_conv.h:321
@ CLFS_OK
CPLLockFileEx() succeeded.
Definition cpl_conv.h:322
@ CLFS_LOCK_BUSY
Lock already taken (and still alive).
Definition cpl_conv.h:324
@ CLFS_CANNOT_CREATE_LOCK
Lock file creation failed.
Definition cpl_conv.h:323
@ CLFS_API_MISUSE
API misuse.
Definition cpl_conv.h:325
@ CLFS_THREAD_CREATION_FAILED
Thread creation failed.
Definition cpl_conv.h:326
int CPLCopyFile(const char *pszNewPath, const char *pszOldPath)
Copy a file.
Definition cpl_conv.cpp:3206
char ** CPLGetKnownConfigOptions(void)
Return the list of known configuration options.
Definition cpl_conv.cpp:1988
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:862
int CPLPrintDouble(char *, const char *, double, const char *)
Print double value into specified string buffer.
Definition cpl_conv.cpp:1449
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:3627
CPLErr CPLCloseFileInZip(void *hZip)
Close current file inside ZIP file.
Definition cpl_conv.cpp:3617
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:3612
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:1405
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:2200
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
CPLSharedFileInfo * CPLGetSharedList(int *)
Fetch list of open shared files.
Definition cpl_conv.cpp:3067
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:330
CPLErr
Error category.
Definition cpl_error.h:37
Core portability definitions for CPL.
unsigned long long GUIntBig
Large unsigned integer type (generally 64-bit unsigned integer type).
Definition cpl_port.h:208
#define CPL_C_END
Macro to end a block of C symbols.
Definition cpl_port.h:289
#define CPL_C_START
Macro to start a block of C symbols.
Definition cpl_port.h:285
#define CPL_RETURNS_NONNULL
Qualifier for a function that does not return NULL.
Definition cpl_port.h:908
#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
char ** CSLConstList
Type of a constant null-terminated list of nul terminated strings.
Definition cpl_port.h:1087
#define CPL_WARN_UNUSED_RESULT
Qualifier to warn when the return value of a function is not used.
Definition cpl_port.h:870
int GInt32
Int32 type.
Definition cpl_port.h:165
long long GIntBig
Large signed integer type (generally 64-bit integer type).
Definition cpl_port.h:205
Standard C Covers.
struct VSIVirtualHandle VSILFILE
Opaque type for a FILE that implements the VSIVirtualHandle API.
Definition cpl_vsi.h:141
Information on a shared file.
Definition cpl_conv.h:276
char * pszAccess
Access mode.
Definition cpl_conv.h:281
FILE * fp
File pointer.
Definition cpl_conv.h:277
int nRefCount
Reference counter.
Definition cpl_conv.h:278
char * pszFilename
Filename.
Definition cpl_conv.h:280
int bLarge
Whether fp must be interpreted as VSIFILE*.
Definition cpl_conv.h:279