Message ID | 1421175905-17035-29-git-send-email-colin.king@canonical.com |
---|---|
State | Accepted |
Headers | show |
On 01/14/2015 03:04 AM, Colin King wrote: > From: Colin Ian King <colin.king@canonical.com> > > cppcheck is picking up some minor style issues which can > be easily fixed: > > [src/lib/src/fwts_dump.c:203]: > (style) Obsolete function 'asctime' called. It is > recommended to use the function 'strftime' instead. > > Signed-off-by: Colin Ian King <colin.king@canonical.com> > --- > src/lib/src/fwts_dump.c | 8 +++----- > 1 file changed, 3 insertions(+), 5 deletions(-) > > diff --git a/src/lib/src/fwts_dump.c b/src/lib/src/fwts_dump.c > index 33156c0..0023aea 100644 > --- a/src/lib/src/fwts_dump.c > +++ b/src/lib/src/fwts_dump.c > @@ -193,16 +193,14 @@ static int dump_readme(void) > { > time_t now = time(NULL); > struct tm *tm = localtime(&now); > + char *str, buf[64]; > FILE *fp; > - char *str; > - int len; > > if ((fp = fopen("README.txt", "w")) == NULL) > return FWTS_ERROR; > > - str = asctime(tm); > - len = strlen(str) - 1; > - fprintf(fp, "This is output captured by fwts on %*.*s.\n\n", len, len, str); > + (void)strftime(buf, sizeof(buf), "%a %b %e %T %Y", tm); > + fprintf(fp, "This is output captured by fwts on %s.\n\n", buf); > > fwts_framework_show_version(fp, "fwts"); > > Acked-by: Ivan Hu <ivan.hu@canonical.com>
On 01/14/2015 03:04 AM, Colin King wrote: > From: Colin Ian King <colin.king@canonical.com> > > cppcheck is picking up some minor style issues which can > be easily fixed: > > [src/lib/src/fwts_dump.c:203]: > (style) Obsolete function 'asctime' called. It is > recommended to use the function 'strftime' instead. > > Signed-off-by: Colin Ian King <colin.king@canonical.com> > --- > src/lib/src/fwts_dump.c | 8 +++----- > 1 file changed, 3 insertions(+), 5 deletions(-) > > diff --git a/src/lib/src/fwts_dump.c b/src/lib/src/fwts_dump.c > index 33156c0..0023aea 100644 > --- a/src/lib/src/fwts_dump.c > +++ b/src/lib/src/fwts_dump.c > @@ -193,16 +193,14 @@ static int dump_readme(void) > { > time_t now = time(NULL); > struct tm *tm = localtime(&now); > + char *str, buf[64]; > FILE *fp; > - char *str; > - int len; > > if ((fp = fopen("README.txt", "w")) == NULL) > return FWTS_ERROR; > > - str = asctime(tm); > - len = strlen(str) - 1; > - fprintf(fp, "This is output captured by fwts on %*.*s.\n\n", len, len, str); > + (void)strftime(buf, sizeof(buf), "%a %b %e %T %Y", tm); > + fprintf(fp, "This is output captured by fwts on %s.\n\n", buf); > > fwts_framework_show_version(fp, "fwts"); > > Acked-by: Alex Hung <alex.hung@canonical.com>
diff --git a/src/lib/src/fwts_dump.c b/src/lib/src/fwts_dump.c index 33156c0..0023aea 100644 --- a/src/lib/src/fwts_dump.c +++ b/src/lib/src/fwts_dump.c @@ -193,16 +193,14 @@ static int dump_readme(void) { time_t now = time(NULL); struct tm *tm = localtime(&now); + char *str, buf[64]; FILE *fp; - char *str; - int len; if ((fp = fopen("README.txt", "w")) == NULL) return FWTS_ERROR; - str = asctime(tm); - len = strlen(str) - 1; - fprintf(fp, "This is output captured by fwts on %*.*s.\n\n", len, len, str); + (void)strftime(buf, sizeof(buf), "%a %b %e %T %Y", tm); + fprintf(fp, "This is output captured by fwts on %s.\n\n", buf); fwts_framework_show_version(fp, "fwts");