Change #ifdef _WIN32 checks into #ifdef HAVE_.*

commit b964b79d495d058f645f5a63357699a6c295025e
category: bugfix
issue: #I6VAS0
CVE: NA

Signed-off-by: DongSenhao <dongsenhao2@huawei.com>
---------------------------------------

It is recommended to test a HAVE_* macro instead of directly testing the
host type in source code. Hence this patch.

Signed-off-by: Bart Van Assche <bvanassche@acm.org>
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
Signed-off-by: dongsenhao <dongsenhao2@huawei.com>
This commit is contained in:
Bart Van Assche 2022-04-21 15:18:29 -07:00 committed by dongsenhao
parent 1fa72eed97
commit 5a3dc5cd85
7 changed files with 22 additions and 9 deletions

View File

@ -116,6 +116,7 @@ AC_CHECK_HEADERS(m4_flatten([
sys/acl.h sys/acl.h
sys/ioctl.h sys/ioctl.h
sys/mount.h sys/mount.h
sys/stat.h
sys/syscall.h sys/syscall.h
sys/sysmacros.h sys/sysmacros.h
sys/utsname.h sys/utsname.h
@ -138,6 +139,7 @@ AC_CHECK_FUNCS_ONCE([
fsetxattr fsetxattr
fstat fstat
fstat64 fstat64
fsync
getgid getgid
getmntent getmntent
getuid getuid

View File

@ -24,8 +24,10 @@
#endif #endif
#include <time.h> #include <time.h>
#include <sys/stat.h> #include <sys/stat.h>
#ifndef _WIN32 #ifdef HAVE_SYS_MOUNT_H
#include <sys/mount.h> #include <sys/mount.h>
#endif
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h> #include <sys/ioctl.h>
#endif #endif
#ifdef HAVE_SYS_SYSMACROS_H #ifdef HAVE_SYS_SYSMACROS_H

View File

@ -25,9 +25,13 @@
#include <mntent.h> #include <mntent.h>
#endif #endif
#include <time.h> #include <time.h>
#ifndef _WIN32 #ifdef HAVE_SYS_STAT_H
#include <sys/stat.h> #include <sys/stat.h>
#endif
#ifdef HAVE_SYS_MOUNT_H
#include <sys/mount.h> #include <sys/mount.h>
#endif
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h> #include <sys/ioctl.h>
#endif #endif
#ifdef HAVE_LINUX_HDREG_H #ifdef HAVE_LINUX_HDREG_H
@ -636,7 +640,7 @@ int dev_reada_block(__u64 blk_addr)
int f2fs_fsync_device(void) int f2fs_fsync_device(void)
{ {
#ifndef _WIN32 #ifdef HAVE_FSYNC
int i; int i;
for (i = 0; i < c.ndevs; i++) { for (i = 0; i < c.ndevs; i++) {
@ -785,7 +789,7 @@ int f2fs_finalize_device(void)
* in the block device page cache. * in the block device page cache.
*/ */
for (i = 0; i < c.ndevs; i++) { for (i = 0; i < c.ndevs; i++) {
#ifndef _WIN32 #ifdef HAVE_FSYNC
ret = fsync(c.devices[i].fd); ret = fsync(c.devices[i].fd);
if (ret < 0) { if (ret < 0) {
MSG(0, "\tError: Could not conduct fsync!!!\n"); MSG(0, "\tError: Could not conduct fsync!!!\n");

View File

@ -24,7 +24,7 @@
#ifdef HAVE_LINUX_LIMITS_H #ifdef HAVE_LINUX_LIMITS_H
#include <linux/limits.h> #include <linux/limits.h>
#endif #endif
#ifndef _WIN32 #ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h> #include <sys/ioctl.h>
#endif #endif
#include <libgen.h> #include <libgen.h>

View File

@ -15,8 +15,10 @@
#include <fcntl.h> #include <fcntl.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#ifndef _WIN32 #ifdef HAVE_SYS_STAT_H
#include <sys/stat.h> #include <sys/stat.h>
#endif
#ifdef HAVE_SYS_MOUNT_H
#include <sys/mount.h> #include <sys/mount.h>
#endif #endif
#include <time.h> #include <time.h>

View File

@ -17,7 +17,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <unistd.h> #include <unistd.h>
#include <sys/stat.h> #include <sys/stat.h>
#ifndef _WIN32 #ifdef HAVE_SYS_MOUNT_H
#include <sys/mount.h> #include <sys/mount.h>
#endif #endif
#include <time.h> #include <time.h>

View File

@ -26,7 +26,7 @@
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
#ifndef _WIN32 #ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h> #include <sys/ioctl.h>
#endif #endif
#include <sys/stat.h> #include <sys/stat.h>
@ -39,16 +39,19 @@
#include <linux/falloc.h> #include <linux/falloc.h>
#endif #endif
#ifdef __linux__
#ifndef BLKDISCARD #ifndef BLKDISCARD
#define BLKDISCARD _IO(0x12,119) #define BLKDISCARD _IO(0x12,119)
#endif #endif
#ifndef BLKSECDISCARD #ifndef BLKSECDISCARD
#define BLKSECDISCARD _IO(0x12,125) #define BLKSECDISCARD _IO(0x12,125)
#endif #endif
#endif
static int trim_device(int i) static int trim_device(int i)
{ {
#ifndef _WIN32 #if defined(FALLOC_FL_PUNCH_HOLE) || defined(BLKDISCARD) || \
defined(BLKSECDISCARD)
unsigned long long range[2]; unsigned long long range[2];
struct stat *stat_buf; struct stat *stat_buf;
struct device_info *dev = c.devices + i; struct device_info *dev = c.devices + i;