mirror of
https://github.com/tio/tio.git
synced 2026-05-01 14:57:59 +02:00
Move string_to_long() to misc.c
This commit is contained in:
parent
d7b038d4ef
commit
e9d5a23129
4 changed files with 19 additions and 17 deletions
17
src/misc.c
17
src/misc.c
|
|
@ -25,6 +25,7 @@
|
|||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <errno.h>
|
||||
#include "error.h"
|
||||
#include "print.h"
|
||||
#include "options.h"
|
||||
|
|
@ -91,3 +92,19 @@ void delay(long ms)
|
|||
|
||||
nanosleep(&ts, NULL);
|
||||
}
|
||||
|
||||
long string_to_long(char *string)
|
||||
{
|
||||
long result;
|
||||
char *end_token;
|
||||
|
||||
errno = 0;
|
||||
result = strtol(string, &end_token, 10);
|
||||
if ((errno != 0) || (*end_token != 0))
|
||||
{
|
||||
printf("Error: Invalid digit\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,3 +24,4 @@
|
|||
|
||||
char * current_time(void);
|
||||
void delay(long ms);
|
||||
long string_to_long(char *string);
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@
|
|||
#include <limits.h>
|
||||
#include "options.h"
|
||||
#include "error.h"
|
||||
#include "misc.h"
|
||||
|
||||
/* Default options */
|
||||
struct option_t option =
|
||||
|
|
@ -80,22 +81,6 @@ void print_help(char *argv[])
|
|||
printf("\n");
|
||||
}
|
||||
|
||||
long string_to_long(char *string)
|
||||
{
|
||||
long result;
|
||||
char *end_token;
|
||||
|
||||
errno = 0;
|
||||
result = strtol(string, &end_token, 10);
|
||||
if ((errno != 0) || (*end_token != 0))
|
||||
{
|
||||
printf("Error: Invalid digit\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void parse_options(int argc, char *argv[])
|
||||
{
|
||||
int c;
|
||||
|
|
|
|||
|
|
@ -56,5 +56,4 @@ struct option_t
|
|||
|
||||
extern struct option_t option;
|
||||
|
||||
long string_to_long(char *string);
|
||||
void parse_options(int argc, char *argv[]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue