summaryrefslogtreecommitdiff
path: root/os/windows/posix.c
diff options
context:
space:
mode:
authorBart Van Assche <bvanassche@acm.org>2020-01-05 17:51:19 -0800
committerBart Van Assche <bvanassche@acm.org>2020-01-06 11:10:56 -0800
commita4820445a718a545eb0014848399d275d25263b7 (patch)
treee42e7eb2b24bbb5c801e6c4423bcd28eb4cea1d7 /os/windows/posix.c
parentf5bff36e93580e9cc5f94a2b361c5eccaea9f2f5 (diff)
downloadfio-a4820445a718a545eb0014848399d275d25263b7.tar.gz
fio-a4820445a718a545eb0014848399d275d25263b7.tar.bz2
Windows: Use snprintf() instead of StringCch*()
Use ANSI C functions instead of Windows-specific functions. Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Diffstat (limited to 'os/windows/posix.c')
-rw-r--r--os/windows/posix.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/os/windows/posix.c b/os/windows/posix.c
index fd1d5582..e36453e9 100644
--- a/os/windows/posix.c
+++ b/os/windows/posix.c
@@ -28,10 +28,6 @@
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) {
@@ -312,11 +308,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;
}
@@ -958,8 +954,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 +995,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 +1005,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;