Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define UID_PACKING_LEN 8
- int header_insert_special_int(char* where, size_t size, int32_t val)
- {
- int err = 0;
- if (val < 0 || size < sizeof(val))
- {
- err++;
- }
- else
- {
- memset(where, 0, size);
- *(int32_t *)(where+size-sizeof(val)) = htonl(val);
- *where |= 0x80;
- }
- return err;
- }
- int header_extract_special_int(char* where, int len)
- {
- int32_t val = -1;
- if ( (len>=sizeof(val)) && (where[0] & 0x80))
- {
- val = *(int32_t *)(where + len - sizeof(val));
- val = ntohl(val);
- }
- return val;
- }
- void header_set_uid_bigsafe(char* buf, int32_t uid)
- {
- int toobig = 07777777;
- /* Tests if bitpacking is needed */
- if(uid > toobig)
- {
- header_insert_special_int(buf,UID_PACKING_LEN,uid);
- }
- else
- {
- /* Do normal formatting as octal */
- }
- }
- void header_parse_uid_bigsafe(char* uidstring, uid_t* uid)
- {
- /* Tests if bitpacking was used */
- if(uidstring[0] == '\0')
- {
- *uid = header_extract_special_int(uidstring, UID_PACKING_LEN);
- }
- else
- {
- /* Do normal parsing from octal */
- }
- }
Add Comment
Please, Sign In to add comment