gd_alter_endianness(3)

πŸ“¦
version 0.11.0 Β· 3 versions
, in debian bookworm, debian trixie, fedora 43, fedora 44, ubuntu jammy, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ NAME ✨

gd_alter_endianness β€” bestie, we're flipping the byte sex of fields in a Dirfile πŸ’…


🌸 SYNOPSIS 🌸

#include <getdata.h>

int gd_alter_endianness(DIRFILE *dirfile, unsigned long byte_sex, int
       fragment_index, int recode);

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so listen. gd_alter_endianness() sets the byte sex of the format specification fragment given by fragment_index to byte_sex, inside the dirfile(5) database that dirfile is pointing at. 🫢

and like, what even IS the byte sex of a fragment? it's the endianness of the data stored in binary files associated with RAW fields defined in that fragment. that's it, that's the whole vibe. and if a fragment has no RAW fields in it? then its byte sex is literally ignored. not relevant, not invited to the party. πŸ™ˆ

so byte_sex should be one of these, bestie:

  • 0 (zero) β€” indicating that the byte sex should be the native endianness of the host, whichever that may be.
  • GD_BIG_ENDIAN β€” indicating that the byte sex should be big endian.
  • GD_LITTLE_ENDIAN β€” indicating that the byte sex should be little endian.
  • (GD_BIG_ENDIAN | GD_LITTLE_ENDIAN) β€” indicating that the byte sex should be the opposite of the native endianness of the host, whichever that may be.

and ALSO, any of those can be bitwise or'd with GD_ARM_ENDIAN or GD_NOT_ARM_ENDIAN, which says the floating point data are stored in the ARM middle-endian format. iykyk πŸ’€

now, fragment_index can just be a valid fragment index, but it can ALSO be the special value GD_ALL_FRAGMENTS β€” which means change the byte sex of all the fragments in the database. everything. all of it. periodt. πŸ‘‘

and if recode is non-zero?? this call will byte swap the binary data of the affected RAW fields, to account for the change in byte sex. but if the encoding of the fragment is endianness insensitive, or the data type is only one byte in size, no change is made. nothing to do, nothing happens. also, the I/O pointer of all affected RAW fields gets reset to the beginning-of-frame. πŸŽ€

if recode is zero, the affected binary files are left completely untouched. hands off. πŸ™…


πŸ’– RETURN VALUE πŸ’–

upon successful completion, gd_alter_endianness() returns zero. on error, it returns a negative-valued error code. possible error codes are:

  • GD_E_ACCMODE β€” the specified dirfile was opened read-only.
  • GD_E_ALLOC β€” the library was unable to allocate memory. 😭
  • GD_E_ARGUMENT β€” the supplied byte_sex was invalid.
  • GD_E_BAD_DIRFILE β€” the supplied dirfile was invalid.
  • GD_E_BAD_INDEX β€” the supplied index was out of range.
  • GD_E_IO β€” an I/O error occurred while attempting to byte swap a binary file.
  • GD_E_PROTECTED β€” the metadata of the indicated format specification fragment was protected from change, or the binary data of the fragment was protected from change and binary file byte swapping was requested.
  • GD_E_UNCLEAN_DB β€” an error occurred while moving the byte-swapped file into place. as a result, the database may be in an unclean state. see the NOTES section below for recovery instructions. in this case, the dirfile will be flagged as invalid, to prevent further database corruption. it should be immediately closed. 🚨
  • GD_E_UNKNOWN_ENCODING β€” the encoding scheme of the fragment is unknown.
  • GD_E_UNSUPPORTED β€” the encoding scheme of the fragment does not support binary file byte swapping.

the error code is also stored in the DIRFILE object, and you can get it back after this function returns by calling gd_error(3). and if you want a descriptive error string for the error? call gd_error_string(3). easy. πŸ’…


🧚 NOTES 🧚

a binary file byte swap happens out-of-place. so as a result, there has to be sufficient space on the filesystem for the binary files of all RAW fields in the fragment β€” both before and after translation. and if all fragments get updated by specifying GD_ALL_FRAGMENTS, the byte swapping occurs one fragment at a time.

an error code of GD_E_UNCLEAN_DB means a system error occurred while moving the byte-swapped binary data into place, or when deleting the old data. if that happens, the database may be left in an unclean state. 😭 the caller should check the filesystem directly to ascertain the state of the dirfile data before continuing. for recovery instructions, see the file /usr/share/doc/getdata/unclean_database_recovery.txt.

fr fr, don't just keep going after a GD_E_UNCLEAN_DB. go look at the filesystem first. your data will thank you. 🫢

🌈 HISTORY 🌈

the function dirfile_alter_endianness() appeared in GetData-0.5.0.

in GetData-0.7.0, this function was renamed to gd_alter_endianness(). the GD_E_ARM_ENDIAN and GD_NOT_ARM_ENDIAN flags also appeared in this version.

in GetData-0.10.0, the error return from this function changed from -1 to a negative-valued error code. glow-up honestly ✨


πŸ‘‘ SEE ALSO πŸ‘‘

gd_open(3), gd_error(3), gd_error_string(3), gd_endianness(3), dirfile(5), dirfile-format(5)


and that's the whole page, bestie!! this was Version 0.10.0, dated 25 December 2016, from the GETDATA manual section, and honestly? iconic. go forth and byte-swap responsibly. πŸ’–πŸŽ€πŸ¦‹πŸŒΈπŸ’