Guest User

Untitled

a guest
May 24th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #define UID_PACKING_LEN 8
  2.  
  3. int header_insert_special_int(char* where, size_t size, int32_t val)
  4. {
  5. int err = 0;
  6. if (val < 0 || size < sizeof(val))
  7. {
  8. err++;
  9. }
  10. else
  11. {
  12. memset(where, 0, size);
  13. *(int32_t *)(where+size-sizeof(val)) = htonl(val);
  14. *where |= 0x80;
  15. }
  16. return err;
  17. }
  18.  
  19. int header_extract_special_int(char* where, int len)
  20. {
  21. int32_t val = -1;
  22. if ( (len>=sizeof(val)) && (where[0] & 0x80))
  23. {
  24. val = *(int32_t *)(where + len - sizeof(val));
  25. val = ntohl(val);
  26. }
  27. return val;
  28. }
  29.  
  30.  
  31. void header_set_uid_bigsafe(char* buf, int32_t uid)
  32. {
  33. int toobig = 07777777;
  34.  
  35. /* Tests if bitpacking is needed */
  36. if(uid > toobig)
  37. {
  38. header_insert_special_int(buf,UID_PACKING_LEN,uid);
  39. }
  40. else
  41. {
  42. /* Do normal formatting as octal */
  43. }
  44. }
  45.  
  46. void header_parse_uid_bigsafe(char* uidstring, uid_t* uid)
  47. {
  48.  
  49. /* Tests if bitpacking was used */
  50. if(uidstring[0] == '\0')
  51. {
  52. *uid = header_extract_special_int(uidstring, UID_PACKING_LEN);
  53. }
  54. else
  55. {
  56. /* Do normal parsing from octal */
  57. }
  58. }
Add Comment
Please, Sign In to add comment