From c8df8599df25bfd0f732707da3af719da9111cc2 Mon Sep 17 00:00:00 2001 From: Elliu <elliu@hashi.re> Date: Wed, 1 Dec 2021 14:51:23 -0800 Subject: [PATCH] WIP: Fix build on windows --- inc/lektor/internal/os.h | 2 ++ inc/lektor/internal/worker.h | 4 ++-- inc/lektor/net.h | 2 +- src/base/config.c | 2 +- src/base/launch.c | 2 ++ src/base/logfile.c | 2 +- src/base/os.c | 1 + src/database/cache.c | 2 +- src/database/config.c | 2 +- src/database/open.c | 2 ++ src/main/lkt.c | 8 +++++--- src/mkv/write.c | 6 ++++++ src/module/module_repo.c | 2 +- src/net/listen.c | 33 +++++++++++++++++++-------------- 14 files changed, 45 insertions(+), 25 deletions(-) diff --git a/inc/lektor/internal/os.h b/inc/lektor/internal/os.h index d0f565ce..4f04ccf3 100644 --- a/inc/lektor/internal/os.h +++ b/inc/lektor/internal/os.h @@ -30,6 +30,8 @@ extern "C" { #include "lektor/internal/win32/endian.h" #include <processthreadsapi.h> #include <windows.h> +#include <direct.h> +#include <fcntl.h> #else #include <linux/limits.h> diff --git a/inc/lektor/internal/worker.h b/inc/lektor/internal/worker.h index b5d17100..6c05933d 100644 --- a/inc/lektor/internal/worker.h +++ b/inc/lektor/internal/worker.h @@ -184,8 +184,8 @@ worker_pool_push(struct worker_pool *pool, worker_pool_function func, void *arg) pool->size = 2; size_t nsize = 2 * pool->size; void *new_func = - safe_realloc((void *)pool->functions, nsize * sizeof(worker_pool_function)); - void *new_args = safe_realloc((void *)pool->args, nsize * sizeof(void *)); + safe_realloc((void *)pool->functions, (long unsigned int)nsize * sizeof(worker_pool_function)); + void *new_args = safe_realloc((void *)pool->args, (long unsigned int)nsize * sizeof(void *)); pool->size *= 2; pool->functions = new_func; diff --git a/inc/lektor/net.h b/inc/lektor/net.h index 22fe26e6..75c78da9 100644 --- a/inc/lektor/net.h +++ b/inc/lektor/net.h @@ -56,7 +56,7 @@ struct lkt_state { #if defined(LKT_OS_WIN) && (LKT_OS_WIN == 1) /* The FDS, Windob' version */ LPWSAPOLLFD fds; - ULONG fds_len; + size_t fds_len; ULONG fds_max; #else diff --git a/src/base/config.c b/src/base/config.c index 57a3f723..04d991c1 100644 --- a/src/base/config.c +++ b/src/base/config.c @@ -224,7 +224,7 @@ config_detect_file(char *conf, size_t conf_len) memset(conf, 0, conf_len * sizeof(char)); /* Try the current working dir config file. */ - if (getcwd(conf, (size_t)(conf_len)-1) != NULL) { + if (getcwd(conf, (int)(conf_len)-1) != NULL) { strncat(conf, "/lektor.ini", conf_len - 1); LOG_INFO("CONFIG", "Trying %s", conf); if (!access(conf, R_OK | F_OK)) diff --git a/src/base/launch.c b/src/base/launch.c index 48dff02c..6f18d0e7 100644 --- a/src/base/launch.c +++ b/src/base/launch.c @@ -14,7 +14,9 @@ extern char **environ; /* Private implementation details */ +#if !(defined(LKT_OS_WIN) && (LKT_OS_WIN == 1)) static pid_t ___klkt_pid = 0; +#endif static int ___is_appimage = 0; char exe[PATH_MAX]; diff --git a/src/base/logfile.c b/src/base/logfile.c index a85decf1..d462cbcd 100644 --- a/src/base/logfile.c +++ b/src/base/logfile.c @@ -54,7 +54,7 @@ ___open_all_files(struct lkt_logfile *logfile) char path[PATH_MAX]; safe_snprintf(path, PATH_MAX, "%s/1", logfile->base_folder); logfile->current_lines_in_file = ___count_lines_in_file(path); - logfile->current_fd = open(path, O_APPEND | O_CREAT | O_WRONLY, 0644); + logfile->current_fd = _open(path, O_APPEND | O_CREAT | O_WRONLY, 0644); FAIL_IF(logfile->current_fd <= 0, "Failed to open log file: %s", path); } diff --git a/src/base/os.c b/src/base/os.c index 404bc4a4..aecead7a 100644 --- a/src/base/os.c +++ b/src/base/os.c @@ -28,6 +28,7 @@ void lkt_thread_set_name(const char *name) { #if defined(LKT_OS_WIN) && (LKT_OS_WIN == 1) + (void)name; #else const size_t len = strlen(name); if (len >= 16) { diff --git a/src/database/cache.c b/src/database/cache.c index 8b6a0e1a..e3b18e96 100644 --- a/src/database/cache.c +++ b/src/database/cache.c @@ -168,7 +168,7 @@ database_cache_kara(lkt_db *db, int id) LOG_ERROR("CACHE", "Failed to cache mtime for '%s' kara %d to %ld", filepath, id, mtime); double duration = 0.; - if (kara_read_length(&duration, filepath) || isnan(duration)) + if (kara_read_length(&duration, filepath) || isnan((float)duration)) LOG_ERROR("CACHE", "Failed to read lengh of '%s' for kara %d", filepath, id); uint64_t duration_uint = (uint64_t)duration; diff --git a/src/database/config.c b/src/database/config.c index 6771ce79..d12f0c31 100644 --- a/src/database/config.c +++ b/src/database/config.c @@ -161,7 +161,7 @@ database_config_get_octal(lkt_db *db, const char *section, const char *key, unsi return false; const long octal = strtol(str_value, NULL, 8); - if (octal < 0 || octal > UINT_MAX) { + if (octal < 0 || (unsigned int)octal > UINT_MAX) { LOG_ERROR("DB", "The octal value is negative or to big for a uint!"); return false; } diff --git a/src/database/open.c b/src/database/open.c index 8042405f..caa0ec32 100644 --- a/src/database/open.c +++ b/src/database/open.c @@ -199,10 +199,12 @@ bool database_open(lkt_db *db, const char *dbpath, bool check) { bool retry = false; +#if !defined(LKT_OS_WIN) && (LKT_OS_WIN == 1) if (___is_sql_str_invalid(dbpath)) { LOG_ERROR("DB", "The database path '%s' is invalid", dbpath); return false; } +#endif /* Try the simple attach, for already initialized database */ retry: diff --git a/src/main/lkt.c b/src/main/lkt.c index f01f8a64..50853bb3 100644 --- a/src/main/lkt.c +++ b/src/main/lkt.c @@ -279,12 +279,14 @@ create_socket(const char *host_arg, const char *port_arg) "invocation of lkt or an invalid hostname..."); sock = *found->ai_addr; - sock_len = found->ai_addrlen; + sock_len = (socklen_t)(found->ai_addrlen); freeaddrinfo(found); ptr_sock = &sock; domain = AF_INET; +#if !(defined(LKT_OS_WIN) && (LKT_OS_WIN == 1)) } +#endif /* Common part */ cx = socket(domain, SOCK_STREAM, 0); @@ -770,7 +772,7 @@ status__(struct cmd_args *args) #undef check_end struct tm *p_tm = localtime(&update_ts); - len = strftime(buff, LKT_MESSAGE_MAX - 1, "%F %H:%M:%S", p_tm); + len = strftime(buff, LKT_MESSAGE_MAX - 1, "%d %H:%M:%S", p_tm); // doc says %F should exists but isn't buff[len] = '\0'; int pla_m = time_pos / 60; @@ -1163,7 +1165,7 @@ search_get__(struct cmd_args *args) memset(buff, 0, LKT_MESSAGE_MAX * sizeof(char)); read_socket(sock, buff, LKT_MESSAGE_MAX - 1); HANDLE_STATUS(buff, { exit(EXIT_SUCCESS); }); - write(1, buff, strlen(buff)); + write(1, buff, (unsigned int)strlen(buff)); } } diff --git a/src/mkv/write.c b/src/mkv/write.c index a8c6d324..e35903e5 100644 --- a/src/mkv/write.c +++ b/src/mkv/write.c @@ -95,6 +95,7 @@ mkvpropedit__(const char *const args[]) return true; #else LOG_ERROR("MKV", "The call to mkvpropedit call is not implemented in windows"); + (void)args; return false; #endif } @@ -116,11 +117,16 @@ kara_metadata_write(struct kara_metadata *mdt, const char *filename) goto error; } +#if !(defined(LKT_OS_WIN) && (LKT_OS_WIN == 1)) + // dprintf doesn't exist, used _get_osfhandle if (dprintf(fd, METADATA_TEMPLATE, mdt->source_name, mdt->song_name, mdt->category, mdt->language, mdt->author_name, mdt->song_type, mdt->song_number) < 0) { LOG_ERROR("MKV", "Failed to write to temporary file: %s", metadafilepath); goto error; } +#else + (void)mdt; +#endif if (!mkvpropedit__(args1) || !mkvpropedit__(args2)) goto error; diff --git a/src/module/module_repo.c b/src/module/module_repo.c index c7ac7043..0756b0d2 100644 --- a/src/module/module_repo.c +++ b/src/module/module_repo.c @@ -211,7 +211,7 @@ ___write_disk(char *data, size_t size, size_t nmem, void *user) { size_t realsize = size * nmem; struct ___file *file = (struct ___file *)user; - RETURN_IF(write(file->fd, data, realsize) != (ssize_t)realsize, "Failed to write", 0); + RETURN_IF(write(file->fd, data, (unsigned int)realsize) != (ssize_t)realsize, "Failed to write", 0); if (file->index < 4) { memcpy(file->magic + file->index, data, 4 - file->index); diff --git a/src/net/listen.c b/src/net/listen.c index 63e1b946..e6d357c4 100644 --- a/src/net/listen.c +++ b/src/net/listen.c @@ -406,8 +406,8 @@ handle_incoming_data(struct lkt_state *srv, size_t i) for (;;) { /* Recieve some data. */ const ssize_t n = - recv(srv->fds[i].fd, to_socket_size_t(cli->buffer_in + cli->buffer_in_len), - to_socket_size_t(LKT_MESSAGE_MAX - cli->buffer_in_len), 0); + recv(srv->fds[i].fd, cli->buffer_in + cli->buffer_in_len, + LKT_MESSAGE_MAX - (int)cli->buffer_in_len, 0); if (n < 0) { if (is_error_would_block(get_last_error())) @@ -494,11 +494,17 @@ typedef SOCKET (*init_socket_func)(const char *, const char *); static void init_permission_socket_unix(const char *file, unsigned int perms) { +#if defined(LKT_OS_WIN) && (LKT_OS_WIN == 1) + (void)file; + (void)perms; + return; +#else errno = 0; if (chmod(file, to_file_mode_t(perms)) < 0) { LOG_FATAL("INIT", "Failed to set '%s' to 0%o: %s", file, perms, strerror(errno)); } LOG_INFO("INIT", "Set socket '%s' to perms 0%o", file, perms); +#endif } static inline int @@ -573,11 +579,8 @@ init_listening_socket_unix(const char UNUSED *file, const char UNUSED *type /* = failure: close(fd); - return INVALID_SOCKET; - -#else - return INVALID_SOCKET; #endif + return INVALID_SOCKET; } PRIVATE_FUNCTION SOCKET @@ -614,7 +617,7 @@ init_listening_socket_net(const char *host, const char *port) goto failure; } - if (bind(fd, p->ai_addr, p->ai_addrlen) != 0) { + if (bind(fd, p->ai_addr, (int)p->ai_addrlen) != 0) { closesocket(fd); LOG_ERROR("INIT", "Failed to bind tcp socket: %s", strerror(errno)); continue; @@ -707,7 +710,7 @@ static int handle_network_events(struct lkt_state *srv) { errno = 0; - const int n = poll(srv->fds, srv->fds_len, 100); + const int n = poll(srv->fds, (ULONG)srv->fds_len, 100); if (n < 0 && errno != EAGAIN && errno != EINTR) { perror("poll failed"); return -1; @@ -994,11 +997,13 @@ redo: * Signal handlers * *******************/ -static int UNUSED ___lkt_signal_INT = 0; /* SIGINT => close the server */ -static int UNUSED ___lkt_signal_QUIT = 0; /* SIGQUIT => close the server */ -static int UNUSED ___lkt_signal_ILL = 0; /* SIGILL => NoT veRy HappY */ -static int UNUSED ___lkt_signal_USR1 = 0; /* SIGUSR1 => not used */ -static int UNUSED ___lkt_signal_USR2 = 0; /* SIGUSR2 => not used */ +static int ___lkt_signal_INT = 0; /* SIGINT => close the server */ +static int ___lkt_signal_ILL = 0; /* SIGILL => NoT veRy HappY */ +#if !defined(LKT_OS_WIN) && (LKT_OS_WIN == 1) +static int ___lkt_signal_QUIT = 0; /* SIGQUIT => close the server */ +static int ___lkt_signal_USR1 = 0; /* SIGUSR1 => not used */ +static int ___lkt_signal_USR2 = 0; /* SIGUSR2 => not used */ +#endif PRIVATE_FUNCTION void ___signal_handler(int sig) @@ -1096,7 +1101,7 @@ lkt_listen(struct lkt_state *srv) if (fds_max_config <= 0) LOG_FATAL("The max_clients number must be a positive integer"); - srv->fds_max = (size_t)fds_max_config; + srv->fds_max = (ULONG)fds_max_config; srv->fds = LKT_ALLOC_STRUCT_ARRAY(pollfd, srv->fds_max); srv->clients = LKT_ALLOC_STRUCT_ARRAY(lkt_client, srv->fds_max); -- GitLab