-
Notifications
You must be signed in to change notification settings - Fork 0
/
checking.c
72 lines (63 loc) · 1.26 KB
/
checking.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "monty.h"
/**
* check_args_num - Check the arguments passed on to the interpreter
* @argn: Number of args
*
* Return: Nothing
*/
void check_args_num(int argn)
{
if (argn != MIN_ARGS)
handle_error(ERR_ARG_USG, NULL, 0, NULL);
}
/**
* check_access_rights - CChecks if the user has permissions to read the file
* @filename: The pathname of the file
*
* Return: Nothing
*/
void check_access_rights(char *filename)
{
if (access(filename, R_OK) == -1)
{
fprintf(stderr, "Error: Can't open file %s\n", filename);
exit(EXIT_FAILURE);
}
}
/**
* check_push_param - Check the parameter of the push instruction
* @param: The parameter to be verified
*
* Return: 0 if is a valid param or errcode if is invalid
*/
int check_push_param(char *param)
{
if (param == NULL || check_digits(param) == 0)
return (ERR_PUSH_USG);
return (VALID_PARM);
}
/**
* check_digits - Checks if all characters in a string are digits
* @s: The string to be evaluated
*
* Return: 1 if all if all evaluated characters are digits or 0 if not
*/
int check_digits(char *s)
{
int status = 1;
while (*s != '\0')
{
if (s[0] == 45)
{
++s;
continue;
}
if (isdigit(*s) == 0)
{
status = 0;
return (status);
}
++s;
}
return (status);
}