+static int rdbLoadType(FILE *fp) {
+ unsigned char type;
+ if (fread(&type,1,1,fp) == 0) return -1;
+ return type;
+}
+
+static uint32_t rdbLoadLen(FILE *fp, int rdbver) {
+ unsigned char buf[2];
+ uint32_t len;
+
+ if (rdbver == 0) {
+ if (fread(&len,4,1,fp) == 0) return REDIS_RDB_LENERR;
+ return ntohl(len);
+ } else {
+ if (fread(buf,1,1,fp) == 0) return REDIS_RDB_LENERR;
+ if ((buf[0]&0xC0) == REDIS_RDB_6BITLEN) {
+ /* Read a 6 bit len */
+ return buf[0];
+ } else if ((buf[0]&0xC0) == REDIS_RDB_14BITLEN) {
+ /* Read a 14 bit len */
+ if (fread(buf+1,1,1,fp) == 0) return REDIS_RDB_LENERR;
+ return ((buf[0]&0x3F)<<8)|buf[1];
+ } else {
+ /* Read a 32 bit len */
+ if (fread(&len,4,1,fp) == 0) return REDIS_RDB_LENERR;
+ return ntohl(len);
+ }
+ }
+}
+
+static robj *rdbLoadStringObject(FILE*fp,int rdbver) {
+ uint32_t len = rdbLoadLen(fp,rdbver);
+ sds val;
+
+ if (len == REDIS_RDB_LENERR) return NULL;
+ val = sdsnewlen(NULL,len);
+ if (len && fread(val,len,1,fp) == 0) {
+ sdsfree(val);
+ return NULL;
+ }
+ return tryObjectSharing(createObject(REDIS_STRING,val));
+}
+
+static int rdbLoad(char *filename) {