Recent

Author Topic: GetLastOSError / fpgeterrno always return 0  (Read 5022 times)

Lenny33

  • New Member
  • *
  • Posts: 49
GetLastOSError / fpgeterrno always return 0
« on: June 03, 2025, 12:11:04 pm »
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

  • Administrator
  • Hero Member
  • *
  • Posts: 12536
  • FPC developer.
Re: GetLastOSError / fpgeterrno always return 0
« Reply #1 on: June 03, 2025, 02:05:48 pm »
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

  • New Member
  • *
  • Posts: 49
Re: GetLastOSError / fpgeterrno always return 0
« Reply #2 on: June 03, 2025, 04:56:19 pm »
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.
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

  • Administrator
  • Hero Member
  • *
  • Posts: 12536
  • FPC developer.
Re: GetLastOSError / fpgeterrno always return 0
« Reply #3 on: June 03, 2025, 11:28:34 pm »
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! :)

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

 

TinyPortal © 2005-2018