#include #include #include #include void over_write_last_byte(char *path, unsigned char byte); int main(int argc, char *argv[]) { if (argc <= 2) { fprintf(stderr, "Usage: %s \n", argv[0]); return 1; } unsigned char byte = strtoul(argv[2], NULL, 0); over_write_last_byte(argv[1],byte); return 0; } // Given a file path and a byte, // modify the file so the final byte is replaced with a given value // If the file is empty do nothing // If the file can't be opened call perror and exit void over_write_last_byte(char *path, unsigned char byte) { int f = open(path, O_WRONLY); if (lseek(f, -1, SEEK_END) >= 0) { write(f, &byte, 1); } close(f); }