diff options
author | Dmitri Pal <dpal@redhat.com> | 2013-01-26 20:07:48 -0500 |
---|---|---|
committer | Ondrej Kos <okos@redhat.com> | 2013-01-28 12:03:23 +0100 |
commit | 44174288111e9715ccbb96e8a8283e99a721ba7b (patch) | |
tree | 7500bc62bf91247f50039765542bffeec4baf1af | |
parent | 059519fb2a8d056eba5f61cde98ed8b5292195d4 (diff) | |
download | ding-libs2-44174288111e9715ccbb96e8a8283e99a721ba7b.tar.gz ding-libs2-44174288111e9715ccbb96e8a8283e99a721ba7b.tar.xz ding-libs2-44174288111e9715ccbb96e8a8283e99a721ba7b.zip |
Expose collected stat data
Added a new top level interface funtion
and a unit test for it.
-rw-r--r-- | ini/ini_configobj.h | 14 | ||||
-rw-r--r-- | ini/ini_fileobj.c | 14 | ||||
-rw-r--r-- | ini/ini_parse_ut.c | 17 |
3 files changed, 45 insertions, 0 deletions
diff --git a/ini/ini_configobj.h b/ini/ini_configobj.h index 16f6499..ac85ba7 100644 --- a/ini/ini_configobj.h +++ b/ini/ini_configobj.h @@ -587,6 +587,20 @@ void ini_config_print_errors(FILE *file, char **error_list); */ const char *ini_config_get_filename(struct ini_cfgfile *file_ctx); +/** + * @brief Get pointer to collected stat data + * + * Returns the pointer to the internal stat structure. + * If stat data was not collected when the file was open + * function would return NULL. + * + * @param[in] file_ctx Configuration file object. + * + * @return Pointer to the stat structure. + */ +const struct stat *ini_config_get_stat(struct ini_cfgfile *file_ctx); + + /** * @brief Print file context diff --git a/ini/ini_fileobj.c b/ini/ini_fileobj.c index 7d2011a..7ac9dc6 100644 --- a/ini/ini_fileobj.c +++ b/ini/ini_fileobj.c @@ -215,6 +215,20 @@ const char *ini_config_get_filename(struct ini_cfgfile *file_ctx) return ret; } +/* Get pointer to stat structure */ +const struct stat *ini_config_get_stat(struct ini_cfgfile *file_ctx) +{ + const struct stat *ret; + TRACE_FLOW_ENTRY(); + + if (file_ctx->stats_read) ret = &(file_ctx->file_stats); + else ret = NULL; + + TRACE_FLOW_EXIT(); + return ret; +} + + /* Check access */ int ini_config_access_check(struct ini_cfgfile *file_ctx, uint32_t flags, diff --git a/ini/ini_parse_ut.c b/ini/ini_parse_ut.c index c5e9166..32c59e7 100644 --- a/ini/ini_parse_ut.c +++ b/ini/ini_parse_ut.c @@ -1057,6 +1057,7 @@ int startup_test(void) char command[PATH_MAX * 3]; char *srcdir = NULL; char *builddir; + const struct stat *file_stat; INIOUT(printf("<==== Startup test ====>\n")); @@ -1095,6 +1096,12 @@ int startup_test(void) return error; } + file_stat = ini_config_get_stat(file_ctx); + if (file_stat) { + printf("Expected NULL got not NULL!\n"); + return EINVAL; + } + /* We will check just permissions here. */ error = ini_config_access_check(file_ctx, INI_ACCESS_CHECK_MODE, /* add uid & gui flags @@ -1125,6 +1132,16 @@ int startup_test(void) return error; } + /* Get stats */ + file_stat = ini_config_get_stat(file_ctx); + if (!file_stat) { + printf("Expected not NULL got NULL!\n"); + return EINVAL; + } + + INIOUT(printf("File was modified at: %d seconds since Jan 1 1970.\n", + (int)(file_stat->st_mtime))); + /* We will check just permissions here. */ error = ini_config_access_check(file_ctx, INI_ACCESS_CHECK_MODE, /* add uid & gui flags |