aboutsummaryrefslogtreecommitdiff
path: root/llong.c
diff options
context:
space:
mode:
Diffstat (limited to 'llong.c')
-rw-r--r--llong.c42
1 files changed, 33 insertions, 9 deletions
diff --git a/llong.c b/llong.c
index 95383f7..2369b68 100644
--- a/llong.c
+++ b/llong.c
@@ -17,7 +17,6 @@
#include "sysincludes.h"
#include "stream.h"
-#include "fsP.h"
#include "llong.h"
#include "mtools.h"
@@ -36,20 +35,46 @@ int fileTooBig(mt_off_t off) {
return (off & ~max_off_t_32) != 0;
}
+/* truncMtOffToOff */
off_t truncBytes32(mt_off_t off)
{
+ if (fileTooBig(off)) {
+ fprintf(stderr, "Internal error, offset too big\n");
+ exit(1);
+ }
+ return (off_t) off;
+}
+
+uint32_t truncMtOffTo32u(mt_off_t off)
+{
if (fileTooBig(off)) {
fprintf(stderr, "Internal error, offset too big\n");
exit(1);
}
- return (off_t) off;
+ return (uint32_t) off;
+}
+
+uint32_t truncSizeTo32u(size_t siz)
+{
+ if (siz > UINT32_MAX) {
+ fprintf(stderr, "Internal error, size too big\n");
+ exit(1);
+ }
+ return (uint32_t) siz;
}
-mt_off_t sectorsToBytes(Stream_t *Stream, off_t off)
+#if SIZEOF_MT_OFF_T == 4
+mt_off_t to_mt_off_t(uint32_t off)
{
- DeclareThis(Fs_t);
- return (mt_off_t) off << This->sectorShift;
+ if(off > UINT32_MAX >> 1) {
+ fprintf(stderr, "File size/pos %d too big for this platform\n",
+ off);
+ exit(1);
+ }
+ return (mt_off_t) off;
}
+#endif
+
#if defined HAVE_LLSEEK
# ifndef HAVE_LLSEEK_PROTOTYPE
@@ -63,7 +88,6 @@ extern long long lseek64 (int fd, long long offset, int origin);
# endif
#endif
-
int mt_lseek(int fd, mt_off_t where, int whence)
{
#if defined HAVE_LSEEK64
@@ -75,7 +99,7 @@ int mt_lseek(int fd, mt_off_t where, int whence)
if(llseek(fd, where, whence) >= 0)
return 0;
else
- return -1;
+ return -1;
#else
if (lseek(fd, (off_t) where, whence) >= 0)
return 0;
@@ -84,12 +108,12 @@ int mt_lseek(int fd, mt_off_t where, int whence)
#endif
}
-unsigned int log_2(int size)
+unsigned int log_2(unsigned int size)
{
unsigned int i;
for(i=0; i<24; i++) {
- if(1 << i == size)
+ if(1u << i == size)
return i;
}
return 24;