Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Postfix/src/global/   (Postfix Mailserver Version 3.11©)  Datei vom 11.9.2024 mit Größe 2 kB image not shown  

Quelle  conv_time.c

  Sprache: C
 

/*++
/* NAME
/* conv_time 3
/* SUMMARY
/* time value conversion
/* SYNOPSIS
/* #include <conv_time.h>
/*
/* int conv_time(strval, timval, def_unit);
/* const char *strval;
/* int *timval;
/* int def_unit;
/* DESCRIPTION
/* conv_time() converts a numerical time value with optional
/* one-letter suffix that specifies an explicit time unit: s
/* (seconds), m (minutes), h (hours), d (days) or w (weeks).
/* Internally, time is represented in seconds.
/*
/* Arguments:
/* .IP strval
/* Input value.
/* .IP timval
/* Result pointer.
/* .IP def_unit
/* The default time unit suffix character.
/* DIAGNOSTICS
/* The result value is non-zero in case of success, zero in
/* case of a bad time value or a bad time unit suffix.
/* LICENSE
/* .ad
/* .fi
/* The Secure Mailer license must be distributed with this software.
/* AUTHOR(S)
/* Wietse Venema
/* IBM T.J. Watson Research
/* P.O. Box 704
/* Yorktown Heights, NY 10598, USA
/*
/* Wietse Venema
/* Google, Inc.
/* 111 8th Avenue
/* New York, NY 10011, USA
/*--*/


/* System library. */

#include <sys_defs.h>
#include <limits.h>   /* INT_MAX */
#include <stdlib.h>
#include <errno.h>

/* Utility library. */

#include <msg.h>

/* Global library. */

#include <conv_time.h>

#define MINUTE (60)
#define HOUR (60 * MINUTE)
#define DAY (24 * HOUR)
#define WEEK (7 * DAY)

/* conv_time - convert time value */

int     conv_time(const char *strval, int *timval, int def_unit)
{
    char   *end;
    int     intval;
    long    longval;

    errno = 0;
    intval = longval = strtol(strval, &end, 10);
    if (*strval == 0 || errno == ERANGE || longval != intval || intval < 0
  /* || (*end != 0 && end[1] != 0) */ )
 return (0);

    switch (*end ? *end : def_unit) {
    case 'w':
 if (intval < INT_MAX / WEEK) {
     *timval = intval * WEEK;
     return (1);
 } else {
     return (0);
 }
    case 'd':
 if (intval < INT_MAX / DAY) {
     *timval = intval * DAY;
     return (1);
 } else {
     return (0);
 }
    case 'h':
 if (intval < INT_MAX / HOUR) {
     *timval = intval * HOUR;
     return (1);
 } else {
     return (0);
 }
    case 'm':
 if (intval < INT_MAX / MINUTE) {
     *timval = intval * MINUTE;
     return (1);
 } else {
     return (0);
 }
    case 's':
 *timval = intval;
 return (1);
    }
    return (0);
}

Messung V0.5 in Prozent
C=72 H=96 G=84

¤ Dauer der Verarbeitung: 0.12 Sekunden  (vorverarbeitet am  2026-08-08) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.