tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: [PATCH] rfc: write() shifts offset if number of bytes to write is zero

On Tue, Aug 26, 2008 at 12:03 PM, Andy Shevchenko
<> wrote:
> write() changes offset of the file even if number of bytes to write equal to
> zero.
Additionally small test case:

#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include <string.h>

#define fn "write-test.txt"

int main()
        int fd;
        long off;
        char *str = "Test write() append\n";
        fd = open(fn, O_CREAT | O_RDWR);
        write(fd, str, strlen(str));
        fd = open(fn, O_WRONLY | O_APPEND);
        off = lseek(fd, (off_t) 0, SEEK_SET);
        write(fd, str, 0);
        off = lseek(fd, (off_t) 0, SEEK_CUR);
        printf("off: %ld\n", off);
        return 0;

Results (linux/netbsd):

andy@FITFIESPPC176:~/tmp$ ./write
off: 0

09:07 tmp$ ./write
off: 20

With Best Regards,
Andy Shevchenko

Home | Main Index | Thread Index | Old Index