2 * Copyright 2004 Timo Hirvonen
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 #include <sys/types.h>
30 static inline int min(int a
, int b
)
35 static inline int max(int a
, int b
)
40 static inline int clamp(int val
, int minval
, int maxval
)
49 static inline int scale_from_percentage(int val
, int max_val
)
52 return (val
* max_val
- 50) / 100;
53 return (val
* max_val
+ 50) / 100;
56 static inline int scale_to_percentage(int val
, int max_val
)
58 int half
= max_val
/ 2;
64 return (val
* 100 - half
) / max_val
;
65 return (val
* 100 + half
) / max_val
;
68 static inline int str_to_int(const char *str
, long int *val
)
72 *val
= strtol(str
, &end
, 10);
73 if (*str
== 0 || *end
!= 0)
78 static inline time_t file_get_mtime(const char *filename
)
82 /* stat follows symlinks, lstat does not */
83 if (stat(filename
, &s
) == -1)
88 static inline void ns_sleep(int ns
)
94 nanosleep(&req
, NULL
);
97 static inline void us_sleep(int us
)
102 static inline void ms_sleep(int ms
)
107 static inline int is_url(const char *name
)
109 return strncmp(name
, "http://", 7) == 0;