| 1 |
/* -*- linux-c -*- |
| 2 |
* |
| 3 |
* strfloctime.c - staprun/io time-based formatting |
| 4 |
* |
| 5 |
* This file is part of systemtap, and is free software. You can |
| 6 |
* redistribute it and/or modify it under the terms of the GNU General |
| 7 |
* Public License (GPL); either version 2, or (at your option) any |
| 8 |
* later version. |
| 9 |
* |
| 10 |
* Copyright (C) 2007-2013 Red Hat Inc. |
| 11 |
*/ |
| 12 |
|
| 13 |
#include "staprun.h" |
| 14 |
#include <time.h> |
| 15 |
|
| 16 |
int stap_strfloctime(char *buf, size_t max, const char *fmt, time_t t) |
| 17 |
{ |
| 18 |
struct tm tm; |
| 19 |
size_t ret; |
| 20 |
if (buf == NULL || fmt == NULL || max <= 1) |
| 21 |
return -EINVAL; |
| 22 |
localtime_r(&t, &tm); |
| 23 |
/* NB: this following invocation is the reason for this CU being built |
| 24 |
with -Wno-format-nonliteral. strftime parsing does not have security |
| 25 |
implications AFAIK, but gcc still wants to check them. */ |
| 26 |
ret = strftime(buf, max, fmt, &tm); |
| 27 |
if (ret == 0) |
| 28 |
return -EINVAL; |
| 29 |
return (int)ret; |
| 30 |
} |
| 31 |
|