static int esp8266_FileSize(sqlite3_file *id, sqlite3_int64 *size) { esp8266_file *file = (esp8266_file*) id; *size = 0LL | vfs_size( file->fd ); dbg_printf("esp8266_FileSize: %s %u[%lld]\n", file->name, vfs_size(file->fd), *size); return SQLITE_OK; }
static void httpd_handle_vfs_send_header (void) { PASTE_RESET (); PASTE_P (httpd_header_200); vfs_size_t len = vfs_size (STATE->u.vfs.fd); if (len > 0) { /* send content-length header */ PASTE_P (httpd_header_length); PASTE_LEN (len); } /* Check whether the file is gzip compressed. */ unsigned char buf[READ_AHEAD_LEN]; #ifndef VFS_TEENSY if (VFS_HAVE_FUNC (STATE->u.vfs.fd, fseek)) { #endif /* not VFS_TEENSY, inlined files are always gzip'd */ /* Rewind stream first, might be a rexmit */ vfs_rewind (STATE->u.vfs.fd); vfs_read (STATE->u.vfs.fd, buf, READ_AHEAD_LEN); vfs_rewind (STATE->u.vfs.fd); #ifndef VFS_TEENSY } else goto no_gzip; if (buf[0] == 0x1f && buf[1] == 0x8b) #endif /* not VFS_TEENSY, inlined files are always gzip'd */ PASTE_P (httpd_header_gzip); #ifdef MIME_SUPPORT PASTE_PF (PSTR ("Content-Type: %S\n\n"), httpd_mimetype_detect (buf)); PASTE_SEND (); return; #endif /* MIME_SUPPORT */ #ifndef VFS_TEENSY no_gzip: #endif /* not VFS_TEENSY, inlined files are always gzip'd */ if (STATE->u.vfs.content_type == 'X') PASTE_P (httpd_header_ct_xhtml); else if (STATE->u.vfs.content_type == 'S') PASTE_P (httpd_header_ct_css); else PASTE_P (httpd_header_ct_html); PASTE_SEND (); }
int16_t parse_cmd_call(char *cmd, char *output, uint16_t len) { char filename[10]; char line[ECMD_INPUTBUF_LENGTH]; uint8_t lsize = 0; uint8_t run = 0; vfs_size_t filesize; sscanf_P(cmd, PSTR("%s"), &filename); // should check for ".es" extention! current_script.handle = vfs_open(filename); if (current_script.handle == NULL) { SCRIPTDEBUG("%s not found\n", filename); return ECMD_FINAL(1); } filesize = vfs_size(current_script.handle); SCRIPTDEBUG("start %s from %i bytes\n", filename, filesize); current_script.linenumber = 0; current_script.filepointer = 0; // open file as long it is open, we have not reached max lines and // not the end of the file as we know it while ((current_script.handle != NULL) && (run++ < ECMD_SCRIPT_MAXLINES) && (filesize > current_script.filepointer)) { lsize = readline(line); SCRIPTDEBUG("(linenr:%i, pos:%i, bufsize:%i)\n", current_script.linenumber, current_script.filepointer, lsize); SCRIPTDEBUG("exec: %s\n", line); if (lsize != 0) { ecmd_parse_command(line, output, len); } } SCRIPTDEBUG("end\n"); parse_cmd_exit(cmd, output, len); return ECMD_FINAL_OK; }
static void vfs_stream_seek(void* state, int offset, vfs_seek_t seek) { struct vfs_stream_state* st = (struct vfs_stream_state*)state; switch(seek) { case VFS_SEEK_SET: st->offset = offset > 0 ? offset : 0; break; case VFS_SEEK_CUR: if(offset < 0 && (uint)-offset > st->offset) st->offset = 0; else st->offset += offset; break; case VFS_SEEK_END: st->offset = vfs_size(st->path); break; } }