From 448365b5889747ee04ac8d8628b730aa477ca89e Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Wed, 26 Nov 2014 16:33:21 +0100 Subject: cal: Enable Linux code only on Linux --- src/cal.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'src/cal.c') diff --git a/src/cal.c b/src/cal.c index 3a46abd..99de241 100644 --- a/src/cal.c +++ b/src/cal.c @@ -33,8 +33,10 @@ #include #include +#ifdef __linux__ #include #include +#endif #include "cal.h" @@ -68,7 +70,9 @@ int cal_init_file(const char * file, struct cal ** cal_out) { void * mem = NULL; struct cal * cal = NULL; struct stat st; +#ifdef __linux__ mtd_info_t mtd_info; +#endif if ( stat(file, &st) != 0 ) return -1; @@ -81,17 +85,30 @@ int cal_init_file(const char * file, struct cal ** cal_out) { if ( S_ISREG(st.st_mode) ) size = st.st_size; else if ( S_ISBLK(st.st_mode) ) { +#ifdef __linux__ if ( ioctl(fd, BLKGETSIZE64, &blksize) != 0 ) 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 ) goto err; 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 { +#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; +#endif } if ( size == 0 || size > MAX_SIZE ) -- cgit v1.2.3