/* vi: set sw=4 ts=4: */
/*
 * Utility routines.
 *
 * Copyright (C) 2018 Denys Vlasenko
 *
 * Licensed under GPLv2, see file LICENSE in this source tree.
 */
//config:config FLOAT_DURATION
//config:	bool "Enable fractional duration arguments"
//config:	default y
//config:	help
//config:	Allow sleep N.NNN, top -d N.NNN etc.

//kbuild:lib-$(CONFIG_SLEEP)   += duration.o
//kbuild:lib-$(CONFIG_TOP)     += duration.o
//kbuild:lib-$(CONFIG_TIMEOUT) += duration.o
//kbuild:lib-$(CONFIG_PING)    += duration.o
//kbuild:lib-$(CONFIG_PING6)   += duration.o
//kbuild:lib-$(CONFIG_WATCH)   += duration.o

#include "libbb.h"

static const struct suffix_mult duration_suffixes[] ALIGN_SUFFIX = {
	{ "s", 1 },
	{ "m", 60 },
	{ "h", 60*60 },
	{ "d", 24*60*60 },
	{ "", 0 }
};

#if ENABLE_FLOAT_DURATION
duration_t FAST_FUNC parse_duration_str(char *str)
{
	duration_t duration;

	if (strchr(str, '.')) {
		double d;
		char *pp;
		int len;
		char sv;

# if ENABLE_LOCALE_SUPPORT
		/* Undo busybox.c: on input, we want to use dot
		 * as fractional separator in strtod(),
		 * regardless of current locale
		 */
		setlocale(LC_NUMERIC, "C");
# endif
		len = strspn(str, "0123456789.");
		sv = str[len];
		str[len] = '\0';
		errno = 0;
		d = strtod(str, &pp);
		if (errno || *pp)
			bb_show_usage();
		str += len;
		*str-- = sv;
		sv = *str;
		*str = '1';
		duration = d * xatoul_sfx(str, duration_suffixes);
		*str = sv;
	} else {
		duration = xatoul_sfx(str, duration_suffixes);
	}

	return duration;
}
void FAST_FUNC sleep_for_duration(duration_t duration)
{
	struct timespec ts;

	ts.tv_sec = MAXINT(typeof(ts.tv_sec));
	ts.tv_nsec = 0;
	if (duration >= 0 && duration < ts.tv_sec) {
		ts.tv_sec = duration;
		ts.tv_nsec = (duration - ts.tv_sec) * 1000000000;
	}
	/* NB: if ENABLE_ASH_SLEEP, we end up here if "sleep N"
	 * is run in ash. ^C will still work, because ash's signal handler
	 * does not return (it longjumps), the below loop
	 * will not continue looping.
	 * (This wouldn't work in hush)
	 */
	do {
		errno = 0;
		nanosleep(&ts, &ts);
	} while (errno == EINTR);
}
#else
duration_t FAST_FUNC parse_duration_str(char *str)
{
	return xatou_range_sfx(str, 0, UINT_MAX, duration_suffixes);
}
#endif
