|
|
Subscribe / Log in / New account

Time To Get Rid Of errno

Time To Get Rid Of errno

Posted Aug 22, 2015 13:52 UTC (Sat) by hrw (subscriber, #44826)
In reply to: Time To Get Rid Of errno by vapier
Parent article: Glibc wrappers for (nearly all) Linux system calls

> the syscall ABI isn't really all that better. if you think using syscall(__NR_xxx) is the solution to all of your problems, then you haven't looked beyond the x86 cpu on your desktop ;).

Should I use __NR_stat, __NR_fstat, __NR_fstat64 or maybe __NR_newfstatat? Will my code run properly on all architectures if I use one of them or should I add some #ifdefs for architecture checks?

Even x86 has 3 architectures now (x86, x86-64, x32) which have different set of syscalls defined.


to post comments

Time To Get Rid Of errno

Posted Sep 23, 2015 3:24 UTC (Wed) by vapier (guest, #15768) [Link]

you should use the symbols provided by the C library. stat() if you have a path string, fstat() if you have a fd, and fstatat() if you have a dir fd.

as for the syscalls you quoted, there are other stat variants (stat64 and fstatat64 at least). there's really no guarantee your code will compile or run properly when you call the syscalls directly. C libraries provide stable APIs/ABIs, including emulating newer functionality when the kernel is old (e.g. the *at syscalls could be emulated in userspace when the kernel was too old by utilizing /proc/self/fd/, but you'd have to call glibc's fstatat and not the kernel's syscall(__NR_newfstatat)).


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds