void Save_Config(const char* fn,int n) { /* 存储分页及书签配置 参数说明: fn: 当前打开文件的文件名 n: 已缓存页数 */ char tmp[64]; FONTCHARACTER fname[64]; int handle,size=0; memset(tmp,0,sizeof(tmp)); strncpy(tmp,fn,strlen(fn)-strlen(strrchr(fn,'.'))); // 取文件名部分 strcat(tmp,".cfg"); char_to_font(tmp,fname); Bfile_CreateEntry_OS(fname,1,&size); // 创建 .cfg 文件 handle=Bfile_OpenFile_OS(fname,2); if (handle<=0) return; Bfile_WriteFile_OS(handle,&n,4); // 前 4 字节,写入已缓存页数 Bfile_SeekFile_OS(handle,4); Bfile_WriteFile_OS(handle,bookmark,16); // 4*4 字节,写入书签指向的页数 Bfile_SeekFile_OS(handle,20); Bfile_WriteFile_OS(handle,bytes,n*4); // 4*n 字节,写入页面缓存 Bfile_CloseFile_OS(handle); }
int fseek(FILE *f, long offset, int whence) { if (isstdstream(f)) { IOERR(f, ERANGE); return -1; } switch (whence) { case SEEK_CUR: offset = ftell(f) + offset; break; case SEEK_END: // TODO this probably doesn't work. Wild guessing. // Speculation says we have Bfile_GetFileSize_OS offset = INT_MAX; break; case SEEK_SET: break; default: return -1; } int fileno = handle_tonative(f->fileno); // TODO can this fail? Probably. Bfile_SeekFile_OS(fileno, (int)offset); f->error = 0; return 0; }
off_t lseek(int fd, off_t offset, int whence){ if(fd>5){ int fileno = toNativeFD(toNativeFD(fd)); switch (whence) { case SEEK_CUR: offset = Bfile_TellFile_OS(fileno) + offset; break; case SEEK_END: offset = Bfile_GetFileSize_OS(fileno); break; case SEEK_SET: break; default: return -1; } // TODO can this fail? Probably. Bfile_SeekFile_OS(fileno, (int)offset); }else return -1; }