Check for magic number in file.
check magic number in file
,
- Parameters
-
is | input stream to read from |
cmagic | 4-byte character sequence representing magic number (most restrictive: pass a const pointer to a const char) is pointer to character array of size sizeof(int) |
fortranmode | use Fortran binary I/O if true |
- Returns
- The return value tells whether the file matches
The function may have the following return values
- magic_match The file has the requested magic number and the bytesex of the data matches that of the system
- magic_swap The file has the requested magic number but byte swapping is required for input data
- magic_nomatch The requested magic number was not found in the file
- Examples:
- tests/fortraniotest.cc.
Definition at line 112 of file ioswap.cc.
References tfxx::ioswap::IOUnion< T >::bytes, magic(), magic_match, magic_nomatch, magic_swap, swap(), and tfxx::ioswap::IOUnion< T >::value.
Referenced by tfxx::fortranio::FortranBinInput::match_magic(), and read_data().
116 IOUnion<int> req_magic, in_magic;
118 req_magic.value=
magic(cmagic);
120 if (fortranmode) is.read(in_magic.bytes,
sizeof(
int));
122 is.read(in_magic.bytes,
sizeof(
int));
123 if (in_magic.value == req_magic.value)
125 else if (in_magic.value ==
swap(req_magic.value))
128 if (fortranmode) is.read(in_magic.bytes,
sizeof(
int));
int magic(const char *const cmagic)
Create a magic number from a character string. ,If represents the input character sequence cmagic an...
T swap(const T &value)
How to swap any generic type.
The bytesex of the file matches this machine.
The bytesex of the file must be swapped to match this machine.
Emagic_type
Define bytesex indicator for magic number test.
The magic number does match the file.