X-Git-Url: https://tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Futils.c;fp=src%2Futils.c;h=3a3030d1ce3ebfcf8cd0b42e7a5193ab1185b669;hp=8655e2beb848fd0ed81456ea650ac2180f174fb0;hb=9235256116574927657a93944ef1b21e255e771b;hpb=c6a15e27d934e90a1f3a26438dddb395bdc9de19 diff --git a/src/utils.c b/src/utils.c index 8655e2be..3a3030d1 100644 --- a/src/utils.c +++ b/src/utils.c @@ -18,8 +18,6 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#include - #include "logger.h" #include "system.h" #include "utils.h" @@ -81,57 +79,6 @@ size_t bin2hex(const void *vsrc, char *dst, size_t length) { return length * 2; } -char *absolute_path(const char *path) { -#ifdef HAVE_WINDOWS - // Works for nonexistent paths - return _fullpath(NULL, path, 0); -#else - - if(!path || !*path) { - return NULL; - } - - // If an absolute path was passed, return its copy - if(*path == '/') { - return xstrdup(path); - } - - // Try using realpath. If it fails for any reason - // other than that the file was not found, bail out. - char *abs = realpath(path, NULL); - - if(abs || errno != ENOENT) { - return abs; - } - - // Since the file does not exist, we're forced to use a fallback. - // Get current working directory and concatenate it with the argument. - char cwd[PATH_MAX]; - - if(!getcwd(cwd, sizeof(cwd))) { - return NULL; - } - - // Remove trailing slash if present since we'll be adding our own - size_t cwdlen = strlen(cwd); - - if(cwdlen && cwd[cwdlen - 1] == '/') { - cwd[cwdlen - 1] = '\0'; - } - - // We don't do any normalization because it's complicated, and the payoff is small. - // If user passed something like '.././../foo' — that's their choice; fopen works either way. - xasprintf(&abs, "%s/%s", cwd, path); - - if(strlen(abs) >= PATH_MAX) { - free(abs); - abs = NULL; - } - - return abs; -#endif -} - size_t b64decode_tinc(const char *src, void *dst, size_t length) { size_t i; uint32_t triplet = 0; @@ -347,32 +294,6 @@ char *replace_name(const char *name) { return ret_name; } -/* Open a file with the desired permissions, minus the umask. - Also, if we want to create an executable file, we call fchmod() - to set the executable bits. */ - -FILE *fopenmask(const char *filename, const char *mode, mode_t perms) { - mode_t mask = umask(0); - perms &= ~mask; - umask(~perms & 0777); - FILE *f = fopen(filename, mode); - - if(!f) { - fprintf(stderr, "Could not open %s: %s\n", filename, strerror(errno)); - return NULL; - } - -#ifdef HAVE_FCHMOD - - if(perms & 0444) { - fchmod(fileno(f), perms); - } - -#endif - umask(mask); - return f; -} - bool string_eq(const char *first, const char *second) { return !first == !second && !(first && second && strcmp(first, second));