-
Notifications
You must be signed in to change notification settings - Fork 0
/
ALL_Printers.c
69 lines (65 loc) · 1.11 KB
/
ALL_Printers.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
#include "shell.h"
/**
* Number_int_print - This function prints integers using
* the _putchar function.
* @Num: Integer The integer to be printed is passed as the parameter Num.
*
*/
void Number_int_print(int Num)
{
unsigned int b = Num;
if (Num < 0)
{
F_putchar('-');
b = -b;
}
if ((b / 10) > 0)
{
Number_print(b / 10);
}
F_putchar(b % 10 + '0');
}
/**
* Number_print - The name of the function that prints
* unsigned integers using _putchar function.
* @Num: Passes an unsigned integer as a parameter to the function.
*
*/
void Number_print(unsigned int Num)
{
unsigned int b = Num;
if ((b / 10) > 0)
Number_print(b / 10);
F_putchar(b % 10 + '0');
}
/**
* Echo_print - This function executes the built-in echo command.
* @cmd: the Command parsed
*
* Return: 0 if successful and -1 if unsuccessful.
*/
int Echo_print(char **cmd)
{
int Stat;
pid_t _PID;
_PID = fork();
if (_PID == 0)
{
if (execve("/bin/echo", cmd, environ) == -1)
{
return (-1);
}
exit(EXIT_FAILURE);
}
else if (_PID < 0)
{
return (-1);
}
else
{
do {
waitpid(_PID, &Stat, WUNTRACED);
} while (!WIFEXITED(Stat) && !WIFSIGNALED(Stat));
}
return (1);
}