mirror of
https://github.com/weechat/weechat.git
synced 2026-06-30 14:56:39 +02:00
core: convert "long long" to "unsigned long long" in functions util_get_microseconds_string and util_parse_delay
This commit is contained in:
@@ -2035,7 +2035,7 @@ COMMAND_CALLBACK(debug)
|
||||
struct t_weechat_plugin *ptr_plugin;
|
||||
struct timeval time_start, time_end;
|
||||
char *result, *str_threshold;
|
||||
long long threshold;
|
||||
unsigned long long threshold;
|
||||
int debug;
|
||||
|
||||
/* make C compiler happy */
|
||||
@@ -2073,7 +2073,8 @@ COMMAND_CALLBACK(debug)
|
||||
if (string_strcmp (argv[1], "callbacks") == 0)
|
||||
{
|
||||
COMMAND_MIN_ARGS(3, argv[1]);
|
||||
threshold = util_parse_delay (argv[2], 1);
|
||||
if (!util_parse_delay (argv[2], 1, &threshold))
|
||||
COMMAND_ERROR;
|
||||
if (threshold > 0)
|
||||
{
|
||||
str_threshold = util_get_microseconds_string (threshold);
|
||||
@@ -6174,7 +6175,7 @@ command_repeat_timer_cb (const void *pointer, void *data, int remaining_calls)
|
||||
COMMAND_CALLBACK(repeat)
|
||||
{
|
||||
int arg_count, count, i;
|
||||
long long interval;
|
||||
unsigned long long interval;
|
||||
char *error;
|
||||
struct t_command_repeat *cmd_repeat;
|
||||
|
||||
@@ -6189,9 +6190,8 @@ COMMAND_CALLBACK(repeat)
|
||||
|
||||
if ((argc >= 5) && (string_strcmp (argv[1], "-interval") == 0))
|
||||
{
|
||||
interval = util_parse_delay (argv[2], 1000000);
|
||||
if (interval < 0)
|
||||
interval = 0;
|
||||
if (!util_parse_delay (argv[2], 1000000, &interval))
|
||||
COMMAND_ERROR;
|
||||
interval /= 1000;
|
||||
arg_count = 3;
|
||||
}
|
||||
@@ -7871,7 +7871,7 @@ COMMAND_CALLBACK(version)
|
||||
|
||||
COMMAND_CALLBACK(wait)
|
||||
{
|
||||
long long delay;
|
||||
unsigned long long delay;
|
||||
|
||||
/* make C compiler happy */
|
||||
(void) pointer;
|
||||
@@ -7879,7 +7879,8 @@ COMMAND_CALLBACK(wait)
|
||||
|
||||
COMMAND_MIN_ARGS(3, "");
|
||||
|
||||
delay = util_parse_delay (argv[1], 1000000);
|
||||
if (!util_parse_delay (argv[1], 1000000, &delay))
|
||||
COMMAND_ERROR;
|
||||
if (delay < 1)
|
||||
COMMAND_ERROR;
|
||||
|
||||
|
||||
@@ -865,7 +865,9 @@ debug_display_time_elapsed (struct timeval *time1, struct timeval *time2,
|
||||
|
||||
gettimeofday (&debug_timeval_end, NULL);
|
||||
diff = util_timeval_diff (time1, time2);
|
||||
str_diff = util_get_microseconds_string (diff);
|
||||
if (diff < 0)
|
||||
diff *= -1;
|
||||
str_diff = util_get_microseconds_string ((unsigned long long)diff);
|
||||
|
||||
if (display)
|
||||
{
|
||||
|
||||
@@ -523,7 +523,7 @@ hook_callback_end (struct t_hook *hook, struct t_hook_exec_cb *hook_exec_cb)
|
||||
time_diff = util_timeval_diff (&hook_exec_cb->start_time, &end_time);
|
||||
if (time_diff >= debug_long_callbacks)
|
||||
{
|
||||
str_diff = util_get_microseconds_string (time_diff);
|
||||
str_diff = util_get_microseconds_string ((unsigned long long)time_diff);
|
||||
log_printf (
|
||||
_("debug: long callback: hook %s (%s), plugin: %s, "
|
||||
"subplugin: %s, time elapsed: %s"),
|
||||
|
||||
+5
-5
@@ -285,14 +285,14 @@ sys_display_rusage (void)
|
||||
#ifdef HAVE_SYS_RESOURCE_H
|
||||
struct rusage usage;
|
||||
char *str_time;
|
||||
long long microseconds;
|
||||
unsigned long long microseconds;
|
||||
|
||||
gui_chat_printf (NULL, "");
|
||||
gui_chat_printf (NULL, _("Resource usage (see \"man getrusage\" for help):"));
|
||||
getrusage (RUSAGE_SELF, &usage);
|
||||
/* ru_utime: user CPU time used */
|
||||
microseconds = ((long long)usage.ru_utime.tv_sec * 1000000)
|
||||
+ (long long)usage.ru_utime.tv_usec;
|
||||
microseconds = ((unsigned long long)usage.ru_utime.tv_sec * 1000000)
|
||||
+ (unsigned long long)usage.ru_utime.tv_usec;
|
||||
str_time = util_get_microseconds_string (microseconds);
|
||||
if (str_time)
|
||||
{
|
||||
@@ -300,8 +300,8 @@ sys_display_rusage (void)
|
||||
free (str_time);
|
||||
}
|
||||
/* ru_stime: system CPU time used */
|
||||
microseconds = ((long long)usage.ru_stime.tv_sec * 1000000)
|
||||
+ (long long)usage.ru_stime.tv_usec;
|
||||
microseconds = ((unsigned long long)usage.ru_stime.tv_sec * 1000000)
|
||||
+ (unsigned long long)usage.ru_stime.tv_usec;
|
||||
str_time = util_get_microseconds_string (microseconds);
|
||||
if (str_time)
|
||||
{
|
||||
|
||||
+32
-19
@@ -123,9 +123,9 @@ util_timeval_add (struct timeval *tv, long long interval)
|
||||
*/
|
||||
|
||||
char *
|
||||
util_get_microseconds_string (long long microseconds)
|
||||
util_get_microseconds_string (unsigned long long microseconds)
|
||||
{
|
||||
long long hour, min, sec, usec;
|
||||
unsigned long long hour, min, sec, usec;
|
||||
char result[128];
|
||||
|
||||
usec = microseconds % 1000000;
|
||||
@@ -134,7 +134,7 @@ util_get_microseconds_string (long long microseconds)
|
||||
hour = (microseconds / 1000000) / 3600;
|
||||
|
||||
snprintf (result, sizeof (result),
|
||||
"%lld:%02lld:%02lld.%06lld",
|
||||
"%llu:%02llu:%02llu.%06llu",
|
||||
hour, min, sec, usec);
|
||||
|
||||
return strdup (result);
|
||||
@@ -534,18 +534,26 @@ util_get_time_diff (time_t time1, time_t time2,
|
||||
* - 60000000: minutes
|
||||
* - 3600000000: hours
|
||||
*
|
||||
* Returns the delay in microseconds, -1 if error.
|
||||
* Returns:
|
||||
* 1: OK
|
||||
* 0: error
|
||||
*/
|
||||
|
||||
long long
|
||||
util_parse_delay (const char *string_delay, long long default_factor)
|
||||
int
|
||||
util_parse_delay (const char *string_delay, unsigned long long default_factor,
|
||||
unsigned long long *delay)
|
||||
{
|
||||
const char *pos;
|
||||
char *str_number, *error;
|
||||
long long factor, delay;
|
||||
unsigned long long factor;
|
||||
|
||||
if (!delay)
|
||||
return 0;
|
||||
|
||||
*delay = 0;
|
||||
|
||||
if (!string_delay || !string_delay[0] || (default_factor < 1))
|
||||
return -1LL;
|
||||
return 0;
|
||||
|
||||
factor = default_factor;
|
||||
|
||||
@@ -559,37 +567,42 @@ util_parse_delay (const char *string_delay, long long default_factor)
|
||||
{
|
||||
str_number = string_strndup (string_delay, pos - string_delay);
|
||||
if (strcmp (pos, "us") == 0)
|
||||
factor = 1LL;
|
||||
factor = 1ULL;
|
||||
else if (strcmp (pos, "ms") == 0)
|
||||
factor = 1000LL;
|
||||
factor = 1000ULL;
|
||||
else if (strcmp (pos, "s") == 0)
|
||||
factor = 1000LL * 1000LL;
|
||||
factor = 1000ULL * 1000ULL;
|
||||
else if (strcmp (pos, "m") == 0)
|
||||
factor = 1000LL * 1000LL * 60LL;
|
||||
factor = 1000ULL * 1000ULL * 60ULL;
|
||||
else if (strcmp (pos, "h") == 0)
|
||||
factor = 1000LL * 1000LL * 60LL * 60LL;
|
||||
factor = 1000ULL * 1000ULL * 60ULL * 60ULL;
|
||||
else
|
||||
return -1LL;
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string_delay[0] == '-')
|
||||
return 0;
|
||||
str_number = strdup (string_delay);
|
||||
}
|
||||
|
||||
if (!str_number)
|
||||
return -1LL;
|
||||
return 0;
|
||||
|
||||
error = NULL;
|
||||
delay = strtoll (str_number, &error, 10);
|
||||
if (!error || error[0] || (delay < 0))
|
||||
*delay = strtoull (str_number, &error, 10);
|
||||
if (!error || error[0])
|
||||
{
|
||||
free (str_number);
|
||||
return -1LL;
|
||||
*delay = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
*delay *= factor;
|
||||
|
||||
free (str_number);
|
||||
|
||||
return delay * factor;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -29,7 +29,7 @@ extern long long util_timeval_diff (struct timeval *tv1, struct timeval *tv2);
|
||||
extern void util_timeval_add (struct timeval *tv, long long interval);
|
||||
|
||||
/* time */
|
||||
extern char *util_get_microseconds_string (long long diff);
|
||||
extern char *util_get_microseconds_string (unsigned long long microseconds);
|
||||
extern const char *util_get_time_string (const time_t *date);
|
||||
extern int util_strftimeval (char *string, int max, const char *format,
|
||||
struct timeval *tv);
|
||||
@@ -41,8 +41,9 @@ extern void util_get_time_diff (time_t time1, time_t time2,
|
||||
|
||||
/* delay */
|
||||
|
||||
extern long long util_parse_delay (const char *string_delay,
|
||||
long long default_factor);
|
||||
extern int util_parse_delay (const char *string_delay,
|
||||
unsigned long long default_factor,
|
||||
unsigned long long *delay);
|
||||
|
||||
/* version */
|
||||
extern int util_version_number (const char *version);
|
||||
|
||||
@@ -435,7 +435,7 @@ gui_bar_item_get_value (struct t_gui_bar *bar, struct t_gui_window *window,
|
||||
time_diff = util_timeval_diff (&start_time, &end_time);
|
||||
if (time_diff >= debug_long_callbacks)
|
||||
{
|
||||
str_diff = util_get_microseconds_string (time_diff);
|
||||
str_diff = util_get_microseconds_string ((unsigned long long)time_diff);
|
||||
log_printf (
|
||||
_("debug: long callback: bar: %s, item: %s, plugin: %s, "
|
||||
"time elapsed: %s"),
|
||||
|
||||
Reference in New Issue
Block a user