summaryrefslogtreecommitdiff
path: root/lib/parse-duration.c
diff options
context:
space:
mode:
authorBruce Korb <bkorb@gnu.org>2011-03-03 15:07:32 -0800
committerBruce Korb <bkorb@gnu.org>2011-03-03 15:07:32 -0800
commit10169d19c63b2a88e6c63ba48a40a42dd290494c (patch)
tree9ed05aebe8cef6ea315d854bf843611eeda519c7 /lib/parse-duration.c
parent329c5b59c9ebfed10f51859a5d16fbe080835a24 (diff)
downloadgnulib-10169d19c63b2a88e6c63ba48a40a42dd290494c.tar.gz
parse-duration: remove xalloc.h dependency
* lib/parse-duration.c (parse_period): handle NULL return from strdup instead of calling xstrdup(). * modules/parse-duration: remove "xalloc" dependency
Diffstat (limited to 'lib/parse-duration.c')
-rw-r--r--lib/parse-duration.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/parse-duration.c b/lib/parse-duration.c
index 8c281330a4..0a8c4ada84 100644
--- a/lib/parse-duration.c
+++ b/lib/parse-duration.c
@@ -26,7 +26,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include "xalloc.h"
#ifndef NUL
#define NUL '\0'
@@ -381,7 +380,7 @@ parse_time (cch_t * pz)
}
/* Returns a substring of the given string, with spaces at the beginning and at
- the end destructively removed. */
+ the end destructively removed, per SNOBOL. */
static char *
trim (char * pz)
{
@@ -406,13 +405,20 @@ trim (char * pz)
static time_t
parse_period (cch_t * in_pz)
{
- char * pz = xstrdup (in_pz);
- char * pT = strchr (pz, 'T');
+ char * pT;
char * ps;
+ char * pz = strdup (in_pz);
void * fptr = pz;
time_t res = 0;
- if (pT != NUL)
+ if (pz == NULL)
+ {
+ errno = ENOMEM;
+ return BAD_TIME;
+ }
+
+ pT = strchr (pz, 'T');
+ if (pT != NULL)
{
*(pT++) = NUL;
pz = trim (pz);