diff options
author | Anton L. Šijanec <anton@sijanec.eu> | 2020-05-01 15:18:12 +0200 |
---|---|---|
committer | Anton L. Šijanec <anton@sijanec.eu> | 2020-05-01 15:18:12 +0200 |
commit | 6961e4237f24306ab2475f4f527a7c802134c4d9 (patch) | |
tree | 0d18e9dd78fe3dee482872a65fbf823e00cd31db /lib | |
parent | folder structure README.mf (diff) | |
download | bverbose-6961e4237f24306ab2475f4f527a7c802134c4d9.tar bverbose-6961e4237f24306ab2475f4f527a7c802134c4d9.tar.gz bverbose-6961e4237f24306ab2475f4f527a7c802134c4d9.tar.bz2 bverbose-6961e4237f24306ab2475f4f527a7c802134c4d9.tar.lz bverbose-6961e4237f24306ab2475f4f527a7c802134c4d9.tar.xz bverbose-6961e4237f24306ab2475f4f527a7c802134c4d9.tar.zst bverbose-6961e4237f24306ab2475f4f527a7c802134c4d9.zip |
Diffstat (limited to 'lib')
-rw-r--r-- | lib/jsmin.c | 2 | ||||
-rw-r--r-- | lib/mkdirp.c | 5 | ||||
-rw-r--r-- | lib/randstring.c | 21 |
3 files changed, 23 insertions, 5 deletions
diff --git a/lib/jsmin.c b/lib/jsmin.c index 402c6c9..3cb0e9b 100644 --- a/lib/jsmin.c +++ b/lib/jsmin.c @@ -29,7 +29,7 @@ This file was modified by Anton Šijanec in 2020 in order to allow it being used as a library for minifying JS inside other programs. All I've added is the option to read from a source file and output to the minified file. */ - +#pragma once #include <stdlib.h> #include <stdio.h> #include <fopenmkdir.c> diff --git a/lib/mkdirp.c b/lib/mkdirp.c index 8c79cf4..a6c58e6 100644 --- a/lib/mkdirp.c +++ b/lib/mkdirp.c @@ -1,12 +1,9 @@ // borrowed from https://gist.github.com/JonathonReinhart/8c0d90191c38af2dcadb102c4e202950 - +#pragma once #include <string.h> #include <limits.h> /* PATH_MAX */ #include <sys/stat.h> /* mkdir(2) */ #include <errno.h> -#ifndef PATH_MAX -#define PATH_MAX 255 -#endif int mkdir_p(const char *path) { /* Adapted from http://stackoverflow.com/a/2336245/119527 */ const size_t len = strlen(path); diff --git a/lib/randstring.c b/lib/randstring.c new file mode 100644 index 0000000..2eeed8f --- /dev/null +++ b/lib/randstring.c @@ -0,0 +1,21 @@ +#pragma once +char *randstring(size_t length) { + + static char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + char *randomString = NULL; + + if (length) { + randomString = malloc(sizeof(char) * (length +1)); + + if (randomString) { + for (int n = 0;n < length;n++) { + int key = rand() % (int)(sizeof(charset) -1); + randomString[n] = charset[key]; + } + + randomString[length] = '\0'; + } + } + + return randomString; +} |