/*     Bed a menu-driven multi dataformat binary editor for Linux            */
/*     Copyright (C) 1998 Jaap Korthals Altes <jkaltes@hetnet.nl>       */
/*                                                                           */
/*     This program is free software; you can redistribute it and/or modify  */
/*     it under the terms of the GNU General Public License as published by  */
/*     the Free Software Foundation; either version 2 of the License, or     */
/*     (at your option) any later version.                                   */
/*                                                                           */
/*     This program is distributed in the hope that it will be useful,       */
/*     but WITHOUT ANY WARRANTY; without even the implied warranty of        */
/*     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         */
/*     GNU General Public License for more details.                          */
/*                                                                           */
/*     You should have received a copy of the GNU General Public License     */
/*     along with this program; if not, write to the Free Software           */
/*     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.             */
/* Fri Dec  8 22:14:27 2000                                                  */
/***
 *  v2  2000.08.23  Jim Blackson	added definiton of TRUNCATE from memory.cpp.
 */
#define NOSTAT
#ifndef OFFTYPES_H
#define OFFTYPES_H
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <features.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <limits.h>
#include <sys/mman.h>
#ifdef HAS_LSEEK64
#define MMAP mmap64
#define LSEEK lseek64
#define LPREAD pread64
#define LPWRITE pwrite64
#define OPEN open64
#define OFFTYPE __off64_t
#define STATTYPE struct stat64
#define FSTAT fstat64
#define STAT stat64
#define FTRUNCATE ftruncate64
#define TRUNCATE truncate64

#define LONGLONGOFFSET 8
#else
//#define MY_O_LARGEFILE 0
#define MMAP mmap
#define LSEEK lseek
#ifdef HAS_PREAD
#define LPREAD pread
#define LPWRITE pwrite
#endif
//#define OFFTYPE   __off_t
#define OFFTYPE   off_t
#define STATTYPE struct stat
#define FSTAT fstat
#define STAT stat
#define OPEN open
#define FTRUNCATE ftruncate
#define TRUNCATE truncate
#if SIZEOF_OFF_T>=8
#define LONGLONGOFFSET 8
#endif
#endif
#ifdef USE_WINFILE
#include <windows.h>
//#define HAS_PREAD 1
#define LPREAD mypread64
#define LPWRITE mypwrite64
#define FILEHANDLE HANDLE 
#define MY_INVALID_HANDLE_VALUE INVALID_HANDLE_VALUE
#undef OFFTYPE
#define OFFTYPE LONGLONG
#define LONGLONGOFFSET 8
#define LARGEFILES 8
extern int myftruncate(FILEHANDLE output,OFFTYPE size) ;
#define FTRUNCATEHANDLE myftruncate
#else
#define FTRUNCATEHANDLE FTRUNCATE
#define FILEHANDLE int
#define MY_INVALID_HANDLE_VALUE -1
#endif
#ifdef LARGEFILES
#define OFFPRINT "%lld"
#define OFFPRINTONLY "ll"
#define BLOCKPRINT "%lld"
#define NUMDIGETS_USED 12 /* When harddrives  reach the 1000 gigabytes limit, this should be changed */
#ifdef LLONG_MAX 
#define OFFTYPEMAX LLONG_MAX
#else
#define OFFTYPEMAX LONG_LONG_MAX
#endif
#define MAXDISCSIZE (OFFTYPE) 1023*1024*1024*1024LL
#define LARGERTYPE  long long
#ifdef ATOIBUG
/*extern long long strtolonglong(char *str) ;
#define ATOO   strtolonglong
*/
#define STRTOO strtoll
#else
/*
#ifdef HAS_ATOLL
#define ATOO   atoll
#else
#define ATOO(str)   strtoll(str,(char **)NULL,10)
#endif
*/
#define STRTOO strtoll
#endif
#else
#define OFFPRINT "%ld"
#define OFFPRINTONLY "l"
#define BLOCKPRINT "%ld"
#define NUMDIGETS_USED 12 
#define OFFTYPEMAX LONG_MAX
#define MAXDISCSIZE OFFTYPEMAX 
#define LARGERTYPE  long long
#ifdef ATOIBUG
//#define ATOO   strtoint
#define STRTOO strtol
#else
//#define ATOO   atol
#define STRTOO strtol
#endif
#endif
#define mysigsetjmp(env,sigs) sigsetjmp(env,sigs)


#define	MUNMAP 	munmap
#define BLOCKTYPE OFFTYPE

#define OFFTYPEINVALID OFFTYPEMAX
#define SEARCHFAILURE OFFTYPEINVALID
#define LREAD read
#define LWRITE write
#define LOPEN OPEN
#define	LCLOSE close
#define SIZE_T ssize_t
#ifdef __CYGWIN__
#define SIZE_TPRINT "%ld"
#else
#define SIZE_TPRINT "%d"
#endif

#ifdef  O_LARGEFILE
#define LARGEFILE_FLAG |O_LARGEFILE
#else
#define LARGEFILE_FLAG 
#endif
#endif
