int write_to_dir(const char *dir, const char *name, const unsigned char *buffer, const size_t len) {
    char path[FILENAME_MAX];
    int n = snprintf(path, sizeof(path), "%s%c%s", dir, separator, name);
    if (n < 0) {
        printf("Creating file name failed\n");
        return ERROR;
    }
    if ((size_t) n >= sizeof(path)) {
        printf("File name too long\n");
        return ERROR;
    }
    return write_file(buffer, len, path);
}
int write_to_dir(const char *dir, const char *name, const unsigned char *buffer, const size_t len) {
    char path[FILENAME_MAX];
    int n = snprintf(path, sizeof(path), "%s%c%s", dir, separator, name);
    if (n < 0) {
        printf("Creating file name failed\n");
        return ERROR;
    }
    if ((size_t) n >= sizeof(path)) {
        printf("File name too long\n");
        return ERROR;
    }
    return write_file(buffer, len, path);
}