windows: fix DWORD format string complaints
[fio.git] / os / windows / posix.c
index fd1d5582f1b33c73b84c21f4fffec4c8aafd79b9..9e9f12effbea9aaf738d159b4211ab617b3d2450 100644 (file)
 extern unsigned long mtime_since_now(struct timespec *);
 extern void fio_gettime(struct timespec *, void *);
 
-/* These aren't defined in the MinGW headers */
-HRESULT WINAPI StringCchCopyA(char *pszDest, size_t cchDest, const char *pszSrc);
-HRESULT WINAPI StringCchPrintfA(char *pszDest, size_t cchDest, const char *pszFormat, ...);
-
 int win_to_posix_error(DWORD winerr)
 {
        switch (winerr) {
@@ -172,7 +168,7 @@ int win_to_posix_error(DWORD winerr)
        case ERROR_FILE_INVALID:
                return ENXIO;
        default:
-               log_err("fio: windows error %d not handled\n", winerr);
+               log_err("fio: windows error %lu not handled\n", winerr);
                return EIO;
        }
 
@@ -192,7 +188,8 @@ int GetNumLogicalProcessors(void)
                if (error == ERROR_INSUFFICIENT_BUFFER)
                        processor_info = malloc(len);
                else {
-                       log_err("Error: GetLogicalProcessorInformation failed: %d\n", error);
+                       log_err("Error: GetLogicalProcessorInformation failed: %lu\n",
+                               error);
                        return -1;
                }
 
@@ -312,11 +309,11 @@ char *ctime_r(const time_t *t, char *buf)
         * We don't know how long `buf` is, but assume it's rounded up from
         * the minimum of 25 to 32
         */
-       StringCchPrintfA(buf, 31, "%s %s %d %02d:%02d:%02d %04d\n",
-                               dayOfWeek[systime.wDayOfWeek % 7],
-                               monthOfYear[(systime.wMonth - 1) % 12],
-                               systime.wDay, systime.wHour, systime.wMinute,
-                               systime.wSecond, systime.wYear);
+       snprintf(buf, 32, "%s %s %d %02d:%02d:%02d %04d\n",
+                dayOfWeek[systime.wDayOfWeek % 7],
+                monthOfYear[(systime.wMonth - 1) % 12],
+                systime.wDay, systime.wHour, systime.wMinute,
+                systime.wSecond, systime.wYear);
        return buf;
 }
 
@@ -754,7 +751,7 @@ int setgid(gid_t gid)
 int nice(int incr)
 {
        DWORD prioclass = NORMAL_PRIORITY_CLASS;
-       
+
        if (incr < -15)
                prioclass = HIGH_PRIORITY_CLASS;
        else if (incr < 0)
@@ -763,7 +760,7 @@ int nice(int incr)
                prioclass = IDLE_PRIORITY_CLASS;
        else if (incr > 0)
                prioclass = BELOW_NORMAL_PRIORITY_CLASS;
-       
+
        if (!SetPriorityClass(GetCurrentProcess(), prioclass))
                log_err("fio: SetPriorityClass failed\n");
 
@@ -887,7 +884,7 @@ int poll(struct pollfd fds[], nfds_t nfds, int timeout)
        FD_ZERO(&exceptfds);
 
        for (i = 0; i < nfds; i++) {
-               if (fds[i].fd < 0) {
+               if (fds[i].fd == INVALID_SOCKET) {
                        fds[i].revents = 0;
                        continue;
                }
@@ -904,7 +901,7 @@ int poll(struct pollfd fds[], nfds_t nfds, int timeout)
 
        if (rc != SOCKET_ERROR) {
                for (i = 0; i < nfds; i++) {
-                       if (fds[i].fd < 0)
+                       if (fds[i].fd == INVALID_SOCKET)
                                continue;
 
                        if ((fds[i].events & POLLIN) && FD_ISSET(fds[i].fd, &readfds))
@@ -958,8 +955,8 @@ DIR *opendir(const char *dirname)
                                OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);
        if (file != INVALID_HANDLE_VALUE) {
                CloseHandle(file);
-               dc = (struct dirent_ctx*)malloc(sizeof(struct dirent_ctx));
-               StringCchCopyA(dc->dirname, MAX_PATH, dirname);
+               dc = malloc(sizeof(struct dirent_ctx));
+               snprintf(dc->dirname, sizeof(dc->dirname), "%s", dirname);
                dc->find_handle = INVALID_HANDLE_VALUE;
        } else {
                DWORD error = GetLastError();
@@ -999,7 +996,8 @@ struct dirent *readdir(DIR *dirp)
        if (dirp->find_handle == INVALID_HANDLE_VALUE) {
                char search_pattern[MAX_PATH];
 
-               StringCchPrintfA(search_pattern, MAX_PATH-1, "%s\\*", dirp->dirname);
+               snprintf(search_pattern, sizeof(search_pattern), "%s\\*",
+                        dirp->dirname);
                dirp->find_handle = FindFirstFileA(search_pattern, &find_data);
                if (dirp->find_handle == INVALID_HANDLE_VALUE)
                        return NULL;
@@ -1008,7 +1006,7 @@ struct dirent *readdir(DIR *dirp)
                        return NULL;
        }
 
-       StringCchCopyA(de.d_name, MAX_PATH, find_data.cFileName);
+       snprintf(de.d_name, sizeof(de.d_name), find_data.cFileName);
        de.d_ino = 0;
 
        return &de;