| 281 | } |
| 282 | |
| 283 | __wasi_errno_t __wasi_fd_close(__wasi_fd_t fd) { |
| 284 | std::shared_ptr<DataFile> closee; |
| 285 | { |
| 286 | // Do not hold the file table lock while performing the close. |
| 287 | auto fileTable = wasmFS.getFileTable().locked(); |
| 288 | auto entry = fileTable.getEntry(fd); |
| 289 | if (!entry) { |
| 290 | return __WASI_ERRNO_BADF; |
| 291 | } |
| 292 | closee = fileTable.setEntry(fd, nullptr); |
| 293 | } |
| 294 | if (closee) { |
| 295 | // Translate to WASI standard of positive return codes. |
| 296 | int ret = -closee->locked().close(); |
| 297 | assert(ret >= 0); |
| 298 | return ret; |
| 299 | } |
| 300 | return __WASI_ERRNO_SUCCESS; |
| 301 | } |
| 302 | |
| 303 | __wasi_errno_t __wasi_fd_sync(__wasi_fd_t fd) { |
| 304 | auto openFile = wasmFS.getFileTable().locked().getEntry(fd); |