previous: >>107920671#define __NR_pwrite64 18https://man7.org/linux/man-pages/man2/pwrite.2.htmlreally not much to say about this one... the man page even redirects back to pread, lol.i guess i will take this opportunity to complain about my least favorite part of this family of syscalls: >Note that it is not an error for a successful call to transfer fewer bytes than requested (see read(2) and write(2)).this is pretty obnoxious, as every time you use these calls, you need to decide whether the return value should be compared against -1, or else against the expected length. luckily in most cases it should be relatively obvious which is the correct way to handle your situation, but it's still a hassle. thank you GNU for the TEMP_FAILURE_RETRY (https://elixir.bootlin.com/glibc/glibc-2.42.9000/source/posix/unistd.h#L1134) macro, though, which is pretty convenient for handling EINTRrelevant resources: man manman syscallshttps://man7.org/linux/man-pages/https://linux.die.net/man/https://elixir.bootlin.com/linux/https://elixir.bootlin.com/musl/https://elixir.bootlin.com/glibc/
#define __NR_pwrite64 18
man man
man syscalls
>>107929895raw syscalls return -errno instead which is much better
>>107930007yes and nohave you *seen* the return value of mmap on 32-bit systems?
>>107930007>>107930040i guess it's always gross (https://elixir.bootlin.com/linux/v6.18.6/source/include/linux/err.h#L22), but it's just especially noticable on 32-bit systems
>>107930040nowhat about it?
>>107930068you have to basically perform bitwise operations or some evil casting with the return value to check against MAX_ERRNO. it's not as easy as on 64-bit systems, where you can just cast and check if the value is negative. just a quirk of the address space
>>107930068>>107930092https://stackoverflow.com/questions/36296130/why-does-is-err-value-cast-negative-max-errno-to-an-unsigned-long
>>107929895wops could've at least cut off the tops and bottoms of the paper
>>107930092mehstill 10x better than having to set up TLS for errno only
>>107930007Only BSDs got it right. Errors shouldn't be signalled in-band unless there's absolutely no other way
>>107930115the idea of having a global like that is honestly really gross loli wish it just took a pointer to an error value and set it for you if the pointer was non-null>>107930141agreed
>>107930144actually, i that back. the return value should always be zero, or else an error. if it wants to return other information, *that* should take a pointer
>>107930188totally agree
>>107929895Have a bump autist, survive for at least 5 more hours
>>107929895The amount of code that doesn't check if writes were partial and doesn't handle EINTR specially doesn't keep me up at night but it does make me wince sometimesRust has an automatic wrapper that handles this for you but flubbed by calling it "write_all" while the primitive is called "write" so of course everyone who doesn't read the docs just goes straight for "write"
>>107934478>write_allsetvbuf _IONBF+fwrite does the same thing in CI have yet to find a way to reproducibly cut short a blocking write on Linux though
>>107929895in case any of you goys wants to learn ASM, I recommend this free book:https://pacman128.github.io/pcasm/sadly, it teaches 32-bit ASM and it doesn't have a section for syscalls, but it's really good as a start. here's the ToC:>Introduction>Basic Assembly Language>Bit Operations>Subprograms>Arrays>Floating Point>Structures and C++it's really cool that it even teaches calling conventions. if you know a bit of C, it might be useful for you.
>>107936475Based, thank you anon.
>>107936475I forgot to mention:there are multiple translations (French, German, Spanish, Italian, Korean, Simplified Chinese, Traditional Chinese)use a 32-bit system (a VM, livecd or whatever) to run the exercise/example codes.you should be able to learn all of that in a week...here's a much shorter tutorial that targets x86_64 and has syscalls and C calling conventions:https://cs.lmu.edu/~ray/notes/nasmtutorial/also, beware that nasm uses a different notation from at&t asm, and most assemblers have different notations and even, err, behaviors.>>107936493yw
>>107936366>_IONBFThat doesn't help if the syscall stops early as it's allowed to do, right? It just disables buffering
>>107937700yes, but fwrite retries until error
>>107934478>EINTRdo you care aboout this if oyu don't install signal handlers?
>>107937845Yeah, you can get EINTR after waking up from Ctrl-Z