diff options
Diffstat (limited to 'src')
| -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 **); |
