gd_alter_protection(3)

πŸ’– gd_alter_protection β€” bestie, let's talk protection levels πŸ’–

okay so this one is from the GETDATA manual, section 3, and it's literally about changing how protected a Dirfile fragment is. slay. let's get into it πŸŽ€


✨ NAME ✨

gd_alter_protection β€” modify the protection level of a Dirfile fragment πŸ’…


✨ SYNOPSIS ✨

#include <getdata.h>

int gd_alter_protection(DIRFILE *dirfile, int protection_level, int
       fragment_index);

✨ DESCRIPTION ✨

so the way this works is: gd_alter_protection() sets the advisory protection level of the format specification fragment given by fragment_index to protection_level, inside the dirfile(5) database that dirfile points at. that's the whole vibe. πŸ¦‹

and the protection_level argument? it should be one of these four, no cap:

  • GD_PROTECT_NONE β€” says the fragment should not be protected at all. zero protection. free range. πŸ™ˆ
  • GD_PROTECT_FORMAT β€” says the fragment's metadata should be protected. ✨
  • GD_PROTECT_DATA β€” says the fragment's binary data should be protected. πŸ“
  • GD_PROTECT_ALL β€” says both the fragment's metadata AND its binary data should be protected. lowkey important: this symbol is equivalent to the bitwise or of GD_PROTECT_FORMAT and GD_PROTECT_DATA. iykyk πŸ’œ

now, fragment_index can just be a normal valid fragment index, sure β€” but it can also be the special value GD_ALL_FRAGMENTS, which means change the protection level of every single fragment in the database. all of them. the whole squad. πŸ‘‘


✨ RETURN VALUE ✨

when it works? gd_alter_protection() returns zero. periodt. πŸ’š

when it doesn't work? it returns a negative-valued error code. here's the menu of possible error codes, bestie:

  • GD_E_ACCMODE β€” the specified dirfile was opened read-only. 😭
  • GD_E_ARGUMENT β€” the protection_level you supplied was invalid. πŸ’€
  • GD_E_BAD_DIRFILE β€” the dirfile you supplied was invalid. πŸ™ˆ
  • GD_E_BAD_INDEX β€” the index you supplied was out of range. 😬
  • GD_E_BAD_PROTECTION β€” the protection level you supplied was invalid. 🫠
also!! the error code gets stored in the DIRFILE object too, so you can grab it after this function returns by calling gd_error(3). and if you want an actual descriptive error string? call gd_error_string(3). two icons. 🫢

✨ NOTES ✨

not to be dramatic but: this is the only GetData function which ignores the (existing) protection level of a format specification fragment. the only one. main character energy fr fr πŸ‘‘


✨ HISTORY ✨

  • the function dirfile_protect() appeared in GetData-0.5.0. throwback. ⭐
  • in GetData-0.7.0, this function was renamed to gd_alter_protection(). glow up. πŸ¦‹
  • in GetData-0.10.0, the error return from this function changed from -1 to a negative-valued error code. growth. 🌸

✨ SEE ALSO ✨

gd_error(3), gd_error_string(3), gd_protection(3), gd_open(3)

go read those too bestie, they're all part of the same friend group πŸ’–


okay that's the whole page!! this was Version 0.10.0, dated 25 December 2016, and honestly? iconic for it. bye bestie, go protect your fragments πŸ’…βœ¨πŸŽ€