コード例 #1
0
ファイル: parse-duration.c プロジェクト: execunix/vinos
/* After a number HH has been parsed, parse subsequent :MM or :MM:SS.  */
static time_t
parse_hr_min_sec (time_t start, cch_t * pz)
{
  int lpct = 0;

  errno = 0;

  /* For as long as our scanner pointer points to a colon *AND*
     we've not looped before, then keep looping.  (two iterations max) */
  while ((*pz == ':') && (lpct++ <= 1))
    {
      unsigned long v = str_const_to_ul (pz+1, &pz, 10);

      if (errno != 0)
        return BAD_TIME;

      start = scale_n_add (v, start, 60);

      if (errno != 0)
        return BAD_TIME;
    }

  /* allow for trailing spaces */
  while (isspace ((unsigned char)*pz))
    pz++;
  if (*pz != NUL)
    {
      errno = EINVAL;
      return BAD_TIME;
    }

  return start;
}
コード例 #2
0
ファイル: parse-duration.c プロジェクト: pombredanne/NetBSD
static time_t
parse_scaled_value (time_t base, cch_t ** ppz, cch_t * endp, int scale)
{
    cch_t * pz = *ppz;
    time_t val;

    if (base == BAD_TIME)
        return base;

    errno = 0;
    val = str_const_to_ul (pz, &pz, 10);
    if (errno != 0)
        return BAD_TIME;
    while (isspace ((unsigned char)*pz))   pz++;
    if (pz != endp)
    {
        errno = EINVAL;
        return BAD_TIME;
    }

    *ppz =  pz;
    return scale_n_add (base, val, scale);
}