-
Notifications
You must be signed in to change notification settings - Fork 0
/
42_header.c
57 lines (54 loc) · 1.93 KB
/
42_header.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
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
#include <time.h>
#include <stdbool.h>
#ifndef USER
# define USER "marvin"
# endif
#ifndef MAIL
# define MAIL "student.42.fr"
# endif
int set_42_header(const char *restrict path, bool open_fd)
{
time_t ltime = time(NULL);
int fd;
int amount;
struct tm tstruct = *localtime(<ime);
char buf[24];
fd = open(path, O_CREAT | O_WRONLY, 0644);
if (fd == -1)
return (-1);
dprintf(fd, "/* ************************************************************************** */\n");
dprintf(fd, "/* */\n");
dprintf(fd, "/* ::: :::::::: */\n");
dprintf(fd, "/* ");
amount = 50 - dprintf(fd, "%.*s", 43, path);
while (amount--)
dprintf(fd, " ");
dprintf(fd, " :+: :+: :+: */\n/* +:+ +:+ +:+ */\n");
amount = 52 - dprintf(fd, "/* By: %.*s <%.*s@%s>", 8, USER, 8, USER, MAIL);
while (amount--)
dprintf(fd, " ");
dprintf(fd, "+#+ +:+ +#+ */\n");
dprintf(fd, "/* +#+#+#+#+#+ +#+ */\n");
amount = dprintf(fd, "/* Created: ");
strftime(buf, 24, "%Y/%m/%d %T by ", &tstruct);
amount += dprintf(fd, "%s%.*s", buf, 8, USER);
amount = 55 - amount;
while (amount--)
dprintf(fd, " ");
dprintf(fd, "#+# #+# */\n");
amount = dprintf(fd, "/* Updated: ");
strftime(buf, 24, "%Y/%m/%d %T by ", &tstruct);
amount += dprintf(fd, "%s%.*s", buf, 8, USER);
amount = 54 - amount;
while (amount--)
dprintf(fd, " ");
dprintf(fd, "### ########.fr */\n");
dprintf(fd, "/* */\n");
dprintf(fd, "/* ************************************************************************** */\n\n");
if (!open_fd)
return (close(fd));
return (fd);
}