GetLastOSError / fpgeterrno always return 0 lazarus / 66-Unix ---------------------------------------------------------------------- Lenny33 · 2025-06-03 10:11 Lazarus 4.0 / FPC 3.2.2 Working with semaphores on Linux. I call sem_timedwait function which returns -1 in case of failure. According to the Linux documentation errno should then be set to ETIMEDOUT. I check errno, but there is 0, I tried calling GetLastOSError/fpgeterrno, but it also returns 0. Moreover I checked the operation of other semaphore functions. In case of an error they all return -1, but GetLastOSError still returns 0. What can be the reason for GetLastOSError/fpgeterrno always return 0 value instead of ETIMEDOUT, EACCES, EEXIST, EINVAL etc? ---------------------------------------------------------------------- marcov · 2025-06-03 12:05 It's been a while since I did these things, but afaik Errno is the FPC runtime libraries error variable. If you call libc's functions you need to load C's error variable, cerrno in unit initc. ---------------------------------------------------------------------- Lenny33 · 2025-06-03 14:56 Quote from: marcov on June 03, 2025, 02:05:48 pmIt's been a while since I did these things, but afaik Errno is the FPC runtime libraries error variable. If you call libc's functions you need to load C's error variable, cerrno in unit initc. Yep! Thanks a lot! cerrno in initc it is exactly that I need In general, it's strange that working with Linux semaphores in Lazarus is left at the level of calling C libraries. Although, as far as I understand, it may be due to the ambiguity of semaphore implementation on different platforms. Thanks again! ---------------------------------------------------------------------- marcov · 2025-06-03 21:28 Quote from: Lenny33 on June 03, 2025, 04:56:19 pmIn general, it's strange that working with Linux semaphores in Lazarus is left at the level of calling C libraries. Although, as far as I understand, it may be due to the ambiguity of semaphore implementation on different platforms. Thanks again! In the old days (pre kernel 2.2/2.4) nearly everything was a syscall. There was a readdir(2) call (*) Threading was based on clone/rfork call. With kernel 2.2 and even more 2.4 (m:n threads) that got increasing more complicated, buried under mountains of architecture specific headers/macros. (*) a big problem when I started on the FPC BSD ports, as they didn't have that. I basically learned C back then to convert the readdir support, say 1999-2000, learned to work with strace/ktrace etc