From 551c339c02254cdd99b2ef5b720c7da1b58fed13 Mon Sep 17 00:00:00 2001 From: Phil Carns Date: Mon, 23 May 2016 21:18:51 -0400 Subject: [PATCH] getc wrapper --- darshan-runtime/lib/darshan-stdio.c | 24 ++++++++++++++++++- .../share/ld-opts/darshan-stdio-ld-opts | 1 + 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/darshan-runtime/lib/darshan-stdio.c b/darshan-runtime/lib/darshan-stdio.c index 20d588b..12e3cab 100644 --- a/darshan-runtime/lib/darshan-stdio.c +++ b/darshan-runtime/lib/darshan-stdio.c @@ -42,7 +42,7 @@ * size_t fread(void *, size_t, size_t, FILE *); DONE * int fscanf(FILE *, const char *, ...); DONE * int vfscanf(FILE *, const char *, va_list); DONE - * int getc(FILE *); + * int getc(FILE *); DONE * int getc_unlocked(FILE *); * int getw(FILE *); * @@ -102,6 +102,7 @@ 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(fread, size_t, (void *ptr, size_t size, size_t nmemb, FILE *stream)); DARSHAN_FORWARD_DECL(fgetc, int, (FILE *stream)); +DARSHAN_FORWARD_DECL(_IO_getc, 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)); @@ -453,6 +454,27 @@ size_t DARSHAN_DECL(fgetc)(FILE *stream) return(ret); } +/* NOTE: stdio.h typically implements getc() as a macro pointing to _IO_getc */ +size_t DARSHAN_DECL(_IO_getc)(FILE *stream) +{ + int ret; + double tm1, tm2; + + MAP_OR_FAIL(_IO_getc); + + tm1 = darshan_core_wtime(); + ret = __real__IO_getc(stream); + tm2 = darshan_core_wtime(); + + STDIO_LOCK(); + stdio_runtime_initialize(); + if(ret != EOF) + STDIO_RECORD_READ(stream, 1, tm1, tm2); + STDIO_UNLOCK(); + + return(ret); +} + int DARSHAN_DECL(fscanf)(FILE *stream, const char *format, ...) { int ret; diff --git a/darshan-runtime/share/ld-opts/darshan-stdio-ld-opts b/darshan-runtime/share/ld-opts/darshan-stdio-ld-opts index 96c9df6..867061f 100644 --- a/darshan-runtime/share/ld-opts/darshan-stdio-ld-opts +++ b/darshan-runtime/share/ld-opts/darshan-stdio-ld-opts @@ -10,5 +10,6 @@ --wrap=fgetc --wrap=fscanf --wrap=vfscanf +--wrap=_IO_getc --wrap=fgets --wrap=fseek -- 2.26.2