diff mbox

[28/46] lib: fwts_dump: replace asctime with strftime

Message ID 1421175905-17035-29-git-send-email-colin.king@canonical.com
State Accepted
Headers show

Commit Message

Colin Ian King Jan. 13, 2015, 7:04 p.m. UTC
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(-)

Comments

Ivan Hu Jan. 15, 2015, 7:35 a.m. UTC | #1
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>
Alex Hung Jan. 20, 2015, 7:47 a.m. UTC | #2
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 mbox

Patch

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");