## -*- octave -*-
[id, msg] = tmpfile ();
 if (id < 0)
   __printf_assert__ ("tmpfile failed: %s\n", msg);
 else
   unwind_protect
     ## FIXME: better test for endianness?
     big_endian = (bitunpack (uint16 (1))(1) == 0);
     fwrite (id, "abcdefg");
     frewind (id);
     [data, count] = fread (id);
     assert (data, [97; 98; 99; 100; 101; 102; 103]);
     assert (count, 7);
     frewind (id);
     [data, count] = fread (id, 'int16');
     expected = [25185; 25699; 26213];
     if (big_endian)
       expected = double (swapbytes (int16 (expected)));
     endif
     assert (data, expected);
     assert (count, 3);
     frewind (id);
     [data, count] = fread (id, [10, 2], 'int16');
     assert (data, expected);
     assert (count, 3);
     frewind (id);
     [data, count] = fread (id, [2, 10], 'int16');
     expected = [25185, 26213; 25699, 0];
     if (big_endian)
       expected = double (swapbytes (int16 (expected)));
     endif
     assert (data, expected);
     assert (count, 3);
   unwind_protect_cleanup
     fclose (id);
   end_unwind_protect
 endif
