Commit 9e6663d9 authored by Philip Carns's avatar Philip Carns

fscanf and vfscanf wrappers

- needs testing
parent da08451f
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
* - POSIX_FWRITES * - POSIX_FWRITES
* - POSIX_FSEEKS * - POSIX_FSEEKS
* - add regression test cases for all functions captured here * - add regression test cases for all functions captured here
* - especially the scanf and printf variants
*/ */
/* catalog of stdio functions instrumented by this module /* catalog of stdio functions instrumented by this module
...@@ -39,7 +40,8 @@ ...@@ -39,7 +40,8 @@
* int fgetc(FILE *); DONE * int fgetc(FILE *); DONE
* char *fgets(char *, int, FILE *); DONE * char *fgets(char *, int, FILE *); DONE
* size_t fread(void *, size_t, size_t, FILE *); DONE * size_t fread(void *, size_t, size_t, FILE *); DONE
* int fscanf(FILE *, const char *, ...); * int fscanf(FILE *, const char *, ...); DONE
* int vfscanf(FILE *, const char *, va_list); DONE
* int getc(FILE *); * int getc(FILE *);
* int getc_unlocked(FILE *); * int getc_unlocked(FILE *);
* int getw(FILE *); * int getw(FILE *);
...@@ -100,6 +102,8 @@ DARSHAN_FORWARD_DECL(fflush, int, (FILE *fp)); ...@@ -100,6 +102,8 @@ DARSHAN_FORWARD_DECL(fflush, int, (FILE *fp));
DARSHAN_FORWARD_DECL(fwrite, size_t, (const void *ptr, size_t size, size_t nmemb, FILE *stream)); DARSHAN_FORWARD_DECL(fwrite, size_t, (const void *ptr, size_t size, size_t nmemb, FILE *stream));
DARSHAN_FORWARD_DECL(fread, size_t, (void *ptr, size_t size, size_t nmemb, FILE *stream)); DARSHAN_FORWARD_DECL(fread, size_t, (void *ptr, size_t size, size_t nmemb, FILE *stream));
DARSHAN_FORWARD_DECL(fgetc, int, (FILE *stream)); DARSHAN_FORWARD_DECL(fgetc, int, (FILE *stream));
DARSHAN_FORWARD_DECL(fscanf, int, (FILE *stream, const char *format, ...));
DARSHAN_FORWARD_DECL(vfscanf, int, (FILE *stream, const char *format, va_list ap));
DARSHAN_FORWARD_DECL(fgets, char*, (char *s, int size, FILE *stream)); DARSHAN_FORWARD_DECL(fgets, char*, (char *s, int size, FILE *stream));
DARSHAN_FORWARD_DECL(fseek, int, (FILE *stream, long offset, int whence)); DARSHAN_FORWARD_DECL(fseek, int, (FILE *stream, long offset, int whence));
...@@ -449,6 +453,59 @@ size_t DARSHAN_DECL(fgetc)(FILE *stream) ...@@ -449,6 +453,59 @@ size_t DARSHAN_DECL(fgetc)(FILE *stream)
return(ret); return(ret);
} }
int DARSHAN_DECL(fscanf)(FILE *stream, const char *format, ...)
{
int ret;
double tm1, tm2;
va_list ap;
long start_off, end_off;
MAP_OR_FAIL(vfscanf);
tm1 = darshan_core_wtime();
/* NOTE: we intentionally switch to vfscanf here to handle the variable
* length arguments.
*/
start_off = ftell(stream);
va_start(ap, format);
ret = __real_vfscanf(stream, format, ap);
va_end(ap);
end_off = ftell(stream);
tm2 = darshan_core_wtime();
STDIO_LOCK();
stdio_runtime_initialize();
if(ret != 0)
STDIO_RECORD_READ(stream, end_off-start_off, tm1, tm2);
STDIO_UNLOCK();
return(ret);
}
int DARSHAN_DECL(vfscanf)(FILE *stream, const char *format, va_list ap)
{
int ret;
double tm1, tm2;
long start_off, end_off;
MAP_OR_FAIL(vfscanf);
tm1 = darshan_core_wtime();
start_off = ftell(stream);
ret = __real_vfscanf(stream, format, ap);
end_off = ftell(stream);
tm2 = darshan_core_wtime();
STDIO_LOCK();
stdio_runtime_initialize();
if(ret != 0)
STDIO_RECORD_READ(stream, end_off-start_off, tm1, tm2);
STDIO_UNLOCK();
return(ret);
}
char* DARSHAN_DECL(fgets)(char *s, int size, FILE *stream) char* DARSHAN_DECL(fgets)(char *s, int size, FILE *stream)
{ {
char *ret; char *ret;
......
...@@ -8,5 +8,7 @@ ...@@ -8,5 +8,7 @@
--wrap=fwrite --wrap=fwrite
--wrap=fread --wrap=fread
--wrap=fgetc --wrap=fgetc
--wrap=fscanf
--wrap=vfscanf
--wrap=fgets --wrap=fgets
--wrap=fseek --wrap=fseek
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment