Check truncate and append flags.
[cascardo/kernel/samples/char2/.git] / hellochar.c
index ee09b1e..71605f6 100644 (file)
@@ -37,6 +37,12 @@ struct hello_buffer *hello;
 
 static int hello_open(struct inode *ino, struct file *fp)
 {
+       if (fp->f_flags & O_TRUNC) {
+               memset(hello->buffer, 0, MAXLEN);
+               hello->len = 0;
+       }
+       if (fp->f_flags & O_APPEND)
+               fp->f_pos = hello->len;
        return 0;
 }