-
Notifications
You must be signed in to change notification settings - Fork 2
/
my_puts.c
67 lines (58 loc) · 973 Bytes
/
my_puts.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
/*
** utils.c for my_select in /home/sebastien/travaux/my_select
**
** Made by sebastien
** Login <[email protected]>
**
** Started on Tue Jan 14 17:32:39 2014 sebastien
** Last update Thu Jan 16 15:28:46 2014 sebastien
*/
#include <stdlib.h>
#include <unistd.h>
#include "my_select.h"
int puterror(char *str)
{
int i;
i = 0;
if (str == NULL)
return (-1);
while (str[i])
write(2, &str[i++], 1);
return (-1);
}
void my_putstr(char *str)
{
int i;
i = 0;
if (str == NULL)
return ;
while (str[i])
write(1, &str[i++], 1);
}
void my_tputs(char *str)
{
int i;
i = 0;
if (str == NULL)
{
puterror("error: problem with tgetstr or tgoto\n");
exit(EXIT_FAILURE);
}
while (str[i])
write(fd_tty, &str[i++], 1);
}
void my_putchar(char c)
{
write(fd_tty, &c, 1);
}
void my_putnbr(int n)
{
if (n < 0)
{
my_putchar('-');
n = -n;
}
if (n >= 10)
my_putnbr(n / 10);
my_putchar((n % 10) + '0');
}