diff --git a/inc/lektor/internal/os.h b/inc/lektor/internal/os.h
index 4f04ccf3db7ecd2408e110e81041bd050e465709..dc7b1e5a8af46052a2b99be8911b69bbfb7b94f0 100644
--- a/inc/lektor/internal/os.h
+++ b/inc/lektor/internal/os.h
@@ -92,8 +92,10 @@ enum {
 typedef int SOCKET;
 #define closesocket(fd)        close(fd)
 #define INVALID_SOCKET         ((SOCKET)(-1))
-#define to_file_mode_t(perm)   (perm)
-#define to_socket_size_t(size) (size)
+#define to_file_mode_t(perm)   ((unsigned int)(perm))
+#define to_size_t(size) ((size_t)(size))
+#define to_int_t(size)  ((size_t)(size))
+#define to_socket_len_t(size)  ((socklen_t)(size))
 
 #else
 /* LKT_OS_WIN  */
@@ -105,7 +107,9 @@ typedef int SOCKET;
 #define socket(dom, type, proto__) WSASocket(dom, type, 0, 0, 0, 0)
 #define get_nprocs_conf()          2
 #define to_file_mode_t(perm)       ((int)(perm))
-#define to_socket_size_t(size)     ((ULONG)(size))
+#define to_size_t(size)     ((ULONG)(size))
+#define to_int_t(size)      ((int)(size))
+#define to_socket_len_t(size)      ((int)(size))
 
 #endif
 
diff --git a/inc/lektor/net.h b/inc/lektor/net.h
index 75c78da936656bd852b9dc46ca48188f2cd0b5dc..1ce5f37f43711d55cb8d04afa115a6e912028165 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;
-    size_t fds_len;
+    ULONG fds_len;
     ULONG fds_max;
 
 #else
@@ -64,6 +64,7 @@ struct lkt_state {
     struct pollfd *fds;
     size_t fds_len;
     size_t fds_max;
+
 #endif
 
     struct lkt_client *clients;
diff --git a/src/base/config.c b/src/base/config.c
index 04d991c12c83c49590fcc04424cb7db05ee5b8e4..b8bf452b6210ba134a4042aa7af260d476b1e140 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, (int)(conf_len)-1) != NULL) {
+    if (getcwd(conf, to_size_t(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/logfile.c b/src/base/logfile.c
index d462cbcd3bf863e7cbb47130b4975b523a0ff131..a85decf1c0df7e49b41bb96d57d5f6997f4e0ddb 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/database/open.c b/src/database/open.c
index caa0ec32110eaf18fa32306238e6c4c72bc35b6e..a733877bdef27dfdb53ab62370781bfb06d4dd61 100644
--- a/src/database/open.c
+++ b/src/database/open.c
@@ -199,7 +199,7 @@ bool
 database_open(lkt_db *db, const char *dbpath, bool check)
 {
     bool retry = false;
-#if !defined(LKT_OS_WIN) && (LKT_OS_WIN == 1)
+#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;
diff --git a/src/net/listen.c b/src/net/listen.c
index e6d357c4c5dc79d640ff839dfbd1d7d4dab6bcd2..fbe92597520202defa4b4a0552688952f04c9011 100644
--- a/src/net/listen.c
+++ b/src/net/listen.c
@@ -407,7 +407,7 @@ handle_incoming_data(struct lkt_state *srv, size_t i)
         /* Recieve some data. */
         const ssize_t n =
             recv(srv->fds[i].fd, cli->buffer_in + cli->buffer_in_len,
-                 LKT_MESSAGE_MAX - (int)cli->buffer_in_len, 0);
+                 to_int_t(LKT_MESSAGE_MAX - cli->buffer_in_len), 0);
 
         if (n < 0) {
             if (is_error_would_block(get_last_error()))
@@ -617,7 +617,7 @@ init_listening_socket_net(const char *host, const char *port)
             goto failure;
         }
 
-        if (bind(fd, p->ai_addr, (int)p->ai_addrlen) != 0) {
+        if (bind(fd, p->ai_addr, to_socket_len_t(p->ai_addrlen)) != 0) {
             closesocket(fd);
             LOG_ERROR("INIT", "Failed to bind tcp socket: %s", strerror(errno));
             continue;
@@ -710,7 +710,7 @@ static int
 handle_network_events(struct lkt_state *srv)
 {
     errno       = 0;
-    const int n = poll(srv->fds, (ULONG)srv->fds_len, 100);
+    const int n = poll(srv->fds, to_size_t(srv->fds_len), 100);
     if (n < 0 && errno != EAGAIN && errno != EINTR) {
         perror("poll failed");
         return -1;
@@ -999,7 +999,7 @@ redo:
 
 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)
+#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         */
@@ -1052,19 +1052,19 @@ ___lkt_handle_ILL(struct lkt_state UNUSED *srv)
     ___lkt_handle_INT(srv);
 }
 
-static void
+PRIVATE_FUNCTION void
 ___lkt_handle_USR1(struct lkt_state UNUSED *srv)
 {
     LOG_INFO("SIGNAL", "Ignore signal SIGUSR1");
 }
 
-static void
+PRIVATE_FUNCTION void
 ___lkt_handle_USR2(struct lkt_state UNUSED *srv)
 {
     LOG_INFO("SIGNAL", "Ignore signal SIGUSR2");
 }
 
-static inline void
+PRIVATE_FUNCTION void
 handle_signals(struct lkt_state *srv)
 {
 #define HANDLE(srv, signal)                                                    \
@@ -1101,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 = (ULONG)fds_max_config;
+    srv->fds_max = to_size_t(fds_max_config);
     srv->fds     = LKT_ALLOC_STRUCT_ARRAY(pollfd, srv->fds_max);
     srv->clients = LKT_ALLOC_STRUCT_ARRAY(lkt_client, srv->fds_max);