From 6cdf2324d714b5f87dac893b453129f7b4bc0413 Mon Sep 17 00:00:00 2001 From: aspiring_aurelian Date: Sat, 9 Dec 2023 09:08:14 -0600 Subject: No longer overwrite existing makefile --- main.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index d25e435..b688864 100644 --- a/main.c +++ b/main.c @@ -31,8 +31,12 @@ void *f1_newer(void *arg) { } void *create_template(void *arg) { - /* Create simple main.c and makefile boilerplate */ + /* Create simple main.c or makefile boilerplate */ char *path = (char *) arg; + struct stat attr; + if (stat(path, &attr) == 0) { + return NULL; + } int fd = creat(path, 00644); FILE *file = fdopen(fd, "w"); switch(path[2]) { @@ -54,12 +58,13 @@ void new(char *argv[]) { char *name = argv[2]; mkdir(name, 0777); chdir(name); + pthread_t s_thread, m_thread; pthread_create(&s_thread, NULL, create_template, (void *) "main.c"); pthread_create(&m_thread, NULL, create_template, (void *) "makefile"); - pthread_join(s_thread, NULL); pthread_join(m_thread, NULL); + printf("Created project: %s\n", name); exit(0); } @@ -123,9 +128,9 @@ int main(int argc, char *argv[]) { break; default: execl("/usr/bin/make", "make", "debug", NULL); - printf("\n"); } } + if (mode == RUN) printf("\n"); waitpid(make_pid, NULL, 0); } else if (mode == BUILD || mode == BUILD_RELEASE) { -- cgit v1.2.3