updated docs
[rlserver.git] / util.c
blob6a8d2ad2576c46dcad3e9c5b7be9beef922759b9
1 #include <sys/stat.h>
2 #include <string.h>
3 #include "util.h"
7 void str_replace (char *buf, int size, const char *str, const char *what, const char *to)
9 int i, b;
10 int len = strlen(what);
13 for (i = b = 0; str[i] != 0 && b < size - 1; i++, b++)
15 if (strncmp(&str[i], what, len) == 0)
17 const char *t = to;
18 while ((buf[b++] = *(t++)));
19 i += len - 1;
20 b -= 2;
22 else
24 buf[b] = str[i];
28 buf[b] = 0;
33 #define BUF_SIZE 1024
35 void make_dir (const char *dir)
37 char buf[BUF_SIZE];
38 int i = 0;
43 buf[i] = dir[i];
45 if (dir[i] == '/' || dir[i] == 0)
47 buf[i] = 0;
48 mkdir (buf, 0750);
49 buf[i] = '/';
51 } while (dir[i++] != 0 && i < BUF_SIZE);