boolean locked = fptr.lock();
try {
fptr = io.getOpenFileChecked();
fptr.checkWritable(context);
n = fptr.fwrite(context, str, nosync);
if (n == -1) throw runtime.newErrnoFromErrno(fptr.errno(), fptr.getPath());
} finally {
if (locked) fptr.unlock();
}