Factor out strtobytes() helper function from syslogd.c
For use in logger.c Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
parent
f6e17bd6b3
commit
76b6981467
31
src/compat.h
31
src/compat.h
@ -31,6 +31,8 @@
|
|||||||
#define SYSKLOGD_COMPAT_H_
|
#define SYSKLOGD_COMPAT_H_
|
||||||
|
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The following macro is used to remove const cast-away warnings
|
* The following macro is used to remove const cast-away warnings
|
||||||
@ -69,4 +71,33 @@ static inline char *getprogname(void)
|
|||||||
return __progname;
|
return __progname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline 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;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* SYSKLOGD_COMPAT_H_ */
|
#endif /* SYSKLOGD_COMPAT_H_ */
|
||||||
|
@ -569,6 +569,7 @@ static char sccsid[] __attribute__((unused)) =
|
|||||||
#endif
|
#endif
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include <paths.h>
|
#include <paths.h>
|
||||||
|
#include "compat.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Linux uses EIO instead of EBADFD (mrn 12 May 96)
|
* Linux uses EIO instead of EBADFD (mrn 12 May 96)
|
||||||
@ -2713,35 +2714,6 @@ void init(void)
|
|||||||
logit("syslogd: restarted.\n");
|
logit("syslogd: restarted.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Crack a configuration file line
|
* Crack a configuration file line
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user