MCPcopy Index your code
hub / github.com/MapServer/MapServer / msSHPDiskTreeOpen

Function msSHPDiskTreeOpen

maptree.c:86–192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84
85
86SHPTreeHandle msSHPDiskTreeOpen(const char * pszTree, int debug)
87{
88 char *pszFullname, *pszBasename;
89 SHPTreeHandle psTree;
90
91 char pabyBuf[16];
92 int i;
93 char bBigEndian;
94
95 /* -------------------------------------------------------------------- */
96 /* Establish the byte order on this machine. */
97 /* -------------------------------------------------------------------- */
98 i = 1;
99 if( *((uchar *) &i) == 1 )
100 bBigEndian = MS_FALSE;
101 else
102 bBigEndian = MS_TRUE;
103
104 /* -------------------------------------------------------------------- */
105 /* Initialize the info structure. */
106 /* -------------------------------------------------------------------- */
107 psTree = (SHPTreeHandle) msSmallMalloc(sizeof(SHPTreeInfo));
108
109 /* -------------------------------------------------------------------- */
110 /* Compute the base (layer) name. If there is any extension */
111 /* on the passed in filename we will strip it off. */
112 /* -------------------------------------------------------------------- */
113 pszBasename = (char *) msSmallMalloc(strlen(pszTree)+5);
114 strcpy( pszBasename, pszTree );
115 for( i = strlen(pszBasename)-1;
116 i > 0 && pszBasename[i] != '.' && pszBasename[i] != '/'
117 && pszBasename[i] != '\\';
118 i-- ) {}
119
120 if( pszBasename[i] == '.' )
121 pszBasename[i] = '\0';
122
123 /* -------------------------------------------------------------------- */
124 /* Open the .shp and .shx files. Note that files pulled from */
125 /* a PC to Unix with upper case filenames won't work! */
126 /* -------------------------------------------------------------------- */
127 pszFullname = (char *) msSmallMalloc(strlen(pszBasename) + 5);
128 sprintf( pszFullname, "%s%s", pszBasename, MS_INDEX_EXTENSION);
129 psTree->fp = fopen(pszFullname, "rb" );
130
131 msFree(pszBasename); /* don't need these any more */
132 msFree(pszFullname);
133
134 if( psTree->fp == NULL ) {
135 msFree(psTree);
136 return( NULL );
137 }
138
139 fread( pabyBuf, 8, 1, psTree->fp );
140
141 memcpy( &psTree->signature, pabyBuf, 3 );
142 if( strncmp(psTree->signature,"SQT",3) )
143 {

Callers 4

msSearchDiskTreeFunction · 0.85
msReadTreeFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 4

msSmallMallocFunction · 0.85
msFreeFunction · 0.85
msDebugFunction · 0.85
SwapWordFunction · 0.70

Tested by

no test coverage detected