23 #include <sys/types.h>
25 #include <grass/gis.h>
26 #include <grass/Vect.h>
27 #include <grass/glocale.h>
39 return (file->current - file->start);
41 return (ftell(file->file));
65 file->current = file->start + offset;
68 file->current += offset;
71 file->current = file->start + file->size + offset;
77 return (fseek(file->file, offset, whence));
88 file->current = file->start;
108 return (fflush(file->file));
128 if (file->current >= file->end) {
133 if (file->current + tot > file->end) {
134 tot = file->end - file->current;
135 cnt = (
int)tot / size;
137 memcpy(ptr, file->current, tot);
138 file->current += tot;
141 return (fread(ptr, size, nmemb, file->file));
157 G_fatal_error(_(
"Writing to file loaded to memory not supported"));
160 return fwrite(ptr, size, nmemb, file->file);
172 file->current =
NULL;
197 G_debug(2,
"dig_file_load ()");
199 if (file->file ==
NULL) {
200 G_warning(_(
"Unable to load file to memory, file not open"));
205 mode = GV_MEMORY_NEVER;
209 mode = GV_MEMORY_ALWAYS;
211 mode = GV_MEMORY_NEVER;
213 mode = GV_MEMORY_AUTO;
215 G_warning(_(
"Vector memory mode not supported, using 'AUTO'"));
217 G_debug(2,
" requested mode = %d", mode);
220 fstat(fileno(file->file), &sbuf);
223 G_debug(2,
" size = %u", size);
227 if (mode == GV_MEMORY_AUTO)
228 mode = GV_MEMORY_NEVER;
229 if (mode == GV_MEMORY_ALWAYS)
235 file->start = G_malloc(size);
236 if (file->start ==
NULL)
239 fseek(file->file, 0L, 0);
240 ret = fread(file->start, size, 1, file->file);
241 fseek(file->file, 0L, 0);
250 file->current = file->start;
251 file->end = file->start +
size;
254 G_debug(2,
" file was loaded to the memory");
258 G_debug(2,
" file was not loaded to the memory");
int G_strcasecmp(const char *x, const char *y)
String compare ignoring case (upper or lower)
size_t dig_fwrite(void *ptr, size_t size, size_t nmemb, GVFILE *file)
Write GVFILE.
void G_free(void *buf)
Free allocated memory.
char * G__getenv(const char *name)
Get environment variable.
void dig_file_free(GVFILE *file)
Free GVFILE.
int dig_fseek(GVFILE *file, long offset, int whence)
Set GVFILE position.
int dig_fflush(GVFILE *file)
Flush GVFILE.
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
int G_debug(int level, const char *msg,...)
Print debugging message.
void dig_file_init(GVFILE *file)
Initialize GVFILE.
void dig_rewind(GVFILE *file)
Rewind GVFILE position.
int dig_file_load(GVFILE *file)
Load opened GVFILE to memory.
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
size_t dig_fread(void *ptr, size_t size, size_t nmemb, GVFILE *file)
Read GVFILE.
long dig_ftell(GVFILE *file)
Get GVFILE position.