/* +------------------------------------------------------------------------------ | Function : read +------------------------------------------------------------------------------ | Description : | | Parameters : | Returns : | +------------------------------------------------------------------------------ */ int read(int fd, char *buf, int len) { int result; struct dfs_fd* d; /* get the fd */ d = fd_get(fd); if (d == RT_NULL) { rt_set_errno(-RT_ERROR); return -1; } result = dfile_raw_read(d, buf, len); if (result < 0) { rt_set_errno(result); fd_put(d); return -1; } /* release the ref-count of fd */ fd_put(d); return result; }
void __cat(const char* filename) { rt_uint32_t length; char buffer[81]; if (dfile_raw_open(&fd, filename, DFS_O_RDONLY) < 0) { rt_kprintf("Open %s failed\n", filename); return; } do { rt_memset(buffer, 0, sizeof(buffer)); length = dfile_raw_read(&fd, buffer, 81); if (length > 0) { rt_kprintf("%s", buffer); } }while (length > 0); dfile_raw_close(&fd); }