linux-sysprog · intermediate · ~15 min
Create and write a file through descriptors.
Implement int posix_write(const char *path, const char *data, int n) creating/truncating path and writing n bytes with open/write/close. Return the count written, or -1 on failure.
#include <fcntl.h>
#include <unistd.h>
int posix_write(const char *path, const char *data, int n) {
/* TODO */
return -1;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.