Extract filesystem-related functions into fs.c
[tinc] / src / utils.c
index c2f4333..3a3030d 100644 (file)
@@ -85,7 +85,7 @@ size_t b64decode_tinc(const char *src, void *dst, size_t length) {
        unsigned char *udst = (unsigned char *)dst;
 
        for(i = 0; i < length && src[i]; i++) {
-               triplet |= base64_decode[src[i] & 0xff] << (6 * (i & 3));
+               triplet |= (uint32_t)(base64_decode[src[i] & 0xff] << (6 * (i & 3)));
 
                if((i & 3) == 3) {
                        if(triplet & 0xff000000U) {
@@ -294,29 +294,7 @@ 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));
 }
-