Skip to content

Commit

Permalink
Merge pull request #7 from pmp-p/patch-2
Browse files Browse the repository at this point in the history
maybe fix fd_seek #6
  • Loading branch information
konsumer authored Nov 14, 2024
2 parents fc8838f + 4b892dc commit c6fb1c6
Showing 1 changed file with 22 additions and 20 deletions.
42 changes: 22 additions & 20 deletions docs/easywasi.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,34 +384,36 @@ export class WasiPreview1 {
if (!fileDesc) return defs.ERRNO_BADF
if (fileDesc.type === 'stdio') return defs.ERRNO_SPIPE

var stats = null
let newPosition = 0
let noffset = Number(offset)

try {
const stats = this.fs.statSync(fileDesc.handle.path)
const size = stats.size
let newPosition
stats = this.fs.statSync(fileDesc.handle.path)
} catch (e) {
return defs.ERRNO_IO
}

switch (whence) {
case defs.WHENCE_SET:
newPosition = offset
switch (whence) {
case defs.WHENCE_SET:
newPosition = noffset
break
case defs.WHENCE_CUR:
newPosition = fileDesc.handle.position + offset
case defs.WHENCE_CUR:
newPosition = Number(fileDesc.handle.position) + noffset
break
case defs.WHENCE_END:
newPosition = size + offset
case defs.WHENCE_END:
newPosition = Number(stats.size) + noffset
break
default:
default:
return defs.ERRNO_INVAL
}
}

// Update position
fileDesc.handle.position = newPosition
// Update position
fileDesc.handle.position = newPosition

const view = new DataView(this.wasm.memory.buffer)
view.setBigUint64(newOffsetPtr, BigInt(newPosition), true)
return defs.ERRNO_SUCCESS
} catch (e) {
return defs.ERRNO_IO
}
const view = new DataView(this.wasm.memory.buffer)
view.setBigUint64(newOffsetPtr, BigInt(newPosition), true)
return defs.ERRNO_SUCCESS
}

fd_write (fd, iovs, iovsLen, nwrittenPtr) {
Expand Down

0 comments on commit c6fb1c6

Please sign in to comment.