:: [DNG] High level language primitive…
Etusivu
Poista viesti
Vastaa
Lähettäjä: Didier Kryn
Päiväys:  
Vastaanottaja: dng
Vanhat otsikot: Re: [DNG] Please keep 32-bits alive
Aihe: [DNG] High level language primitives [ was Please keep 32-bits alive]
Le 26/07/2017 à 22:00, Christopher Clements a écrit :
>
> Wouldn't this work? (no error checking of course XD)
>
>    off_t lseek(int fd, off_t offset, int whence);
>    ssize_t write(int fd, const void *buf, size_t count);
>       ssize_t pwrite(int fd, const void *buf, size_t count, off_t 
> offset) {
>        lseek(fd, offset, SEEK_SET);
>        return write(fd, buf, count);
>    }

>

     I looked at the source code of Musl libc. Actually both write() and 
pwrite() are simple wrappers to... a general-purpose system-call 
wrapper. The second simply has one more argument. I didn't dig further. 
At first glance at least, it means that file offsets are managed in the 
kernel or VFS but they can be bypassed by pwrite(). AFAIR pwrite() 
doesn't change the "current" file offset; it simply ignores and bypasses 
it, which isn't exactly what your example does.


     But the discussion was about low-level vs high-level programming. 
Using unistd's read() and write() in C means you are dealing with low 
level issues; otherwise why would you bother with the complexity it 
introduces - not only you need to deal with buffering but also with 
retries when interrupted by signals.


     Didier