Skip to content

Commit

Permalink
better faster stronger : optimized code
Browse files Browse the repository at this point in the history
  • Loading branch information
Namonay committed Dec 21, 2023
1 parent c2ab33c commit 6e31586
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion 42_header.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# define MAIL "student.42.fr"
# endif

int set_42_header(char *path, bool open_fd)
int set_42_header(const char *restrict path, bool open_fd)
{
time_t ltime = time(NULL);
int fd;
Expand Down
12 changes: 6 additions & 6 deletions fastclass.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
#define STATIC_CLASS 2u
#define has_flag(flags, flag) (flags >> flag & 1)

int set_42_header(char *path, bool open_fd);
int set_42_header(const char *restrict path, bool open_fd);

char *ft_toupper(char *str)
char *ft_toupper(const char *restrict str)
{
char *buf;
unsigned int i;
Expand All @@ -27,7 +27,7 @@ char *ft_toupper(char *str)
return (buf);
}

void create_class(char *filename, char *name, unsigned int flags)
void create_class(const char *restrict filename, const char *restrict name, unsigned int flags)
{
char *upper = ft_toupper(name);
int fd;
Expand Down Expand Up @@ -59,7 +59,7 @@ void create_class(char *filename, char *name, unsigned int flags)
close(fd);
}

void create_cpp(char *filename, char *name, unsigned int flags)
void create_cpp(char *restrict filename, char *restrict name, unsigned int flags)
{
int fd;

Expand Down Expand Up @@ -134,12 +134,12 @@ int main(int argc, char **argv)
name = strcpy(name, *argv);
name = strcat(name, ".hpp");
if (access(name, F_OK) == 0)
dprintf(2, "WARNING : %s already exists, trying to make .cpp\n", name);
dprintf(STDERR_FILENO, "WARNING : %s already exists, trying to make .cpp\n", name);
else
create_class(name, *argv, flags);
name[strlen(*argv) + 1] = 'c';
if (access(name, F_OK) == 0)
dprintf(2, "WARNING : %s already exists, aborting\n", name);
dprintf(STDERR_FILENO, "WARNING : %s already exists, aborting\n", name);
else
create_cpp(name, *argv, flags);
free(name);
Expand Down

0 comments on commit 6e31586

Please sign in to comment.