#include <stdio.h>Include dependency graph for vbyte2.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.
Functions | |
| unsigned int | vbyte_read (FILE *fp, unsigned long int *n) |
| unsigned int | vbyte_write (FILE *fp, unsigned long int n) |
| unsigned int | vbyte_scan (FILE *fp) |
| unsigned int | vbyte_len (unsigned long int n) |
| unsigned int vbyte_len | ( | unsigned long int | n | ) |
| unsigned int vbyte_read | ( | FILE * | fp, | |
| unsigned long int * | n | |||
| ) |
Definition at line 19 of file vbyte2.c.
Referenced by get_list_at(), and get_next_lo_info().
00019 { 00020 unsigned int ret = 1; 00021 unsigned int count = 0; 00022 uint8_t byte; 00023 00024 *n = 0; 00025 while (fread(&byte, 1, 1, fp)) { 00026 if (byte & 0x80) { 00027 /* For each time we get a group of 7 bits, need to left-shift the 00028 latest group by an additional 7 places, since the groups were 00029 effectively stored in reverse order.*/ 00030 *n |= ((byte & 0x7f) << count); 00031 ret++; 00032 count += 7; 00033 } else if (ret > (sizeof(*n))) { 00034 if (ret == (sizeof(*n) + 1) 00035 && (byte < (1 << (sizeof(*n) + 1)))) { 00036 /* its a large, but valid number */ 00037 *n |= byte << count; 00038 return ret; 00039 } else { 00040 /* we've overflowed */ 00041 00042 /* pretend we detected it as it happened */ 00043 fseek(fp, - (int) (ret - (sizeof(*n) + 1)), SEEK_CUR); 00044 errno = EOVERFLOW; 00045 return 0; 00046 } 00047 } else { 00048 *n |= byte << count; 00049 return ret; 00050 } 00051 } 00052 00053 /* got a read error */ 00054 return 0; 00055 }
Here is the caller graph for this function:

| unsigned int vbyte_scan | ( | FILE * | fp | ) |
Definition at line 79 of file vbyte2.c.
00079 { 00080 unsigned int ret = 1; 00081 uint8_t byte; 00082 00083 while (fread(&byte, 1, 1, fp)) { 00084 if (byte & 0x80) { 00085 /* For each time we get a group of 7 bits, need to left-shift the 00086 latest group by an additional 7 places, since the groups were 00087 effectively stored in reverse order.*/ 00088 ret++; 00089 } else if (ret > sizeof(unsigned long int)) { 00090 if (ret == (sizeof(unsigned long int) + 1) 00091 && (byte < (1 << (sizeof(unsigned long int) + 1)))) { 00092 /* its a large, but valid number */ 00093 return ret; 00094 } else { 00095 /* we've overflowed */ 00096 00097 /* pretend we detected it as it happened */ 00098 fseek(fp, - (int) (ret - (sizeof(unsigned long int) + 1)), SEEK_CUR); 00099 errno = EOVERFLOW; 00100 return 0; 00101 } 00102 } else { 00103 return ret; 00104 } 00105 } 00106 00107 /* got a read error */ 00108 return 0; 00109 }
| unsigned int vbyte_write | ( | FILE * | fp, | |
| unsigned long int | n | |||
| ) |
Definition at line 57 of file vbyte2.c.
00057 { 00058 unsigned int ret = 1; 00059 uint8_t byte; 00060 00061 while (n >= 128) { 00062 /* write the bytes out least significant to most significant */ 00063 byte = (uint8_t) (n & 0x7f) | 0x80; 00064 if (!fwrite(&byte, 1, 1, fp)) { 00065 return 0; 00066 } 00067 n >>= 7; 00068 ret++; 00069 } 00070 00071 byte = (uint8_t) n; 00072 if (!fwrite(&byte, 1, 1, fp)) { 00073 return 0; 00074 } 00075 00076 return ret; 00077 }
1.5.2