OGR
Classes | Macros | Typedefs | Functions
cpl_conv.h File Reference
#include "cpl_port.h"
#include "cpl_vsi.h"
#include "cpl_error.h"

Go to the source code of this file.

Classes

struct  CPLSharedFileInfo
 

Macros

#define CPLFree   VSIFree
 

Typedefs

typedef const char *(* CPLFileFinder )(const char *, const char *)
 

Functions

const char * CPLGetConfigOption (const char *, const char *)
 
const char * CPLGetThreadLocalConfigOption (const char *, const char *)
 
void CPLSetConfigOption (const char *, const char *)
 
void CPLSetThreadLocalConfigOption (const char *pszKey, const char *pszValue)
 
char ** CPLGetConfigOptions (void)
 
void CPLSetConfigOptions (const char *const *papszConfigOptions)
 
char ** CPLGetThreadLocalConfigOptions (void)
 
void CPLSetThreadLocalConfigOptions (const char *const *papszConfigOptions)
 
void * CPLMalloc (size_t)
 
void * CPLCalloc (size_t, size_t)
 
void * CPLRealloc (void *, size_t)
 
char * CPLStrdup (const char *)
 
char * CPLStrlwr (char *)
 
char * CPLFGets (char *, int, FILE *)
 
const char * CPLReadLine (FILE *)
 
const char * CPLReadLineL (VSILFILE *)
 
const char * CPLReadLine2L (VSILFILE *, int nMaxCols, const char *const *papszOptions)
 
double CPLAtof (const char *)
 
double CPLAtofDelim (const char *, char)
 
double CPLStrtod (const char *, char **)
 
double CPLStrtodDelim (const char *, char **, char)
 
float CPLStrtof (const char *, char **)
 
float CPLStrtofDelim (const char *, char **, char)
 
double CPLAtofM (const char *)
 
char * CPLScanString (const char *, int, int, int)
 
double CPLScanDouble (const char *, int)
 
long CPLScanLong (const char *, int)
 
unsigned long CPLScanULong (const char *, int)
 
GUIntBig CPLScanUIntBig (const char *, int)
 
GIntBig CPLAtoGIntBig (const char *pszString)
 
GIntBig CPLAtoGIntBigEx (const char *pszString, int bWarn, int *pbOverflow)
 
void * CPLScanPointer (const char *, int)
 
int CPLPrintString (char *, const char *, int)
 
int CPLPrintStringFill (char *, const char *, int)
 
int CPLPrintInt32 (char *, GInt32, int)
 
int CPLPrintUIntBig (char *, GUIntBig, int)
 
int CPLPrintDouble (char *, const char *, double, const char *)
 
int CPLPrintTime (char *, int, const char *, const struct tm *, const char *)
 
int CPLPrintPointer (char *, void *, int)
 
void * CPLGetSymbol (const char *, const char *)
 
int CPLGetExecPath (char *pszPathBuf, int nMaxLength)
 
const char * CPLGetPath (const char *)
 
const char * CPLGetDirname (const char *)
 
const char * CPLGetFilename (const char *)
 
const char * CPLGetBasename (const char *)
 
const char * CPLGetExtension (const char *)
 
char * CPLGetCurrentDir (void)
 
const char * CPLFormFilename (const char *pszPath, const char *pszBasename, const char *pszExtension)
 
const char * CPLFormCIFilename (const char *pszPath, const char *pszBasename, const char *pszExtension)
 
const char * CPLResetExtension (const char *, const char *)
 
const char * CPLProjectRelativeFilename (const char *pszProjectDir, const char *pszSecondaryFilename)
 
int CPLIsFilenameRelative (const char *pszFilename)
 
const char * CPLExtractRelativePath (const char *, const char *, int *)
 
const char * CPLCleanTrailingSlash (const char *)
 
char ** CPLCorrespondingPaths (const char *pszOldFilename, const char *pszNewFilename, char **papszFileList)
 
int CPLCheckForFile (char *pszFilename, char **papszSiblingList)
 
const char * CPLGenerateTempFilename (const char *pszStem)
 
const char * CPLExpandTilde (const char *pszFilename)
 
const char * CPLFindFile (const char *pszClass, const char *pszBasename)
 
const char * CPLDefaultFindFile (const char *pszClass, const char *pszBasename)
 
void CPLPushFileFinder (CPLFileFinder pfnFinder)
 
CPLFileFinder CPLPopFileFinder (void)
 
void CPLPushFinderLocation (const char *)
 
void CPLPopFinderLocation (void)
 
void CPLFinderClean (void)
 
int CPLStat (const char *, VSIStatBuf *)
 
FILE * CPLOpenShared (const char *, const char *, int)
 
void CPLCloseShared (FILE *)
 
CPLSharedFileInfoCPLGetSharedList (int *)
 
void CPLDumpSharedList (FILE *)
 
double CPLDMSToDec (const char *is)
 
const char * CPLDecToDMS (double dfAngle, const char *pszAxis, int nPrecision)
 
double CPLPackedDMSToDec (double)
 
double CPLDecToPackedDMS (double dfDec)
 
void CPLStringToComplex (const char *pszString, double *pdfReal, double *pdfImag)
 
int CPLUnlinkTree (const char *)
 
int CPLCopyFile (const char *pszNewPath, const char *pszOldPath)
 
int CPLCopyTree (const char *pszNewPath, const char *pszOldPath)
 
int CPLMoveFile (const char *pszNewPath, const char *pszOldPath)
 
int CPLSymlink (const char *pszOldPath, const char *pszNewPath, char **papszOptions)
 
void * CPLCreateZip (const char *pszZipFilename, char **papszOptions)
 
CPLErr CPLCreateFileInZip (void *hZip, const char *pszFilename, char **papszOptions)
 
CPLErr CPLWriteFileInZip (void *hZip, const void *pBuffer, int nBufferSize)
 
CPLErr CPLCloseFileInZip (void *hZip)
 
CPLErr CPLCloseZip (void *hZip)
 
void * CPLZLibInflate (const void *ptr, size_t nBytes, void *outptr, size_t nOutAvailableBytes, size_t *pnOutBytes)
 Uncompress a buffer compressed with ZLib DEFLATE compression. More...
 
char * CPLsetlocale (int category, const char *locale)
 

Detailed Description

Various convenience functions for CPL.

Macro Definition Documentation

#define CPLFree   VSIFree

Alias of VSIFree()

Referenced by OGRStyleMgr::AddPart(), CPLODBCStatement::AppendEscaped(), CPLODBCStatement::Clear(), OGR_SRSNode::ClearChildren(), CPLODBCStatement::ClearColumnData(), CPLCloseShared(), CPLCopyFile(), CPLDestroyXMLNode(), CPLFormCIFilename(), CPLHashSetDestroy(), CPLHTTPDestroyResult(), CPLHTTPFetch(), CPLListDestroy(), CPLListRemove(), CPLLoggingErrorHandler(), CPLParseXMLFile(), CPLParseXMLString(), CPLPrintTime(), CPLQuadTreeDestroy(), CPLScanDouble(), CPLSerializeXMLTreeToFile(), CPLSetXMLValue(), CPLStrtodDelim(), CPLStrtofDelim(), CPLUnescapeString(), CPLVirtualMemFree(), CSLAddNameValue(), CSLDestroy(), CSLMerge(), CSLRemoveStrings(), CSLSetNameValue(), CSLSetNameValueSeparator(), CSLTokenizeString2(), OGRGeometryFactory::curveToLineString(), OGRSpatialReference::dumpReadable(), OGRGeometry::dumpReadable(), OGRGeometryCollection::empty(), OGRPolyhedralSurface::empty(), OGRGeometry::exportToGEOS(), OGRPolygon::exportToWkt(), CPLODBCStatement::Fetch(), OGRFeature::FillUnsetWithDefault(), OGR_SRSNode::FixupOrdering(), OGRLayer::GetFeature(), OGRFeature::GetFieldAsString(), OGRStyleTool::GetStyleString(), OGRSpatialReference::importFromCRSURL(), OGRSpatialReference::importFromEPSGA(), OGRSpatialReference::importFromESRI(), OGRSpatialReference::importFromPanorama(), OGRSpatialReference::importFromPCI(), OGRSpatialReference::importFromProj4(), OGRSpatialReference::importFromURN(), OGRSpatialReference::importFromUSGS(), OGRPoint::importFromWkt(), OGRPolygon::importFromWkt(), OGRMultiSurface::importFromWkt(), OGRPolyhedralSurface::importFromWkt(), OGRMultiPoint::importFromWkt(), OGRStyleMgr::InitFromFeature(), OGRStyleMgr::InitStyleString(), OGRSpatialReference::morphFromESRI(), OGRSpatialReference::morphToESRI(), OGR_G_ExportToGMLEx(), OGR_G_ExportToGMLTree(), OGR_G_ExportToKML(), OGRGeocode(), OGRGeocodeDestroySession(), OGRGeometryFactory::organizePolygons(), CPLString::Recode(), OGRLayer::ReorderField(), OGRFeatureDefn::ReorderFieldDefns(), OGRSimpleCurve::segmentize(), CPLString::Seize(), OGRLayer::SetAttributeFilter(), OGRFieldDefn::SetDefault(), OGRFeature::SetField(), OGRFeature::SetFieldNull(), OGRSpatialReference::SetFromUserInput(), OGRSpatialReference::SetLinearUnitsAndUpdateParameters(), OGRFieldDefn::SetName(), OGRGeomFieldDefn::SetName(), CPLStringList::SetNameValue(), OGRFeature::SetNativeData(), OGRFeature::SetNativeMediaType(), OGRSimpleCurve::setNumPoints(), OGRFeature::SetStyleString(), OGRFeature::SetStyleStringDirectly(), OGR_SRSNode::SetValue(), CPLWorkerThreadPool::SubmitJob(), CPLWorkerThreadPool::SubmitJobs(), OGRProj4CT::Transform(), OGRSimpleCurve::transform(), OGRFeature::UnsetField(), OGRSpatialReference::Validate(), CPLString::vPrintf(), VSIReadDirRecursive(), VSISetCryptKey(), and OGRStyleMgr::~OGRStyleMgr().

Typedef Documentation

typedef const char*(* CPLFileFinder)(const char *, const char *)

Callback for CPLPushFileFinder

Function Documentation

double CPLAtof ( const char *  nptr)

Converts ASCII string to floating point number.

This function converts the initial portion of the string pointed to by nptr to double floating point representation. The behaviour is the same as

CPLStrtod(nptr, (char **)NULL);

This function does the same as standard atof(3), but does not take locale in account. That means, the decimal delimiter is always '.' (decimal point). Use CPLAtofDelim() function if you want to specify custom delimiter.

IMPORTANT NOTE:

Existence of this function does not mean you should always use it. Sometimes you should use standard locale aware atof(3) and its family. When you need to process the user's input (for example, command line parameters) use atof(3), because the user works in a localized environment and the user's input will be done according to the locale set. In particular that means we should not make assumptions about character used as decimal delimiter, it can be either "." or ",".

But when you are parsing some ASCII file in predefined format, you most likely need CPLAtof(), because such files distributed across the systems with different locales and floating point representation should be considered as a part of file format. If the format uses "." as a delimiter the same character must be used when parsing number regardless of actual locale setting.

Parameters
nptrPointer to string to convert.
Returns
Converted value, if any.

References CPLStrtod().

Referenced by OGRSpatialReference::CloneGeogCS(), CPLGetValueType(), CPLScanDouble(), CPLStringToComplex(), OGRSpatialReference::exportToPCI(), OGRSpatialReference::exportToProj4(), OGRSpatialReference::Fixup(), OGRSpatialReference::GetAngularUnits(), OGRFeature::GetFieldAsDouble(), OGRSpatialReference::GetInvFlattening(), OGRStyleTool::GetParamDbl(), OGRSpatialReference::GetPrimeMeridian(), OGRSpatialReference::GetProjParm(), OGRSpatialReference::GetSemiMajor(), OGRSpatialReference::GetTargetLinearUnits(), OGRSpatialReference::GetTOWGS84(), OGRSpatialReference::importFromERM(), OGRSpatialReference::importFromESRI(), OGRSpatialReference::importFromOzi(), OGRSpatialReference::importFromPCI(), OGRSpatialReference::importFromProj4(), OGRSpatialReference::importFromWMSAUTO(), OGRSpatialReference::IsSameGeogCS(), OGRSpatialReference::IsSameVertCS(), OGRFeature::SetField(), OGRSpatialReference::SetGeogCS(), OGRStyleTool::SetParamStr(), and OGRSpatialReference::SetStatePlane().

double CPLAtofDelim ( const char *  nptr,
char  point 
)

Converts ASCII string to floating point number.

This function converts the initial portion of the string pointed to by nptr to double floating point representation. The behaviour is the same as

CPLStrtodDelim(nptr, (char **)NULL, point);

This function does the same as standard atof(3), but does not take locale in account. Instead of locale defined decimal delimiter you can specify your own one. Also see notes for CPLAtof() function.

Parameters
nptrPointer to string to convert.
pointDecimal delimiter.
Returns
Converted value, if any.

References CPLStrtodDelim().

double CPLAtofM ( const char *  nptr)

Converts ASCII string to floating point number using any numeric locale.

This function converts the initial portion of the string pointed to by nptr to double floating point representation. This function does the same as standard atof(), but it allows a variety of locale representations. That is it supports numeric values with either a comma or a period for the decimal delimiter.

PS. The M stands for Multi-lingual.

Parameters
nptrThe string to convert.
Returns
Converted value, if any. Zero on failure.

References CPLStrtodDelim().

Referenced by OGRSpatialReference::importFromOzi(), OGRSpatialReference::importFromProj4(), OGRGeocodeCreateSession(), and OGRGeometryFactory::transformWithOptions().

GIntBig CPLAtoGIntBig ( const char *  pszString)

Convert a string to a 64 bit signed integer.

Parameters
pszStringString containing 64 bit signed integer.
Returns
64 bit signed integer.
Since
GDAL 2.0
GIntBig CPLAtoGIntBigEx ( const char *  pszString,
int  bWarn,
int *  pbOverflow 
)

Convert a string to a 64 bit signed integer.

Parameters
pszStringString containing 64 bit signed integer.
bWarnIssue a warning if an overflow occurs during conversion
pbOverflowPointer to an integer to store if an overflow occurred, or NULL
Returns
64 bit signed integer.
Since
GDAL 2.0

References CPLE_AppDefined, CPLError(), GINTBIG_MAX, and GINTBIG_MIN.

Referenced by OGRFeature::GetFieldAsInteger64(), and OGRFeature::SetField().

void* CPLCalloc ( size_t  nCount,
size_t  nSize 
)

Safe version of calloc().

This function is like the C library calloc(), but raises a CE_Fatal error with CPLError() if it fails to allocate the desired memory. It should be used for small memory allocations that are unlikely to fail and for which the application is unwilling to test for out of memory conditions. It uses VSICalloc() to get the memory, so any hooking of VSICalloc() will apply to CPLCalloc() as well. CPLFree() or VSIFree() can be used free memory allocated by CPLCalloc().

Parameters
nCountnumber of objects to allocate.
nSizesize (in bytes) of object to allocate.
Returns
pointer to newly allocated memory, only NULL if nSize * nCount is NULL.

References CPLMalloc().

Referenced by CPLODBCStatement::CollectResultsInfo(), CPLCreateXMLNode(), CPLHashSetNew(), CPLHTTPFetch(), CPLSerializeXMLTree(), CPLSPrintf(), CSLRemoveStrings(), CSLTokenizeString2(), OGR_SRSNode::exportToPrettyWkt(), OGR_SRSNode::exportToWkt(), OGRPolygon::exportToWkt(), OGR_SRSNode::FixupOrdering(), CPLODBCStatement::GetColumns(), OGRGeocodeCreateSession(), and OPTGetParameterList().

int CPLCheckForFile ( char *  pszFilename,
char **  papszSiblingFiles 
)

Check for file existence.

The function checks if a named file exists in the filesystem, hopefully in an efficient fashion if a sibling file list is available. It exists primarily to do faster file checking for functions like GDAL open methods that get a list of files from the target directory.

If the sibling file list exists (is not NULL) it is assumed to be a list of files in the same directory as the target file, and it will be checked (case insensitively) for a match. If a match is found, pszFilename is updated with the correct case and TRUE is returned.

If papszSiblingFiles is NULL, a VSIStatL() is used to test for the files existence, and no case insensitive testing is done.

Parameters
pszFilenamename of file to check for - filename case updated in some cases.
papszSiblingFilesa list of files in the same directory as pszFilename if available, or NULL. This list should have no path components.
Returns
TRUE if a match is found, or FALSE if not.

References CPLGetFilename(), EQUAL, and VSIStatL().

const char* CPLCleanTrailingSlash ( const char *  pszPath)

Remove trailing forward/backward slash from the path for UNIX/Windows resp.

Returns a string containing the portion of the passed path string with trailing slash removed. If there is no path in the passed filename an empty string will be returned (not NULL).

CPLCleanTrailingSlash( "abc/def/" ) == "abc/def"
CPLCleanTrailingSlash( "abc/def" ) == "abc/def"
CPLCleanTrailingSlash( "c:\abc\def\" ) == "c:\abc\def"
CPLCleanTrailingSlash( "c:\abc\def" ) == "c:\abc\def"
CPLCleanTrailingSlash( "abc" ) == "abc"
Parameters
pszPaththe path to be cleaned up
Returns
Path in an internal string which must not be freed. The string may be destroyed by the next CPL filename handling call.

References CPLAssert, and CPLStrlcpy().

CPLErr CPLCloseFileInZip ( void *  hZip)

Close current file inside ZIP file

void CPLCloseShared ( FILE *  fp)

Close shared file.

Dereferences the indicated file handle, and closes it if the reference count has dropped to zero. A CPLError() is issued if the file is not in the shared file list.

Parameters
fpfile handle from CPLOpenShared() to deaccess.

References CPLE_AppDefined, CPLE_FileIO, CPLError(), CPLFree, CPLSharedFileInfo::fp, and VSIFCloseL().

CPLErr CPLCloseZip ( void *  hZip)

Close ZIP file

int CPLCopyFile ( const char *  pszNewPath,
const char *  pszOldPath 
)
int CPLCopyTree ( const char *  pszNewPath,
const char *  pszOldPath 
)
char** CPLCorrespondingPaths ( const char *  pszOldFilename,
const char *  pszNewFilename,
char **  papszFileList 
)

Identify corresponding paths.

Given a prototype old and new filename this function will attempt to determine corresponding names for a set of other old filenames that will rename them in a similar manner. This correspondence assumes there are two possibly kinds of renaming going on. A change of path, and a change of filename stem.

If a consistent renaming cannot be established for all the files this function will return indicating an error.

The returned file list becomes owned by the caller and should be destroyed with CSLDestroy().

Parameters
pszOldFilenamepath to old prototype file.
pszNewFilenamepath to new prototype file.
papszFileListlist of other files associated with pszOldFilename to rename similarly.
Returns
a list of files corresponding to papszFileList but renamed to correspond to pszNewFilename.

References CPLE_AppDefined, CPLError(), CPLFormFilename(), CPLGetBasename(), CPLGetFilename(), CPLGetPath(), CSLAddString(), CSLCount(), EQUAL, and EQUALN.

CPLErr CPLCreateFileInZip ( void *  hZip,
const char *  pszFilename,
char **  papszOptions 
)

Create a file in a ZIP file

void* CPLCreateZip ( const char *  pszZipFilename,
char **  papszOptions 
)

Create ZIP file

References CPLE_NotSupported, and CPLError().

const char* CPLDecToDMS ( double  dfAngle,
const char *  pszAxis,
int  nPrecision 
)

Translate a decimal degrees value to a DMS string with hemisphere.

References CPLsnprintf(), EQUAL, and VALIDATE_POINTER1.

double CPLDecToPackedDMS ( double  dfDec)

Convert decimal degrees into packed DMS value (DDDMMMSSS.SS).

This function converts a value, specified in decimal degrees into packed DMS angle. The standard packed DMS format is:

degrees * 1000000 + minutes * 1000 + seconds

See also CPLPackedDMSToDec().

Parameters
dfDecAngle in decimal degrees.
Returns
Angle in packed DMS format.

Referenced by OGRSpatialReference::exportToUSGS().

const char* CPLDefaultFindFile ( const char *  ,
const char *  pszBasename 
)

CPLDefaultFindFile

References CPLFormFilename(), CSLCount(), and VSIStatL().

double CPLDMSToDec ( const char *  is)

CPLDMSToDec

Referenced by OGRSpatialReference::importFromProj4().

void CPLDumpSharedList ( FILE *  fp)

Report open shared files.

Dumps all open shared files to the indicated file handle. If the file handle is NULL information is sent via the CPLDebug() call.

Parameters
fpFile handle to write to.

References CPLDebug().

const char* CPLExpandTilde ( const char *  pszFilename)

Expands ~/ at start of filename.

Assumes that the HOME configuration option is defined.

Parameters
pszFilenamefilename potentially starting with ~/
Returns
an expanded filename.
Since
GDAL 2.2

References CPLFormFilename(), CPLGetConfigOption(), and STARTS_WITH_CI.

const char* CPLExtractRelativePath ( const char *  pszBaseDir,
const char *  pszTarget,
int *  pbGotRelative 
)

Get relative path from directory to target file.

Computes a relative path for pszTarget relative to pszBaseDir. Currently this only works if they share a common base path. The returned path is normally into the pszTarget string. It should only be considered valid as long as pszTarget is valid or till the next call to this function, whichever comes first.

Parameters
pszBaseDirthe name of the directory relative to which the path should be computed. pszBaseDir may be NULL in which case the original target is returned without relativizing.
pszTargetthe filename to be changed to be relative to pszBaseDir.
pbGotRelativePointer to location in which a flag is placed indicating that the returned path is relative to the basename (TRUE) or not (FALSE). This pointer may be NULL if flag is not desired.
Returns
an adjusted path or the original if it could not be made relative to the pszBaseFile's path.

References CPLIsFilenameRelative(), EQUAL, and EQUALN.

char* CPLFGets ( char *  pszBuffer,
int  nBufferSize,
FILE *  fp 
)

Reads in at most one less than nBufferSize characters from the fp stream and stores them into the buffer pointed to by pszBuffer. Reading stops after an EOF or a newline. If a newline is read, it is not stored into the buffer. A '\0' is stored after the last character in the buffer. All three types of newline terminators recognized by the CPLFGets(): single '\r' and '\n' and '\r\n' combination.

Parameters
pszBufferpointer to the targeting character buffer.
nBufferSizemaximum size of the string to read (not including terminating '\0').
fpfile pointer to read from.
Returns
pointer to the pszBuffer containing a string read from the file or NULL if the error or end of file was encountered.

References CPLDebug(), CPLE_FileIO, and CPLError().

Referenced by CPLReadLine().

void CPLFinderClean ( void  )

CPLFinderClean

const char* CPLFindFile ( const char *  pszClass,
const char *  pszBasename 
)

CPLFindFile

Referenced by OGRSpatialReference::importFromDict().

const char* CPLFormCIFilename ( const char *  pszPath,
const char *  pszBasename,
const char *  pszExtension 
)

Case insensitive file searching, returning full path.

This function tries to return the path to a file regardless of whether the file exactly matches the basename, and extension case, or is all upper case, or all lower case. The path is treated as case sensitive. This function is equivalent to CPLFormFilename() on case insensitive file systems (like Windows).

Parameters
pszPathdirectory path to the directory containing the file. This may be relative or absolute, and may have a trailing path separator or not. May be NULL.
pszBasenamefile basename. May optionally have path and/or extension. May not be NULL.
pszExtensionfile extension, optionally including the period. May be NULL.
Returns
a fully formed filename in an internal static string. Do not modify or free the returned string. The string may be destroyed by the next CPL call.

References CPLFormFilename(), CPLFree, VSI_MALLOC_VERBOSE, VSI_STAT_EXISTS_FLAG, VSIIsCaseSensitiveFS(), and VSIStatExL().

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.

The path, and extension are optional. The basename may in fact contain an extension if desired.

CPLFormFilename("abc/xyz", "def", ".dat" ) == "abc/xyz/def.dat"
CPLFormFilename(NULL,"def", NULL ) == "def"
CPLFormFilename(NULL, "abc/def.dat", NULL ) == "abc/def.dat"
CPLFormFilename("/abc/xyz/", "def.dat", NULL ) == "/abc/xyz/def.dat"
Parameters
pszPathdirectory path to the directory containing the file. This may be relative or absolute, and may have a trailing path separator or not. May be NULL.
pszBasenamefile basename. May optionally have path and/or extension. Must NOT be NULL.
pszExtensionfile extension, optionally including the period. May be NULL.
Returns
a fully formed filename in an internal static string. Do not modify or free the returned string. The string may be destroyed by the next CPL call.

References CPLAssert, CPLIsFilenameRelative(), CPLStrlcat(), CPLStrlcpy(), and STARTS_WITH.

Referenced by CPLCopyTree(), CPLCorrespondingPaths(), CPLDefaultFindFile(), CPLExpandTilde(), CPLFormCIFilename(), CPLGenerateTempFilename(), and CPLUnlinkTree().

const char* CPLGenerateTempFilename ( const char *  pszStem)

Generate temporary file name.

Returns a filename that may be used for a temporary file. The location of the file tries to follow operating system semantics but may be forced via the CPL_TMPDIR configuration option.

Parameters
pszStemif non-NULL this will be part of the filename.
Returns
a filename which is valid till the next CPL call in this thread.

References CPLFormFilename(), CPLGetConfigOption(), and CPLString::Printf().

const char* CPLGetBasename ( const char *  pszFullFilename)

Extract basename (non-directory, non-extension) portion of filename.

Returns a string containing the file basename portion of the passed name. If there is no basename (passed value ends in trailing directory separator, or filename starts with a dot) an empty string is returned.

CPLGetBasename( "abc/def.xyz" ) == "def"
CPLGetBasename( "abc/def" ) == "def"
CPLGetBasename( "abc/def/" ) == ""
Parameters
pszFullFilenamethe full filename potentially including a path.
Returns
just the non-directory, non-extension portion of the path in an internal string which must not be freed. The string may be destroyed by the next CPL filename handling call.

References CPLAssert, and CPLStrlcpy().

Referenced by CPLCorrespondingPaths().

const char* CPLGetConfigOption ( const char *  pszKey,
const char *  pszDefault 
)

Get the value of a configuration option.

The value is the value of a (key, value) option set with CPLSetConfigOption(), or CPLSetThreadLocalConfigOption() of the same thread. If the given option was no defined with CPLSetConfigOption(), it tries to find it in environment variables.

Note: the string returned by CPLGetConfigOption() might be short-lived, and in particular it will become invalid after a call to CPLSetConfigOption() with the same key.

To override temporary a potentially existing option with a new value, you can use the following snippet :

    // backup old value
    const char* pszOldValTmp = CPLGetConfigOption(pszKey, NULL);
    char* pszOldVal = pszOldValTmp ? CPLStrdup(pszOldValTmp) : NULL;
    // override with new value
    CPLSetConfigOption(pszKey, pszNewVal);
    // do something useful
    // restore old value
    CPLSetConfigOption(pszKey, pszOldVal);
    CPLFree(pszOldVal);
Parameters
pszKeythe key of the option to retrieve
pszDefaulta default value if the key does not match existing defined options (may be NULL)
Returns
the value associated to the key, or the default value if not found
See Also
CPLSetConfigOption(), http://trac.osgeo.org/gdal/wiki/ConfigOptions

References CSLFetchNameValue().

Referenced by CPLDebug(), CPLDefaultErrorHandler(), CPLErrorV(), CPLExpandTilde(), CPLGenerateTempFilename(), CPLHTTPFetch(), CPLLoggingErrorHandler(), CPLParseXMLString(), OGRGeometryFactory::createFromWkb(), OGRGeometryFactory::createFromWkt(), OGRSpatialReference::exportToProj4(), OGRFeatureDefn::GetGeomType(), GOA2GetAccessToken(), GOA2GetAuthorizationURL(), GOA2GetRefreshToken(), OGRSpatialReference::morphFromESRI(), OGR_G_CreateFromGML(), OGRGeometryFactory::organizePolygons(), OGRFeature::SetField(), OGRSimpleCurve::transform(), and OGRSpatialReference::Validate().

char** CPLGetConfigOptions ( void  )

Return the list of configuration options as KEY=VALUE pairs.

The list is the one set through the CPLSetConfigOption() API.

Options that through environment variables or with CPLSetThreadLocalConfigOption() will not be listed.

Returns
a copy of the list, to be freed with CSLDestroy().
Since
GDAL 2.2

References CSLDuplicate().

char* CPLGetCurrentDir ( void  )

Get the current working directory name.

Returns
a pointer to buffer, containing current working directory path or NULL in case of error. User is responsible to free that buffer after usage with CPLFree() function. If HAVE_GETCWD macro is not defined, the function returns NULL.

References VSI_MALLOC_VERBOSE.

const char* CPLGetDirname ( const char *  pszFilename)

Extract directory path portion of filename.

Returns a string containing the directory path portion of the passed filename. If there is no path in the passed filename the dot will be returned. It is the only difference from CPLGetPath().

CPLGetDirname( "abc/def.xyz" ) == "abc"
CPLGetDirname( "/abc/def/" ) == "/abc/def"
CPLGetDirname( "/" ) == "/"
CPLGetDirname( "/abc/def" ) == "/abc"
CPLGetDirname( "abc" ) == "."
Parameters
pszFilenamethe filename potentially including a path.
Returns
Path in an internal string which must not be freed. The string may be destroyed by the next CPL filename handling call. The returned will generally not contain a trailing path separator.

References CPLAssert, and CPLStrlcpy().

int CPLGetExecPath ( char *  pszPathBuf,
int  nMaxLength 
)

Fetch path of executable.

The path to the executable currently running is returned. This path includes the name of the executable. Currently this only works on win32 and linux platforms. The returned path is UTF-8 encoded.

Parameters
pszPathBufthe buffer into which the path is placed.
nMaxLengththe buffer size, MAX_PATH+1 is suggested.
Returns
FALSE on failure or TRUE on success.
const char* CPLGetExtension ( const char *  pszFullFilename)

Extract filename extension from full filename.

Returns a string containing the extension portion of the passed name. If there is no extension (the filename has no dot) an empty string is returned. The returned extension will not include the period.

CPLGetExtension( "abc/def.xyz" ) == "xyz"
CPLGetExtension( "abc/def" ) == ""
Parameters
pszFullFilenamethe full filename potentially including a path.
Returns
just the extension portion of the path in an internal string which must not be freed. The string may be destroyed by the next CPL filename handling call.

References CPLAssert, and CPLStrlcpy().

Referenced by OGRGeocodeCreateSession().

const char* CPLGetFilename ( const char *  pszFullFilename)

Extract non-directory portion of filename.

Returns a string containing the bare filename portion of the passed filename. If there is no filename (passed value ends in trailing directory separator) an empty string is returned.

CPLGetFilename( "abc/def.xyz" ) == "def.xyz"
CPLGetFilename( "/abc/def/" ) == ""
CPLGetFilename( "abc/def" ) == "def"
Parameters
pszFullFilenamethe full filename potentially including a path.
Returns
just the non-directory portion of the path (points back into original string).

Referenced by CPLCheckForFile(), and CPLCorrespondingPaths().

const char* CPLGetPath ( const char *  pszFilename)

Extract directory path portion of filename.

Returns a string containing the directory path portion of the passed filename. If there is no path in the passed filename an empty string will be returned (not NULL).

CPLGetPath( "abc/def.xyz" ) == "abc"
CPLGetPath( "/abc/def/" ) == "/abc/def"
CPLGetPath( "/" ) == "/"
CPLGetPath( "/abc/def" ) == "/abc"
CPLGetPath( "abc" ) == ""
Parameters
pszFilenamethe filename potentially including a path.
Returns
Path in an internal string which must not be freed. The string may be destroyed by the next CPL filename handling call. The returned will generally not contain a trailing path separator.

References CPLAssert, and CPLStrlcpy().

Referenced by CPLCorrespondingPaths().

CPLSharedFileInfo* CPLGetSharedList ( int *  pnCount)

Fetch list of open shared files.

Parameters
pnCountplace to put the count of entries.
Returns
the pointer to the first in the array of shared file info structures.
void* CPLGetSymbol ( const char *  pszLibrary,
const char *  pszSymbolName 
)

Fetch a function pointer from a shared library / DLL.

This function is meant to abstract access to shared libraries and DLLs and performs functions similar to dlopen()/dlsym() on Unix and LoadLibrary() / GetProcAddress() on Windows.

If no support for loading entry points from a shared library is available this function will always return NULL. Rules on when this function issues a CPLError() or not are not currently well defined, and will have to be resolved in the future.

Currently CPLGetSymbol() doesn't try to:

  • prevent the reference count on the library from going up for every request, or given any opportunity to unload the library.
  • Attempt to look for the library in non-standard locations.
  • Attempt to try variations on the symbol name, like pre-pending or post-pending an underscore.

Some of these issues may be worked on in the future.

Parameters
pszLibrarythe name of the shared library or DLL containing the function. May contain path to file. If not system supplies search paths will be used.
pszSymbolNamethe name of the function to fetch a pointer to.
Returns
A pointer to the function if found, or NULL if the function isn't found, or the shared library can't be loaded.

References CPLE_AppDefined, and CPLError().

const char* CPLGetThreadLocalConfigOption ( const char *  pszKey,
const char *  pszDefault 
)

Same as CPLGetConfigOption() but only with options set with CPLSetThreadLocalConfigOption()

References CSLFetchNameValue().

char** CPLGetThreadLocalConfigOptions ( void  )

Return the list of thread local configuration options as KEY=VALUE pairs.

Options that through environment variables or with CPLSetConfigOption() will not be listed.

Returns
a copy of the list, to be freed with CSLDestroy().
Since
GDAL 2.2

References CSLDuplicate().

int CPLIsFilenameRelative ( const char *  pszFilename)

Is filename relative or absolute?

The test is filesystem convention agnostic. That is it will test for Unix style and windows style path conventions regardless of the actual system in use.

Parameters
pszFilenamethe filename with path to test.
Returns
TRUE if the filename is relative or FALSE if it is absolute.

References STARTS_WITH.

Referenced by CPLExtractRelativePath(), CPLFormFilename(), and CPLProjectRelativeFilename().

void* CPLMalloc ( size_t  nSize)

Safe version of malloc().

This function is like the C library malloc(), but raises a CE_Fatal error with CPLError() if it fails to allocate the desired memory. It should be used for small memory allocations that are unlikely to fail and for which the application is unwilling to test for out of memory conditions. It uses VSIMalloc() to get the memory, so any hooking of VSIMalloc() will apply to CPLMalloc() as well. CPLFree() or VSIFree() can be used free memory allocated by CPLMalloc().

Parameters
nSizesize (in bytes) of memory block to allocate.
Returns
pointer to newly allocated memory, only NULL if nSize is zero.

References CPLE_AppDefined, CPLE_OutOfMemory, CPLEmergencyError(), CPLError(), and VSIMalloc().

Referenced by CPLStringList::AddNameValue(), CPLBinaryToHex(), CPLCalloc(), CPLEscapeString(), CPLForceToASCII(), CPLHashSetNew(), CPLHexToBinary(), CPLHTTPFetch(), CPLListAppend(), CPLListInsert(), CPLLoggingErrorHandler(), CPLParseNameValue(), CPLPrintTime(), CPLPushErrorHandlerEx(), CPLQuadTreeCreate(), CPLScanDouble(), CPLScanString(), CPLStrdup(), CPLUnescapeString(), CSLAddNameValue(), CSLDuplicate(), CSLSetNameValue(), CSLSetNameValueSeparator(), OGRGeometry::exportToGEOS(), OGRSpatialReference::exportToPCI(), OGR_SRSNode::exportToPrettyWkt(), OGRSpatialReference::exportToUSGS(), OGR_SRSNode::exportToWkt(), CPLODBCStatement::Fetch(), OGRSpatialReference::importFromCRSURL(), OGRSpatialReference::importFromPanorama(), OGRSpatialReference::importFromPCI(), CPLODBCDriverInstaller::InstallDriver(), OGRSpatialReference::morphToESRI(), OGR_G_ExportToGMLEx(), OGR_G_ExportToKML(), OGRFeatureDefn::OGRFeatureDefn(), OGRLayer::ReorderField(), OGRFeatureDefn::ReorderFieldDefns(), OGRSpatialReference::SetFromUserInput(), CPLStringList::SetNameValue(), OGRProj4CT::Transform(), CPLString::vPrintf(), and VSISetCryptKey().

int CPLMoveFile ( const char *  pszNewPath,
const char *  pszOldPath 
)

Move a file

References CPLCopyFile(), VSIRename(), and VSIUnlink().

FILE* CPLOpenShared ( const char *  pszFilename,
const char *  pszAccess,
int  bLargeIn 
)

Open a shared file handle.

Some operating systems have limits on the number of file handles that can be open at one time. This function attempts to maintain a registry of already open file handles, and reuse existing ones if the same file is requested by another part of the application.

Note that access is only shared for access types "r", "rb", "r+" and "rb+". All others will just result in direct VSIOpen() calls. Keep in mind that a file is only reused if the file name is exactly the same. Different names referring to the same file will result in different handles.

The VSIFOpen() or VSIFOpenL() function is used to actually open the file, when an existing file handle can't be shared.

Parameters
pszFilenamethe name of the file to open.
pszAccessthe normal fopen()/VSIFOpen() style access string.
bLargeInIf TRUE VSIFOpenL() (for large files) will be used instead of VSIFOpen().
Returns
a file handle or NULL if opening fails.

References CPLSharedFileInfo::bLarge, CPLRealloc(), CPLStrdup(), EQUAL, CPLSharedFileInfo::fp, CPLSharedFileInfo::nRefCount, CPLSharedFileInfo::pszAccess, CPLSharedFileInfo::pszFilename, and VSIFOpenL().

double CPLPackedDMSToDec ( double  dfPacked)

Convert a packed DMS value (DDDMMMSSS.SS) into decimal degrees.

This function converts a packed DMS angle to seconds. The standard packed DMS format is:

degrees * 1000000 + minutes * 1000 + seconds

Example: angle = 120025045.25 yields deg = 120 min = 25 sec = 45.25

The algorithm used for the conversion is as follows:

  1. The absolute value of the angle is used.
  2. The degrees are separated out: deg = angle/1000000 (fractional portion truncated)
  3. The minutes are separated out: min = (angle - deg * 1000000) / 1000 (fractional portion truncated)
  4. The seconds are then computed: sec = angle - deg * 1000000 - min * 1000
  5. The total angle in seconds is computed: sec = deg * 3600.0 + min * 60.0 + sec
  6. The sign of sec is set to that of the input angle.

Packed DMS values used by the USGS GCTP package and probably by other software.

NOTE: This code does not validate input value. If you give the wrong value, you will get the wrong result.

Parameters
dfPackedAngle in packed DMS format.
Returns
Angle in decimal degrees.

Referenced by OGRSpatialReference::importFromUSGS().

CPLFileFinder CPLPopFileFinder ( void  )

CPLPopFileFinder

void CPLPopFinderLocation ( void  )

CPLPopFinderLocation

int CPLPrintDouble ( char *  pszBuffer,
const char *  pszFormat,
double  dfValue,
const char *  pszLocale 
)

Print double value into specified string buffer. Exponential character flag 'E' (or 'e') will be replaced with 'D', as in Fortran. Resulting string will not to be NULL-terminated.

Parameters
pszBufferPointer to the destination string buffer. Should be large enough to hold the resulting string. Note, that the string will not be NULL-terminated, so user should do this himself, if needed.
pszFormatFormat specifier (for example, "%16.9E").
dfValueNumerical value to print.
pszLocaleUnused.
Returns
Number of characters printed.

References CPLPrintString(), and CPLsnprintf().

int CPLPrintInt32 ( char *  pszBuffer,
GInt32  iValue,
int  nMaxLen 
)

Print GInt32 value into specified string buffer. This string will not be NULL-terminated.

Parameters
pszBufferPointer to the destination string buffer. Should be large enough to hold the resulting string. Note, that the string will not be NULL-terminated, so user should do this himself, if needed.
iValueNumerical value to print.
nMaxLenMaximum length of the resulting string. If string length is greater than nMaxLen, it will be truncated.
Returns
Number of characters printed.

References CPLPrintString().

Referenced by OGRSpatialReference::exportToPCI().

int CPLPrintPointer ( char *  pszBuffer,
void *  pValue,
int  nMaxLen 
)

Print pointer value into specified string buffer. This string will not be NULL-terminated.

Parameters
pszBufferPointer to the destination string buffer. Should be large enough to hold the resulting string. Note, that the string will not be NULL-terminated, so user should do this himself, if needed.
pValuePointer to ASCII encode.
nMaxLenMaximum length of the resulting string. If string length is greater than nMaxLen, it will be truncated.
Returns
Number of characters printed.

References CPLPrintString(), and STARTS_WITH_CI.

int CPLPrintString ( char *  pszDest,
const char *  pszSrc,
int  nMaxLen 
)

Copy the string pointed to by pszSrc, NOT including the terminating `\0' character, to the array pointed to by pszDest.

Parameters
pszDestPointer to the destination string buffer. Should be large enough to hold the resulting string.
pszSrcPointer to the source buffer.
nMaxLenMaximum length of the resulting string. If string length is greater than nMaxLen, it will be truncated.
Returns
Number of characters printed.

Referenced by CPLPrintDouble(), CPLPrintInt32(), CPLPrintPointer(), CPLPrintTime(), and CPLPrintUIntBig().

int CPLPrintStringFill ( char *  pszDest,
const char *  pszSrc,
int  nMaxLen 
)

Copy the string pointed to by pszSrc, NOT including the terminating `\0' character, to the array pointed to by pszDest. Remainder of the destination string will be filled with space characters. This is only difference from the PrintString().

Parameters
pszDestPointer to the destination string buffer. Should be large enough to hold the resulting string.
pszSrcPointer to the source buffer.
nMaxLenMaximum length of the resulting string. If string length is greater than nMaxLen, it will be truncated.
Returns
Number of characters printed.

Referenced by OGRSpatialReference::exportToPCI().

int CPLPrintTime ( char *  pszBuffer,
int  nMaxLen,
const char *  pszFormat,
const struct tm *  poBrokenTime,
const char *  pszLocale 
)

Print specified time value accordingly to the format options and specified locale name. This function does following:

  • if locale parameter is not NULL, the current locale setting will be stored and replaced with the specified one;
  • format time value with the strftime(3) function;
  • restore back current locale, if was saved.
Parameters
pszBufferPointer to the destination string buffer. Should be large enough to hold the resulting string. Note, that the string will not be NULL-terminated, so user should do this himself, if needed.
nMaxLenMaximum length of the resulting string. If string length is greater than nMaxLen, it will be truncated.
pszFormatControls the output format. Options are the same as for strftime(3) function.
poBrokenTimePointer to the broken-down time structure. May be requested with the VSIGMTime() and VSILocalTime() functions.
pszLocalePointer to a character string containing locale name ("C", "POSIX", "us_US", "ru_RU.KOI8-R" etc.). If NULL we will not manipulate with locale settings and current process locale will be used for printing. Be aware that it may be unsuitable to use current locale for printing time, because all names will be printed in your native language, as well as time format settings also may be adjusted differently from the C/POSIX defaults. To solve these problems this option was introduced.
Returns
Number of characters printed.

References CPLFree, CPLMalloc(), CPLPrintString(), CPLsetlocale(), and EQUAL.

int CPLPrintUIntBig ( char *  pszBuffer,
GUIntBig  iValue,
int  nMaxLen 
)

Print GUIntBig value into specified string buffer. This string will not be NULL-terminated.

Parameters
pszBufferPointer to the destination string buffer. Should be large enough to hold the resulting string. Note, that the string will not be NULL-terminated, so user should do this himself, if needed.
iValueNumerical value to print.
nMaxLenMaximum length of the resulting string. If string length is greater than nMaxLen, it will be truncated.
Returns
Number of characters printed.

References CPLPrintString().

const char* CPLProjectRelativeFilename ( const char *  pszProjectDir,
const char *  pszSecondaryFilename 
)

Find a file relative to a project file.

Given the path to a "project" directory, and a path to a secondary file referenced from that project, build a path to the secondary file that the current application can use. If the secondary path is already absolute, rather than relative, then it will be returned unaltered.

Examples:

CPLProjectRelativeFilename("abc/def", "tmp/abc.gif") == "abc/def/tmp/abc.gif"
CPLProjectRelativeFilename("abc/def", "/tmp/abc.gif") == "/tmp/abc.gif"
CPLProjectRelativeFilename("/xy", "abc.gif") == "/xy/abc.gif"
CPLProjectRelativeFilename("/abc/def", "../abc.gif") == "/abc/def/../abc.gif"
CPLProjectRelativeFilename("C:\WIN", "abc.gif") == "C:\WIN\abc.gif"
Parameters
pszProjectDirthe directory relative to which the secondary files path should be interpreted.
pszSecondaryFilenamethe filename (potentially with path) that is to be interpreted relative to the project directory.
Returns
a composed path to the secondary file. The returned string is internal and should not be altered, freed, or depending on past the next CPL call.

References CPLAssert, CPLIsFilenameRelative(), CPLStrlcat(), CPLStrlcpy(), and STARTS_WITH.

void CPLPushFileFinder ( CPLFileFinder  pfnFinder)

CPLPushFileFinder

References CPLRealloc().

void CPLPushFinderLocation ( const char *  pszLocation)

CPLPushFinderLocation

References CSLAddStringMayFail(), and CSLFindStringCaseSensitive().

const char* CPLReadLine ( FILE *  fp)

Simplified line reading from text file.

Read a line of text from the given file handle, taking care to capture CR and/or LF and strip off ... equivalent of DKReadLine(). Pointer to an internal buffer is returned. The application shouldn't free it, or depend on its value past the next call to CPLReadLine().

Note that CPLReadLine() uses VSIFGets(), so any hooking of VSI file services should apply to CPLReadLine() as well.

CPLReadLine() maintains an internal buffer, which will appear as a single block memory leak in some circumstances. CPLReadLine() may be called with a NULL FILE * at any time to free this working buffer.

Parameters
fpfile pointer opened with VSIFOpen().
Returns
pointer to an internal buffer containing a line of text read from the file or NULL if the end of file was encountered.

References CPLFGets().

const char* CPLReadLine2L ( VSILFILE fp,
int  nMaxCars,
const char *const *  papszOptions 
)

Simplified line reading from text file.

Similar to CPLReadLine(), but reading from a large file API handle.

Parameters
fpfile pointer opened with VSIFOpenL().
nMaxCarsmaximum number of characters allowed, or -1 for no limit.
papszOptionsNULL-terminated array of options. Unused for now.
Returns
pointer to an internal buffer containing a line of text read from the file or NULL if the end of file was encountered or the maximum number of characters allowed reached.
Since
GDAL 1.7.0

References CPLE_AppDefined, CPLError(), VSIFReadL(), VSIFSeekL(), and VSIFTellL().

Referenced by CPLReadLineL(), and CSLLoad2().

const char* CPLReadLineL ( VSILFILE fp)

Simplified line reading from text file.

Similar to CPLReadLine(), but reading from a large file API handle.

Parameters
fpfile pointer opened with VSIFOpenL().
Returns
pointer to an internal buffer containing a line of text read from the file or NULL if the end of file was encountered.

References CPLReadLine2L().

Referenced by CSLLoad2(), and OGRSpatialReference::importFromDict().

void* CPLRealloc ( void *  pData,
size_t  nNewSize 
)

Safe version of realloc().

This function is like the C library realloc(), but raises a CE_Fatal error with CPLError() if it fails to allocate the desired memory. It should be used for small memory allocations that are unlikely to fail and for which the application is unwilling to test for out of memory conditions. It uses VSIRealloc() to get the memory, so any hooking of VSIRealloc() will apply to CPLRealloc() as well. CPLFree() or VSIFree() can be used free memory allocated by CPLRealloc().

It is also safe to pass NULL in as the existing memory block for CPLRealloc(), in which case it uses VSIMalloc() to allocate a new block.

Parameters
pDataexisting memory block which should be copied to the new block.
nNewSizenew size (in bytes) of memory block to allocate.
Returns
pointer to allocated memory, only NULL if nNewSize is zero.

References CPLE_AppDefined, CPLE_OutOfMemory, CPLEmergencyError(), CPLError(), VSIFree(), VSIMalloc(), and VSIRealloc().

Referenced by OGRFeatureDefn::AddFieldDefn(), OGRFeatureDefn::AddGeomFieldDefn(), CPLODBCStatement::Append(), CPLErrorV(), CPLEscapeString(), CPLHashSetClear(), CPLHTTPParseMultipartMime(), CPLOpenShared(), CPLParseXMLString(), CPLPushFileFinder(), CSLInsertStrings(), CSLTokenizeString2(), OGRMultiPoint::exportToWkt(), CPLODBCStatement::Fetch(), OGRSpatialReference::importFromESRI(), OGR_SRSNode::InsertChild(), OGRSimpleCurve::segmentize(), OGRCircularString::segmentize(), OGRProj4CT::TransformEx(), and CPLString::vPrintf().

const char* CPLResetExtension ( const char *  pszPath,
const char *  pszExt 
)

Replace the extension with the provided one.

Parameters
pszPaththe input path, this string is not altered.
pszExtthe new extension to apply to the given path.
Returns
an altered filename with the new extension. Do not modify or free the returned string. The string may be destroyed by the next CPL call.

References CPLAssert, CPLStrlcat(), and CPLStrlcpy().

double CPLScanDouble ( const char *  pszString,
int  nMaxLength 
)

Extract double from string.

Scan up to a maximum number of characters from a string and convert the result to a double. This function uses CPLAtof() to convert string to double value, so it uses a comma as a decimal delimiter.

Parameters
pszStringString containing characters to be scanned. It may be terminated with a null character.
nMaxLengthThe maximum number of character to consider as part of the number. Less characters will be considered if a null character is encountered.
Returns
Double value, converted from its ASCII form.

References CPLAtof(), CPLFree, and CPLMalloc().

long CPLScanLong ( const char *  pszString,
int  nMaxLength 
)

Scan up to a maximum number of characters from a string and convert the result to a long.

Parameters
pszStringString containing characters to be scanned. It may be terminated with a null character.
nMaxLengthThe maximum number of character to consider as part of the number. Less characters will be considered if a null character is encountered.
Returns
Long value, converted from its ASCII form.

References CPLAssert, and CPLStrnlen().

Referenced by OGRSpatialReference::importFromPCI().

void* CPLScanPointer ( const char *  pszString,
int  nMaxLength 
)

Extract pointer from string.

Scan up to a maximum number of characters from a string and convert the result to a pointer.

Parameters
pszStringString containing characters to be scanned. It may be terminated with a null character.
nMaxLengthThe maximum number of character to consider as part of the number. Less characters will be considered if a null character is encountered.
Returns
pointer value, converted from its ASCII form.

References CPLScanUIntBig(), CPLScanULong(), and STARTS_WITH_CI.

char* CPLScanString ( const char *  pszString,
int  nMaxLength,
int  bTrimSpaces,
int  bNormalize 
)

Scan up to a maximum number of characters from a given string, allocate a buffer for a new string and fill it with scanned characters.

Parameters
pszStringString containing characters to be scanned. It may be terminated with a null character.
nMaxLengthThe maximum number of character to read. Less characters will be read if a null character is encountered.
bTrimSpacesIf TRUE, trim ending spaces from the input string. Character considered as empty using isspace(3) function.
bNormalizeIf TRUE, replace ':' symbol with the '_'. It is needed if resulting string will be used in CPL dictionaries.
Returns
Pointer to the resulting string buffer. Caller responsible to free this buffer with CPLFree().

References CPLMalloc(), and CPLStrdup().

GUIntBig CPLScanUIntBig ( const char *  pszString,
int  nMaxLength 
)

Extract big integer from string.

Scan up to a maximum number of characters from a string and convert the result to a GUIntBig.

Parameters
pszStringString containing characters to be scanned. It may be terminated with a null character.
nMaxLengthThe maximum number of character to consider as part of the number. Less characters will be considered if a null character is encountered.
Returns
GUIntBig value, converted from its ASCII form.

References CPLAssert, and CPLStrnlen().

Referenced by CPLScanPointer().

unsigned long CPLScanULong ( const char *  pszString,
int  nMaxLength 
)

Scan up to a maximum number of characters from a string and convert the result to a unsigned long.

Parameters
pszStringString containing characters to be scanned. It may be terminated with a null character.
nMaxLengthThe maximum number of character to consider as part of the number. Less characters will be considered if a null character is encountered.
Returns
Unsigned long value, converted from its ASCII form.

References CPLAssert, and CPLStrnlen().

Referenced by CPLScanPointer().

void CPLSetConfigOption ( const char *  pszKey,
const char *  pszValue 
)

Set a configuration option for GDAL/OGR use.

Those options are defined as a (key, value) couple. The value corresponding to a key can be got later with the CPLGetConfigOption() method.

This mechanism is similar to environment variables, but options set with CPLSetConfigOption() overrides, for CPLGetConfigOption() point of view, values defined in the environment.

If CPLSetConfigOption() is called several times with the same key, the value provided during the last call will be used.

Options can also be passed on the command line of most GDAL utilities with the with '–config KEY VALUE'. For example, ogrinfo –config CPL_DEBUG ON ~/data/test/point.shp

This function can also be used to clear a setting by passing NULL as the value (note: passing NULL will not unset an existing environment variable; it will just unset a value previously set by CPLSetConfigOption()).

Parameters
pszKeythe key of the option
pszValuethe value of the option, or NULL to clear a setting.
See Also
http://trac.osgeo.org/gdal/wiki/ConfigOptions

References CSLSetNameValue().

Referenced by CPLHTTPFetch(), and CPLLoggingErrorHandler().

void CPLSetConfigOptions ( const char *const *  papszConfigOptions)

Replace the full list of configuration options with the passed list of KEY=VALUE pairs.

This has the same effect of clearing the existing list, and setting individually each pair with the CPLSetConfigOption() API.

This does not affect options set through environment variables or with CPLSetThreadLocalConfigOption().

The passed list is copied by the function.

Parameters
papszConfigOptionsthe new list (or NULL).
Since
GDAL 2.2

References CSLDestroy(), and CSLDuplicate().

char* CPLsetlocale ( int  category,
const char *  locale 
)

Prevents parallel executions of setlocale().

Calling setlocale() concurrently from two or more threads is a potential data race. A mutex is used to provide a critical region so that only one thread at a time can be executing setlocale().

The return should not be freed, and copied quickly as it may be invalidated by a following next call to CPLsetlocale().

Parameters
categorySee your compiler's documentation on setlocale.
localeSee your compiler's documentation on setlocale.
Returns
See your compiler's documentation on setlocale.

References CPLSPrintf().

Referenced by CPLPrintTime().

void CPLSetThreadLocalConfigOption ( const char *  pszKey,
const char *  pszValue 
)

Set a configuration option for GDAL/OGR use.

Those options are defined as a (key, value) couple. The value corresponding to a key can be got later with the CPLGetConfigOption() method.

This function sets the configuration option that only applies in the current thread, as opposed to CPLSetConfigOption() which sets an option that applies on all threads. CPLSetThreadLocalConfigOption() will override the effect of CPLSetConfigOption) for the current thread.

This function can also be used to clear a setting by passing NULL as the value (note: passing NULL will not unset an existing environment variable or a value set through CPLSetConfigOption(); it will just unset a value previously set by CPLSetThreadLocalConfigOption()).

Parameters
pszKeythe key of the option
pszValuethe value of the option, or NULL to clear a setting.

References CSLSetNameValue().

void CPLSetThreadLocalConfigOptions ( const char *const *  papszConfigOptions)

Replace the full list of thread local configuration options with the passed list of KEY=VALUE pairs.

This has the same effect of clearing the existing list, and setting individually each pair with the CPLSetThreadLocalConfigOption() API.

This does not affect options set through environment variables or with CPLSetConfigOption().

The passed list is copied by the function.

Parameters
papszConfigOptionsthe new list (or NULL).
Since
GDAL 2.2

References CSLDestroy(), and CSLDuplicate().

int CPLStat ( const char *  pszPath,
VSIStatBuf *  psStatBuf 
)

Same as VSIStat() except it works on "C:" as if it were "C:\".

char* CPLStrdup ( const char *  pszString)

Safe version of strdup() function.

This function is similar to the C library strdup() function, but if the memory allocation fails it will issue a CE_Fatal error with CPLError() instead of returning NULL. It uses VSIStrdup(), so any hooking of that function will apply to CPLStrdup() as well. Memory allocated with CPLStrdup() can be freed with CPLFree() or VSIFree().

It is also safe to pass a NULL string into CPLStrdup(). CPLStrdup() will allocate and return a zero length string (as opposed to a NULL string).

Parameters
pszStringinput string to be duplicated. May be NULL.
Returns
pointer to a newly allocated copy of the string. Free with CPLFree() or VSIFree().

References CPLE_OutOfMemory, CPLError(), and CPLMalloc().

Referenced by OGRStyleMgr::AddPart(), CPLStringList::AddString(), CPLODBCStatement::CollectResultsInfo(), CPLBase64Encode(), CPLCreateXMLNode(), CPLHTTPFetch(), CPLLoggingErrorHandler(), CPLOpenShared(), CPLRecode(), CPLScanString(), CPLSetXMLValue(), CPLVASPrintf(), CSLDuplicate(), CSLInsertStrings(), CSLLoad2(), OGRSpatialReference::exportToPCI(), OGRSpatialReference::exportToPrettyWkt(), OGRSpatialReference::exportToProj4(), OGRSpatialReference::exportToWkt(), OGRPoint::exportToWkt(), OGRSimpleCurve::exportToWkt(), OGRPolygon::exportToWkt(), OGRMultiPoint::exportToWkt(), CPLODBCStatement::GetColumns(), OGRLayer::GetFeature(), OGRFeature::GetFieldAsSerializedJSon(), OGRStyleTool::GetStyleString(), GOA2GetAccessToken(), GOA2GetAuthorizationURL(), GOA2GetRefreshToken(), OGRSpatialReference::importFromCRSURL(), OGRSpatialReference::importFromESRI(), OGRSpatialReference::importFromProj4(), OGRSpatialReference::importFromURN(), OGRStyleMgr::InitStyleString(), CPLStringList::InsertString(), OGRSpatialReference::morphFromESRI(), OGRSpatialReference::morphToESRI(), OGR_G_ExportToGMLEx(), OGR_G_ExportToJsonEx(), OGR_G_ExportToKML(), OGRFeatureDefn::OGRFeatureDefn(), OGRGeocodeCreateSession(), OGRLayer::SetAttributeFilter(), OGRFieldDefn::SetDefault(), OGRSpatialReference::SetFromUserInput(), OGRSpatialReference::SetLinearUnitsAndUpdateParameters(), OGRFieldDefn::SetName(), OGRGeomFieldDefn::SetName(), OGRStyleTool::SetParamDbl(), OGRStyleTool::SetParamNum(), OGRStyleTool::SetParamStr(), OGRStyleTool::SetStyleString(), OGR_SRSNode::SetValue(), and VSIReadDirRecursive().

void CPLStringToComplex ( const char *  pszString,
double *  pdfReal,
double *  pdfImag 
)

Fetch the real and imaginary part of a serialized complex number

References CPLAtof().

char* CPLStrlwr ( char *  pszString)

Convert each characters of the string to lower case.

For example, "ABcdE" will be converted to "abcde". This function is locale dependent.

Parameters
pszStringinput string to be converted.
Returns
pointer to the same string, pszString.
double CPLStrtod ( const char *  nptr,
char **  endptr 
)

Converts ASCII string to floating point number.

This function converts the initial portion of the string pointed to by nptr to double floating point representation. This function does the same as standard strtod(3), but does not take locale in account. That means, the decimal delimiter is always '.' (decimal point). Use CPLStrtodDelim() function if you want to specify custom delimiter. Also see notes for CPLAtof() function.

Parameters
nptrPointer to string to convert.
endptrIf is not NULL, a pointer to the character after the last character used in the conversion is stored in the location referenced by endptr.
Returns
Converted value, if any.

References CPLStrtodDelim().

Referenced by CPLAtof(), OGRFieldDefn::IsDefaultDriverSpecific(), and OGRFeature::SetField().

double CPLStrtodDelim ( const char *  nptr,
char **  endptr,
char  point 
)

Converts ASCII string to floating point number using specified delimiter.

This function converts the initial portion of the string pointed to by nptr to double floating point representation. This function does the same as standard strtod(3), but does not take locale in account. Instead of locale defined decimal delimiter you can specify your own one. Also see notes for CPLAtof() function.

Parameters
nptrPointer to string to convert.
endptrIf is not NULL, a pointer to the character after the last character used in the conversion is stored in the location referenced by endptr.
pointDecimal delimiter.
Returns
Converted value, if any.

References CPLFree, STARTS_WITH, and STARTS_WITH_CI.

Referenced by CPLAtofDelim(), CPLAtofM(), CPLStrtod(), and CPLStrtofDelim().

float CPLStrtof ( const char *  nptr,
char **  endptr 
)

Converts ASCII string to floating point number.

This function converts the initial portion of the string pointed to by nptr to single floating point representation. This function does the same as standard strtof(3), but does not take locale in account. That means, the decimal delimiter is always '.' (decimal point). Use CPLStrtofDelim() function if you want to specify custom delimiter. Also see notes for CPLAtof() function.

Parameters
nptrPointer to string to convert.
endptrIf is not NULL, a pointer to the character after the last character used in the conversion is stored in the location referenced by endptr.
Returns
Converted value, if any.

References CPLStrtofDelim().

float CPLStrtofDelim ( const char *  nptr,
char **  endptr,
char  point 
)

Converts ASCII string to floating point number using specified delimiter.

This function converts the initial portion of the string pointed to by nptr to single floating point representation. This function does the same as standard strtof(3), but does not take locale in account. Instead of locale defined decimal delimiter you can specify your own one. Also see notes for CPLAtof() function.

Parameters
nptrPointer to string to convert.
endptrIf is not NULL, a pointer to the character after the last character used in the conversion is stored in the location referenced by endptr.
pointDecimal delimiter.
Returns
Converted value, if any.

References CPLFree, and CPLStrtodDelim().

Referenced by CPLStrtof().

int CPLSymlink ( const char *  pszOldPath,
const char *  pszNewPath,
char **   
)

Create a symbolic link

int CPLUnlinkTree ( const char *  pszPath)

Recursively unlink a directory.

Returns
0 on successful completion, -1 if function fails.

References CPLE_AppDefined, CPLError(), CPLFormFilename(), CSLDestroy(), EQUAL, VSI_ISDIR, VSI_ISREG, VSIReadDir(), VSIRmdir(), VSIStatL(), and VSIUnlink().

CPLErr CPLWriteFileInZip ( void *  hZip,
const void *  pBuffer,
int  nBufferSize 
)

Write in current file inside a ZIP file

void* CPLZLibInflate ( const void *  ptr,
size_t  nBytes,
void *  outptr,
size_t  nOutAvailableBytes,
size_t *  pnOutBytes 
)

Uncompress a buffer compressed with ZLib DEFLATE compression.

Parameters
ptrinput buffer.
nBytessize of input buffer in bytes.
outptroutput buffer, or NULL to let the function allocate it.
nOutAvailableBytessize of output buffer if provided, or ignored.
pnOutBytespointer to a size_t, where to store the size of the output buffer.
Returns
the output buffer (to be freed with VSIFree() if not provided) or NULL in case of error.
Since
GDAL 1.10.0

Generated for GDAL by doxygen 1.8.5.