diff options
| author | Frank Warmerdam <warmerdam@pobox.com> | 2013-06-22 17:07:26 +0000 |
|---|---|---|
| committer | Frank Warmerdam <warmerdam@pobox.com> | 2013-06-22 17:07:26 +0000 |
| commit | 47ed7427c8c87229963eba585408b690082e2f72 (patch) | |
| tree | 3a24744a5457b2b435ce259d2c643403f0378a9b | |
| parent | 651a224f0993646f889cb9bc035bdde1d3d8ba25 (diff) | |
| download | PROJ-47ed7427c8c87229963eba585408b690082e2f72.tar.gz PROJ-47ed7427c8c87229963eba585408b690082e2f72.zip | |
add pj_ctx_fgets() implementation (untested)
git-svn-id: http://svn.osgeo.org/metacrs/proj/trunk@2347 4e78687f-474d-0410-85f9-8d5e500ac6b2
| -rw-r--r-- | src/pj_fileapi.c | 35 | ||||
| -rw-r--r-- | src/projects.h | 1 |
2 files changed, 36 insertions, 0 deletions
diff --git a/src/pj_fileapi.c b/src/pj_fileapi.c index 1a1a0f21..d0d2a442 100644 --- a/src/pj_fileapi.c +++ b/src/pj_fileapi.c @@ -165,3 +165,38 @@ void pj_ctx_fclose(projCtx ctx, PAFile file) { ctx->fileapi->FClose(file); } + +/************************************************************************/ +/* pj_ctx_fgets() */ +/* */ +/* A not very optimal implementation of fgets on top of */ +/* fread(). If we end up using this a lot more care should be */ +/* taken. */ +/************************************************************************/ + +char *pj_ctx_fgets(projCtx ctx, char *line, int size, PAFile file) +{ + long start = pj_ctx_ftell(ctx, file); + size_t bytes_read; + int i; + + line[size-1] = '\0'; + bytes_read = pj_ctx_fread(ctx, line, 1, size-1, file); + if(bytes_read == 0) + return NULL; + if(bytes_read < size) + { + line[bytes_read] = '\0'; + } + + for( i = 0; i < size-2; i++) + { + if (line[i] == '\n') + { + line[i+1] = '\0'; + pj_ctx_fseek(ctx, file, start + i + 1, SEEK_SET); + break; + } + } + return line; +} diff --git a/src/projects.h b/src/projects.h index 0e24566e..442c483f 100644 --- a/src/projects.h +++ b/src/projects.h @@ -400,6 +400,7 @@ size_t pj_ctx_fread(projCtx ctx, void *buffer, size_t size, size_t nmemb, PAFile int pj_ctx_fseek(projCtx ctx, PAFile file, long offset, int whence); long pj_ctx_ftell(projCtx ctx, PAFile file); void pj_ctx_fclose(projCtx ctx, PAFile file); +char *pj_ctx_fgets(projCtx ctx, char *line, int size, PAFile file); /* procedure prototypes */ double dmstor(const char *, char **); |
