summaryrefslogtreecommitdiffstats
path: root/src/utils.c
diff options
context:
space:
mode:
authorFilip Wandzio <contact@philw.dev>2026-03-01 11:29:12 +0100
committerFilip Wandzio <contact@philw.dev>2026-03-01 11:29:12 +0100
commita2afca302c68b8b5d7c3bec13378180b60a3ac17 (patch)
tree0c7424a1847ff91f61ab439b5e497e5a093639b2 /src/utils.c
downloadysnp-a2afca302c68b8b5d7c3bec13378180b60a3ac17.tar.gz
ysnp-a2afca302c68b8b5d7c3bec13378180b60a3ac17.zip
Scaffold project
Signed-off-by: Filip Wandzio <contact@philw.dev>
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c
new file mode 100644
index 0000000..c139929
--- /dev/null
+++ b/src/utils.c
@@ -0,0 +1,34 @@
1#include "utils.h"
2#include <stdio.h>
3#include <stdlib.h>
4#include <time.h>
5
6void print_line(void) {
7 printf("--------------------------------------------------\n");
8}
9
10void wait_enter(const char *msg) {
11 if (msg)
12 printf("%s", msg);
13 int c;
14 while ((c = getchar()) != '\n' && c != EOF)
15 ;
16}
17
18char ask_yes_no(const char *msg) {
19 char c = 'n';
20 printf("%s", msg);
21 if (scanf(" %c", &c) != 1)
22 c = 'n';
23 int flush;
24 while ((flush = getchar()) != '\n' && flush != EOF)
25 ;
26 return c;
27}
28
29void now_str(char *buf, size_t size) {
30 time_t t = time(NULL);
31 strftime(buf, size, "%Y-%m-%d %H:%M:%S", localtime(&t));
32}
33
34size_t rand_index(size_t max) { return max ? (size_t)(rand() % max) : 0; }