diff options
| author | 2011-05-29 05:07:33 +0200 | |
|---|---|---|
| committer | 2011-05-29 05:07:33 +0200 | |
| commit | bfd8c56c016d97e6845664c7bb2e9b0c65d8cb95 (patch) | |
| tree | 5a2c5c393d17b844c1e6d13869a4f832c18d4176 /src/xplist.c | |
| parent | b82787f145fbc205e539a23715cbd3d11f3cdd9b (diff) | |
| download | libplist-bfd8c56c016d97e6845664c7bb2e9b0c65d8cb95.tar.gz libplist-bfd8c56c016d97e6845664c7bb2e9b0c65d8cb95.tar.bz2 | |
Use simple sscanf for parsing dates if strptime is not available
Diffstat (limited to 'src/xplist.c')
| -rw-r--r-- | src/xplist.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/xplist.c b/src/xplist.c index f62178e..edce2f9 100644 --- a/src/xplist.c +++ b/src/xplist.c | |||
| @@ -260,6 +260,20 @@ static void node_to_xml(node_t* node, void *xml_struct) | |||
| 260 | return; | 260 | return; |
| 261 | } | 261 | } |
| 262 | 262 | ||
| 263 | static void parse_date(const char *strval, struct tm *btime) | ||
| 264 | { | ||
| 265 | if (!btime) return; | ||
| 266 | memset(btime, 0, sizeof(struct tm)); | ||
| 267 | if (!strval) return; | ||
| 268 | #ifdef strptime | ||
| 269 | strptime((char*)strval, "%Y-%m-%dT%H:%M:%SZ", btime); | ||
| 270 | #else | ||
| 271 | sscanf(strval, "%d-%d-%dT%d:%d:%dZ", &btime->tm_year, &btime->tm_mon, &btime->tm_mday, &btime->tm_hour, &btime->tm_min, &btime->tm_sec); | ||
| 272 | btime->tm_year-=1900; | ||
| 273 | btime->tm_mon--; | ||
| 274 | #endif | ||
| 275 | } | ||
| 276 | |||
| 263 | static void xml_to_node(xmlNodePtr xml_node, plist_t * plist_node) | 277 | static void xml_to_node(xmlNodePtr xml_node, plist_t * plist_node) |
| 264 | { | 278 | { |
| 265 | xmlNodePtr node = NULL; | 279 | xmlNodePtr node = NULL; |
| @@ -330,8 +344,7 @@ static void xml_to_node(xmlNodePtr xml_node, plist_t * plist_node) | |||
| 330 | time_t time = 0; | 344 | time_t time = 0; |
| 331 | if (strlen(strval) >= 11) { | 345 | if (strlen(strval) >= 11) { |
| 332 | struct tm btime; | 346 | struct tm btime; |
| 333 | memset(&btime, 0, sizeof(struct tm)); | 347 | parse_date((const char*)strval, &btime); |
| 334 | strptime((char*)strval, "%Y-%m-%dT%H:%M:%SZ", &btime); | ||
| 335 | time = mktime(&btime); | 348 | time = mktime(&btime); |
| 336 | } | 349 | } |
| 337 | data->timeval.tv_sec = (long)time; | 350 | data->timeval.tv_sec = (long)time; |
