0

Looking at documentation for pthread_* functions such as pthread_rwlock_destroy and many others, this is how the documentation is worded:

RETURN VALUE

If successful, the pthread_rwlock_destroy() and pthread_rwlock_init() functions shall return zero; otherwise, an error number shall be returned to indicate the error.

The [EBUSY] and [EINVAL] error checks, if implemented, act as if they were performed immediately at the beginning of processing for the function and caused an error return prior to modifying the state of the read-write lock specified by rwlock.

This says that in case of error, an error number shall be returned. Then, it explains the error codes:

ERRORS

The pthread_rwlock_destroy() function may fail if:

[EBUSY]
The implementation has detected an attempt to destroy the object referenced by rwlock while it is locked.
...

Which doesn't mention whether EBUSY itself is returned or -EBUSY. Almost everywhere I see when functions return an error code, they return -E*****.

Does that mean pthread_* functions also follow this convention? Should I check the return value against -EBUSY or EBUSY itself?

On the same subject, would they store EBUSY in errno or -EBUSY?

Community
  • 1
  • 1
Shahbaz
  • 46,337
  • 19
  • 116
  • 182
  • 2
    `EBUSY != -EBUSY` .. I don't understand where the negative numbers come in. –  Mar 19 '13 at 18:05
  • 1
    Confusion with kernel implementation details. – R.. GitHub STOP HELPING ICE Mar 19 '13 at 18:16
  • @pst, `EBUSY != -EBUSY`, therefore you need to know whether `EBUSY` is returned or `-EBUSY`. Usually error codes are defined positive, and then they are returned with a minus sign behind them. So... the negative numbers come in where they put `-`? Or did I completely misunderstood your comment? – Shahbaz Mar 20 '13 at 09:29
  • You should neither check for `>0` nor `<0` but for `!=0` ... if it didn't succeeded it must have failed! ;-) – alk Mar 20 '13 at 18:22
  • @alk, sigh... Yes. Then you want to check why it failed, i.e. you should check the return value against `EBUSY` or `-EBUSY`. I was asking which is the correct one. – Shahbaz Mar 20 '13 at 20:26

1 Answers1

4

They return the error codes which are positive. Nothing visible to applications returns negated error codes. That's an implementation detail of the kernel.

R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711
  • 1
    Were "*They*" means the `pthread_*` familiy of functions in detail. The majority of system calls simply returns `0` on success an `-1` on error while setting `errno` to a positive value out of the set of `E*` error codes. – alk Mar 19 '13 at 18:50
  • It's funny, I searched for "return EBUSY" and "return EINVAL" in github (in codes) and I indeed see that `pthread_*` functions return the `E*` values themselves. However everything else seems to return `-E*`. At the same time, all of those everything else seem to somehow relate to the kernel! – Shahbaz Mar 20 '13 at 09:36