cal: Enable Linux code only on Linux

This commit is contained in:
Pali Rohár committed 2014-11-26 16:33:21 +01:00
1 parent ef1960cc32
commit 448365b588
1 file changed
+21 -4
+21 -4
View File
@@ -33,8 +33,10 @@
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#ifdef __linux__
#include <linux/fs.h> #include <linux/fs.h>
#include <mtd/mtd-user.h> #include <mtd/mtd-user.h>
#endif
#include "cal.h" #include "cal.h"
@@ -68,7 +70,9 @@ int cal_init_file(const char * file, struct cal ** cal_out) {
void * mem = NULL; void * mem = NULL;
struct cal * cal = NULL; struct cal * cal = NULL;
struct stat st; struct stat st;
#ifdef __linux__
mtd_info_t mtd_info; mtd_info_t mtd_info;
#endif
if ( stat(file, &st) != 0 ) if ( stat(file, &st) != 0 )
return -1; return -1;
@@ -81,17 +85,30 @@ int cal_init_file(const char * file, struct cal ** cal_out) {
if ( S_ISREG(st.st_mode) ) if ( S_ISREG(st.st_mode) )
size = st.st_size; size = st.st_size;
else if ( S_ISBLK(st.st_mode) ) { else if ( S_ISBLK(st.st_mode) ) {
#ifdef __linux__
if ( ioctl(fd, BLKGETSIZE64, &blksize) != 0 ) if ( ioctl(fd, BLKGETSIZE64, &blksize) != 0 )
goto err; goto err;
#else
blksize = lseek(fd, 0, SEEK_END);
if ( blksize == (off_t)-1 )
goto err;
lseek(fd, 0, SEEK_SET);
#endif
if ( blksize > SSIZE_MAX ) if ( blksize > SSIZE_MAX )
goto err; goto err;
size = blksize; size = blksize;
} else if ( S_ISCHR(st.st_mode) && major(st.st_rdev) == 90 ) {
if ( ioctl(fd, MEMGETINFO, &mtd_info) != 0 )
goto err;
size = mtd_info.size;
} else { } else {
#ifdef __linux__
if ( S_ISCHR(st.st_mode) && major(st.st_rdev) == 90 ) {
if ( ioctl(fd, MEMGETINFO, &mtd_info) != 0 )
goto err;
size = mtd_info.size;
} else {
goto err;
}
#else
goto err; goto err;
#endif
} }
if ( size == 0 || size > MAX_SIZE ) if ( size == 0 || size > MAX_SIZE )