-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.c
65 lines (57 loc) · 1005 Bytes
/
helpers.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
#include "shell.h"
/**
* run_prompt - prints prompt to stdout
*/
void run_prompt(void)
{
char *buffer = "($) ";
int len;
len = _strlen(buffer);
write(1, buffer, len);
}
/**
* _memset - fills memory with null bytes
* @buffer: pointer to memory location to set
* Return: set memory
*/
char *_memset(char *buffer)
{
unsigned int i;
for (i = 0; buffer[i] != '\0'; i++)
{
buffer[i] = '0';
}
return (buffer);
}
/**
* file_stat - check whether a file exists
* @str: string containing full path of a command
* Return: 0 if file exist, else 1
*/
int file_stat(char *str)
{
struct stat sb;
if (stat(str, &sb) == 0)
return (0);
else
return (1);
}
/**
* cmd_error - error message for command not found
* @filename: name of command(user input)
*/
void cmd_error(char *filename)
{
_putstring("hsh: 1: ");
_putstring(filename);
_putstring(": not found\n");
}
/**
* signal_handle - signal handler
* @n: signal
*/
void signal_handle(int n)
{
(void) n;
_putstring("\n($)");
}