1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
/*
* $Id: binary.h,v 1.7 2005/08/26 06:40:32 jason Exp $
*/
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdarg.h>
#include <string.h>
#include <limits.h>
#include <assert.h>
#include <math.h>
#ifdef __CYGWIN__
#include <io.h>
#endif
#if defined _WIN32 || defined __TURBOC__ || defined __ZTC__ || defined _MSC_VER
# include <io.h>
# include <fcntl.h>
# include <time.h>
# include <sys/types.h>
# include <sys/stat.h>
#elif defined __unix__ || defined __linux__
# include <fcntl.h>
# include <unistd.h>
# include <sys/time.h>
# include <sys/ioctl.h>
# include <sys/types.h>
# include <sys/stat.h>
#else
/* .... hier Includes fr neues Betriebssystem einfgen (mit vorgestellten: #elif defined) */
# include <fcntl.h>
# include <unistd.h>
# include <sys/ioctl.h>
# include <sys/stat.h>
#endif
#ifndef O_BINARY
# ifdef _O_BINARY
# define O_BINARY _O_BINARY
# else
# define O_BINARY 0
# endif
#endif
#if defined __BORLANDC__ || defined _WIN32
# define FILENO(__fp) _fileno ((__fp))
#elif defined __CYGWIN__ || defined __TURBOC__ || defined __unix__ || defined __EMX__ || defined _MSC_VER
# define FILENO(__fp) fileno ((__fp))
#else
# define FILENO(__fp) fileno ((__fp))
#endif
/*
* If we have access to a file via file name, we can open the file with an
* additional "b" or a O_BINARY within the (f)open function to get a
* transparent untranslated data stream which is necessary for audio bitstream
* data and also for PCM data. If we are working with
* stdin/stdout/FILENO_STDIN/FILENO_STDOUT we can't open the file with this
* attributes, because the files are already open. So we need a non
* standardized sequence to switch to this mode (not necessary for Unix).
* Mostly the sequency is the same for incoming and outgoing streams, but only
* mostly so we need one for IN and one for OUT.
* Macros are called with the file pointer and you get back the untransalted file
* pointer which can be equal or different from the original.
*/
#if defined __EMX__
# define SETBINARY_FD(__fp) (_fsetmode ( (__fp), "b" ))
# define SETBINARY_IN(__fp) (_fsetmode ( (__fp), "b" ))
# define SETBINARY_OUT(__fp) (_fsetmode ( (__fp), "b" ))
#elif defined __TURBOC__ || defined __BORLANDC__
# define SETBINARY_FD(__fp) (setmode ( (__fp), O_BINARY ))
# define SETBINARY_IN(__fp) (setmode ( FILENO ((__fp)), O_BINARY ))
# define SETBINARY_OUT(__fp) (setmode ( FILENO ((__fp)), O_BINARY ))
#elif defined __CYGWIN__
# define SETBINARY_FD(__fp) (setmode ( (__fp), _O_BINARY ))
# define SETBINARY_IN(__fp) (setmode ( FILENO ((__fp)), _O_BINARY ))
# define SETBINARY_OUT(__fp) (setmode ( FILENO ((__fp)), _O_BINARY ))
#elif defined _WIN32
# define SETBINARY_FD(__fp) (_setmode ( (__fp), _O_BINARY ))
# define SETBINARY_IN(__fp) (_setmode ( FILENO ((__fp)), _O_BINARY ))
# define SETBINARY_OUT(__fp) (_setmode ( FILENO ((__fp)), _O_BINARY ))
#elif defined _MSC_VER
# define SETBINARY_FD(__fp) (setmode ( (__fp), O_BINARY ))
# define SETBINARY_IN(__fp) (setmode ( FILENO ((__fp)), O_BINARY ))
# define SETBINARY_OUT(__fp) (setmode ( FILENO ((__fp)), O_BINARY ))
#elif defined __unix__
# define SETBINARY_FD(__fp) (void)(__fp)
# define SETBINARY_IN(__fp) (void)(__fp)
# define SETBINARY_OUT(__fp) (void)(__fp)
#elif 0
# define SETBINARY_FD(__fp) (void)(__fp)
# define SETBINARY_IN(__fp) (freopen ( NULL, "rb", (__fp) ))
# define SETBINARY_OUT(__fp) (freopen ( NULL, "wb", (__fp) ))
#else
# define SETBINARY_FD(__fp) (void)(__fp)
# define SETBINARY_IN(__fp) (void)(__fp)
# define SETBINARY_OUT(__fp) (void)(__fp)
#endif
|