mirror of
https://github.com/troglobit/finit.git
synced 2026-10-04 14:54:14 +07:00
New function, strtobytes(), allows k/M/G ISO size modifiers
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
+30
@@ -25,6 +25,7 @@
|
||||
#include <ctype.h> /* isprint() */
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/sysinfo.h> /* sysinfo() */
|
||||
#include <lite/lite.h> /* strlcat() */
|
||||
@@ -45,6 +46,35 @@ char *progname(char *arg0)
|
||||
return prognm;
|
||||
}
|
||||
|
||||
int strtobytes(char *arg)
|
||||
{
|
||||
int mod = 0, bytes;
|
||||
size_t pos;
|
||||
|
||||
if (!arg)
|
||||
return -1;
|
||||
|
||||
pos = strspn(arg, "0123456789");
|
||||
if (arg[pos] != 0) {
|
||||
if (arg[pos] == 'G')
|
||||
mod = 3;
|
||||
else if (arg[pos] == 'M')
|
||||
mod = 2;
|
||||
else if (arg[pos] == 'k')
|
||||
mod = 1;
|
||||
else
|
||||
return -1;
|
||||
|
||||
arg[pos] = 0;
|
||||
}
|
||||
|
||||
bytes = atoi(arg);
|
||||
while (mod--)
|
||||
bytes *= 1000;
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
void do_sleep(unsigned int sec)
|
||||
{
|
||||
while ((sec = sleep(sec)))
|
||||
|
||||
@@ -39,6 +39,7 @@ extern char *prognm;
|
||||
#include <lite/conio.h>
|
||||
|
||||
char *progname (char *arg0);
|
||||
int strtobytes (char *arg);
|
||||
void do_sleep (unsigned int sec);
|
||||
|
||||
long jiffies (void);
|
||||
|
||||
Reference in New Issue
Block a user