Skip to content

Commit

Permalink
Use GDAL large file API (UTF-8) compatible in a number of places
Browse files Browse the repository at this point in the history
There are still uses of ANSI FILE* API, but this should hopefully
fix #5995
  • Loading branch information
rouault authored and jmckenna committed Apr 13, 2020
1 parent 01df894 commit 82750e4
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 130 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ mapraster.c mapuvraster.c mapdummyrenderer.c mapobject.c maprasterquery.c
mapwcs.c maperror.c mapogcfilter.c mapregex.c mapwcs11.c mapfile.c
mapogcfiltercommon.cpp maprendering.c mapwcs20.c mapogcsld.c mapmetadata.c
mapresample.c mapwfs.c mapgdal.c mapogcsos.c mapscale.c mapwfs11.c mapwfs20.c
mapgeomtransform.c mapogroutput.c mapwfslayer.c mapagg.cpp mapkml.cpp
mapgeomtransform.c mapogroutput.cpp mapwfslayer.c mapagg.cpp mapkml.cpp
mapgeomutil.cpp mapkmlrenderer.cpp fontcache.c textlayout.c maputfgrid.cpp
mapogr.cpp mapcontour.c mapsmoothing.c mapv8.cpp ${REGEX_SOURCES} kerneldensity.c
mapcompositingfilter.c mapmvt.c)
Expand Down
22 changes: 12 additions & 10 deletions mapcontext.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "mapserver.h"
#include "mapows.h"

#include "cpl_vsi.h"


#if defined(USE_WMS_LYR)

Expand All @@ -47,12 +49,12 @@
char * msGetMapContextFileText(char *filename)
{
char *pszBuffer;
FILE *stream;
VSILFILE *stream;
int nLength;

/* open file */
if(filename != NULL && strlen(filename) > 0) {
stream = fopen(filename, "rb");
stream = VSIFOpenL(filename, "rb");
if(!stream) {
msSetError(MS_IOERR, "(%s)", "msGetMapContextFileText()", filename);
return NULL;
Expand All @@ -62,26 +64,26 @@ char * msGetMapContextFileText(char *filename)
return NULL;
}

fseek( stream, 0, SEEK_END );
nLength = ftell( stream );
fseek( stream, 0, SEEK_SET );
VSIFSeekL( stream, 0, SEEK_END );
nLength = (int) VSIFTellL( stream );
VSIFSeekL( stream, 0, SEEK_SET );

pszBuffer = (char *) malloc(nLength+1);
if( pszBuffer == NULL ) {
msSetError(MS_MEMERR, "(%s)", "msGetMapContextFileText()", filename);
fclose( stream );
VSIFCloseL( stream );
return NULL;
}

if(fread( pszBuffer, nLength, 1, stream ) == 0 && !feof(stream)) {
if(VSIFReadL( pszBuffer, nLength, 1, stream ) == 0) {
free( pszBuffer );
fclose( stream );
VSIFCloseL( stream );
msSetError(MS_IOERR, "(%s)", "msGetMapContextFileText()", filename);
return NULL;
}
pszBuffer[nLength] = '\0';

fclose( stream );
VSIFCloseL( stream );

return pszBuffer;
}
Expand Down Expand Up @@ -1275,7 +1277,7 @@ int msLoadMapContext(mapObj *map, char *filename, int unique_layer_names)
int msSaveMapContext(mapObj *map, char *filename)
{
#if defined(USE_WMS_LYR)
FILE *stream;
VSILFILE *stream;
char szPath[MS_MAXPATHLEN];
int nStatus;

Expand Down
17 changes: 9 additions & 8 deletions maplabel.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
#include "mapserver.h"
#include "fontcache.h"


#include "cpl_vsi.h"
#include "cpl_string.h"



Expand Down Expand Up @@ -774,8 +775,8 @@ int msFreeFontSet(fontSetObj *fontset)

int msLoadFontSet(fontSetObj *fontset, mapObj *map)
{
FILE *stream;
char buffer[MS_BUFFER_LENGTH];
VSILFILE *stream;
const char* line;
char alias[64], file1[MS_PATH_LENGTH], file2[MS_PATH_LENGTH];
char *path;
char szPath[MS_MAXPATHLEN];
Expand All @@ -798,20 +799,20 @@ int msLoadFontSet(fontSetObj *fontset, mapObj *map)
/* return(-1); */
/* } */

stream = fopen( msBuildPath(szPath, fontset->map->mappath, fontset->filename), "r");
stream = VSIFOpenL( msBuildPath(szPath, fontset->map->mappath, fontset->filename), "rb");
if(!stream) {
msSetError(MS_IOERR, "Error opening fontset %s.", "msLoadFontset()",
fontset->filename);
return(-1);
}

i = 0;
while(fgets(buffer, MS_BUFFER_LENGTH, stream)) { /* while there's something to load */
while( (line = CPLReadLineL(stream)) != NULL ) { /* while there's something to load */

if(buffer[0] == '#' || buffer[0] == '\n' || buffer[0] == '\r' || buffer[0] == ' ')
if(line[0] == '#' || line[0] == '\n' || line[0] == '\r' || line[0] == ' ')
continue; /* skip comments and blank lines */

sscanf(buffer,"%s %s", alias, file1);
sscanf(line,"%s %s", alias, file1);

if (!(*file1) || !(*alias) || (strlen(file1) <= 0))
continue;
Expand Down Expand Up @@ -845,7 +846,7 @@ int msLoadFontSet(fontSetObj *fontset, mapObj *map)
}

fontset->numfonts = i;
fclose(stream); /* close the file */
VSIFCloseL(stream); /* close the file */
free(path);

return(0);
Expand Down
27 changes: 13 additions & 14 deletions mapogroutput.c → mapogroutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@
#include "mapthread.h"
#include "mapows.h"

#define __USE_LARGEFILE64 1
#include "ogr_api.h"
#include "ogr_srs_api.h"
#include "cpl_conv.h"
#include "cpl_vsi.h"
#include "cpl_string.h"

#include <string>

/************************************************************************/
/* msInitDefaultOGROutputFormat() */
/************************************************************************/
Expand Down Expand Up @@ -717,21 +718,19 @@ int msOGRWriteFromQuery( mapObj *map, outputFormatObj *format, int sendheaders )
CSLFetchNameValueDef(layer_options, "NATIVE_DATA", "{}");
if( pszNativeData[strlen(pszNativeData)-1] == '}' )
{
char szTemp[32];
char* pszTemplate = msSmallMalloc(strlen(pszNativeData) + 32);
strcpy(pszTemplate, pszNativeData);
pszTemplate[strlen(pszTemplate)-1] = 0;
std::string tmpl(pszNativeData);
tmpl.resize(tmpl.size() - 1);
if( strlen(pszNativeData) > 2 )
strcat(pszTemplate, ",");
sprintf(szTemp, "\"numberMatched\":%d}", nMatchingFeatures);
strcat(pszTemplate, szTemp);
tmpl += ',';
tmpl += "\"numberMatched\":";
tmpl += std::to_string(nMatchingFeatures);
tmpl += '}';
layer_options = CSLSetNameValue(layer_options,
"NATIVE_MEDIA_TYPE",
"application/vnd.geo+json");
layer_options = CSLSetNameValue(layer_options,
"NATIVE_DATA",
pszTemplate);
msFree(pszTemplate);
tmpl.c_str());
}
}
if(!strcasecmp("true",msGetOutputFormatOption(format,"USE_FEATUREID","false"))) {
Expand Down Expand Up @@ -1129,11 +1128,11 @@ int msOGRWriteFromQuery( mapObj *map, outputFormatObj *format, int sendheaders )
msShapeGetClass(layer, map, &resultshape, NULL, -1);

if( resultshape.classindex >= 0
&& (layer->class[resultshape.classindex]->text.string
&& (layer->_class[resultshape.classindex]->text.string
|| layer->labelitem)
&& layer->class[resultshape.classindex]->numlabels > 0
&& layer->class[resultshape.classindex]->labels[0]->size != -1 ) {
resultshape.text = msShapeGetLabelAnnotation(layer,&resultshape,layer->class[resultshape.classindex]->labels[0]);
&& layer->_class[resultshape.classindex]->numlabels > 0
&& layer->_class[resultshape.classindex]->labels[0]->size != -1 ) {
resultshape.text = msShapeGetLabelAnnotation(layer,&resultshape,layer->_class[resultshape.classindex]->labels[0]);
}

/*
Expand Down
Loading

0 comments on commit 82750e4

Please sign in to comment.