Skip to content

Commit 82750e4

Browse files
rouaultjmckenna
authored andcommitted
Use GDAL large file API (UTF-8) compatible in a number of places
There are still uses of ANSI FILE* API, but this should hopefully fix #5995
1 parent 01df894 commit 82750e4

8 files changed

Lines changed: 127 additions & 130 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ mapraster.c mapuvraster.c mapdummyrenderer.c mapobject.c maprasterquery.c
282282
mapwcs.c maperror.c mapogcfilter.c mapregex.c mapwcs11.c mapfile.c
283283
mapogcfiltercommon.cpp maprendering.c mapwcs20.c mapogcsld.c mapmetadata.c
284284
mapresample.c mapwfs.c mapgdal.c mapogcsos.c mapscale.c mapwfs11.c mapwfs20.c
285-
mapgeomtransform.c mapogroutput.c mapwfslayer.c mapagg.cpp mapkml.cpp
285+
mapgeomtransform.c mapogroutput.cpp mapwfslayer.c mapagg.cpp mapkml.cpp
286286
mapgeomutil.cpp mapkmlrenderer.cpp fontcache.c textlayout.c maputfgrid.cpp
287287
mapogr.cpp mapcontour.c mapsmoothing.c mapv8.cpp ${REGEX_SOURCES} kerneldensity.c
288288
mapcompositingfilter.c mapmvt.c)

mapcontext.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include "mapserver.h"
3030
#include "mapows.h"
3131

32+
#include "cpl_vsi.h"
33+
3234

3335
#if defined(USE_WMS_LYR)
3436

@@ -47,12 +49,12 @@
4749
char * msGetMapContextFileText(char *filename)
4850
{
4951
char *pszBuffer;
50-
FILE *stream;
52+
VSILFILE *stream;
5153
int nLength;
5254

5355
/* open file */
5456
if(filename != NULL && strlen(filename) > 0) {
55-
stream = fopen(filename, "rb");
57+
stream = VSIFOpenL(filename, "rb");
5658
if(!stream) {
5759
msSetError(MS_IOERR, "(%s)", "msGetMapContextFileText()", filename);
5860
return NULL;
@@ -62,26 +64,26 @@ char * msGetMapContextFileText(char *filename)
6264
return NULL;
6365
}
6466

65-
fseek( stream, 0, SEEK_END );
66-
nLength = ftell( stream );
67-
fseek( stream, 0, SEEK_SET );
67+
VSIFSeekL( stream, 0, SEEK_END );
68+
nLength = (int) VSIFTellL( stream );
69+
VSIFSeekL( stream, 0, SEEK_SET );
6870

6971
pszBuffer = (char *) malloc(nLength+1);
7072
if( pszBuffer == NULL ) {
7173
msSetError(MS_MEMERR, "(%s)", "msGetMapContextFileText()", filename);
72-
fclose( stream );
74+
VSIFCloseL( stream );
7375
return NULL;
7476
}
7577

76-
if(fread( pszBuffer, nLength, 1, stream ) == 0 && !feof(stream)) {
78+
if(VSIFReadL( pszBuffer, nLength, 1, stream ) == 0) {
7779
free( pszBuffer );
78-
fclose( stream );
80+
VSIFCloseL( stream );
7981
msSetError(MS_IOERR, "(%s)", "msGetMapContextFileText()", filename);
8082
return NULL;
8183
}
8284
pszBuffer[nLength] = '\0';
8385

84-
fclose( stream );
86+
VSIFCloseL( stream );
8587

8688
return pszBuffer;
8789
}
@@ -1275,7 +1277,7 @@ int msLoadMapContext(mapObj *map, char *filename, int unique_layer_names)
12751277
int msSaveMapContext(mapObj *map, char *filename)
12761278
{
12771279
#if defined(USE_WMS_LYR)
1278-
FILE *stream;
1280+
VSILFILE *stream;
12791281
char szPath[MS_MAXPATHLEN];
12801282
int nStatus;
12811283

maplabel.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
#include "mapserver.h"
3737
#include "fontcache.h"
3838

39-
39+
#include "cpl_vsi.h"
40+
#include "cpl_string.h"
4041

4142

4243

@@ -774,8 +775,8 @@ int msFreeFontSet(fontSetObj *fontset)
774775

775776
int msLoadFontSet(fontSetObj *fontset, mapObj *map)
776777
{
777-
FILE *stream;
778-
char buffer[MS_BUFFER_LENGTH];
778+
VSILFILE *stream;
779+
const char* line;
779780
char alias[64], file1[MS_PATH_LENGTH], file2[MS_PATH_LENGTH];
780781
char *path;
781782
char szPath[MS_MAXPATHLEN];
@@ -798,20 +799,20 @@ int msLoadFontSet(fontSetObj *fontset, mapObj *map)
798799
/* return(-1); */
799800
/* } */
800801

801-
stream = fopen( msBuildPath(szPath, fontset->map->mappath, fontset->filename), "r");
802+
stream = VSIFOpenL( msBuildPath(szPath, fontset->map->mappath, fontset->filename), "rb");
802803
if(!stream) {
803804
msSetError(MS_IOERR, "Error opening fontset %s.", "msLoadFontset()",
804805
fontset->filename);
805806
return(-1);
806807
}
807808

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

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

814-
sscanf(buffer,"%s %s", alias, file1);
815+
sscanf(line,"%s %s", alias, file1);
815816

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

847848
fontset->numfonts = i;
848-
fclose(stream); /* close the file */
849+
VSIFCloseL(stream); /* close the file */
849850
free(path);
850851

851852
return(0);

mapogroutput.c renamed to mapogroutput.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,14 @@
3333
#include "mapthread.h"
3434
#include "mapows.h"
3535

36-
#define __USE_LARGEFILE64 1
3736
#include "ogr_api.h"
3837
#include "ogr_srs_api.h"
3938
#include "cpl_conv.h"
4039
#include "cpl_vsi.h"
4140
#include "cpl_string.h"
4241

42+
#include <string>
43+
4344
/************************************************************************/
4445
/* msInitDefaultOGROutputFormat() */
4546
/************************************************************************/
@@ -717,21 +718,19 @@ int msOGRWriteFromQuery( mapObj *map, outputFormatObj *format, int sendheaders )
717718
CSLFetchNameValueDef(layer_options, "NATIVE_DATA", "{}");
718719
if( pszNativeData[strlen(pszNativeData)-1] == '}' )
719720
{
720-
char szTemp[32];
721-
char* pszTemplate = msSmallMalloc(strlen(pszNativeData) + 32);
722-
strcpy(pszTemplate, pszNativeData);
723-
pszTemplate[strlen(pszTemplate)-1] = 0;
721+
std::string tmpl(pszNativeData);
722+
tmpl.resize(tmpl.size() - 1);
724723
if( strlen(pszNativeData) > 2 )
725-
strcat(pszTemplate, ",");
726-
sprintf(szTemp, "\"numberMatched\":%d}", nMatchingFeatures);
727-
strcat(pszTemplate, szTemp);
724+
tmpl += ',';
725+
tmpl += "\"numberMatched\":";
726+
tmpl += std::to_string(nMatchingFeatures);
727+
tmpl += '}';
728728
layer_options = CSLSetNameValue(layer_options,
729729
"NATIVE_MEDIA_TYPE",
730730
"application/vnd.geo+json");
731731
layer_options = CSLSetNameValue(layer_options,
732732
"NATIVE_DATA",
733-
pszTemplate);
734-
msFree(pszTemplate);
733+
tmpl.c_str());
735734
}
736735
}
737736
if(!strcasecmp("true",msGetOutputFormatOption(format,"USE_FEATUREID","false"))) {
@@ -1129,11 +1128,11 @@ int msOGRWriteFromQuery( mapObj *map, outputFormatObj *format, int sendheaders )
11291128
msShapeGetClass(layer, map, &resultshape, NULL, -1);
11301129

11311130
if( resultshape.classindex >= 0
1132-
&& (layer->class[resultshape.classindex]->text.string
1131+
&& (layer->_class[resultshape.classindex]->text.string
11331132
|| layer->labelitem)
1134-
&& layer->class[resultshape.classindex]->numlabels > 0
1135-
&& layer->class[resultshape.classindex]->labels[0]->size != -1 ) {
1136-
resultshape.text = msShapeGetLabelAnnotation(layer,&resultshape,layer->class[resultshape.classindex]->labels[0]);
1133+
&& layer->_class[resultshape.classindex]->numlabels > 0
1134+
&& layer->_class[resultshape.classindex]->labels[0]->size != -1 ) {
1135+
resultshape.text = msShapeGetLabelAnnotation(layer,&resultshape,layer->_class[resultshape.classindex]->labels[0]);
11371136
}
11381137

11391138
/*

0 commit comments

Comments
 (0)