-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhelper_func.c
74 lines (67 loc) · 997 Bytes
/
helper_func.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
73
74
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "shell.h"
/**
* open_console - opens the console
*
* Return: nothing
*/
void open_console(void)
{
int fd;
while ((fd = open("/dev/console", O_RDWR)) >= 0)
{
if (fd >= 3)
{
close(fd);
break;
}
}
}
/**
* prompt - write the shell prompt to stdin
*
* @status: determines if the shell is interactive
* Return: nothing
*/
void prompt(int status)
{
if (status)
write(STDIN_FILENO, ":) ", 3);
}
/**
* t_error - error handler
*
* @s: error message
* Return: nothing
*/
void t_error(char *s)
{
write(STDERR_FILENO, s, _strlen(s));
}
/**
* _fork - creates a child process
*
* Return: the process ID
*/
int _fork(void)
{
pid_t id = fork();
if (id < 0)
{
t_error("Fork failed\n");
return (1);
}
return (id);
}
/**
* handl_sigint - Handle signals
* @sig: Signal parameter
* Return: nothing
*/
void handl_sigint(int sig)
{
(void)sig;
write(STDOUT_FILENO, "<saMosC/> SIGINT\n", 18);
}