1

In python code. When you see a negative in front of a Error Flag, what does it mean?

return -errno.EACCES

2
  • What does a minus in front of any other expression (take 1 as a super-simple example) mean?
    – user395760
    May 20, 2011 at 17:52
  • 1
    Even Google search did not explain what you are actually doing.
    – user2665694
    May 20, 2011 at 17:52

3 Answers 3

2

The author may has restricted error code to negative value in order to be able to return various (positive) success values.

The convention seems to be used by some people:
http://www.google.com/codesearch?hl=en&lr=&q=%22return+-errno%22+lang%3Apython&sbtn=Search

0
1

That's a C style error return. A practice that is popular is to return a meaningful non-negative result of the function on success or a negative error code on failure.

In this case, the error EACCES means that permision was denied.

(See also this question)

2
  • Never heard of this practice (I don't says that it doesn't exist). The common practice is to return something different than 0. glibc functions return positive values on error.
    – log0
    May 20, 2011 at 18:03
  • @Ugo, this question (stackoverflow.com/questions/1848729/…) gives some good info on why you'd choose a negative return value. I should probably have incorporated that kind of information into my answer.
    – Doug T.
    May 20, 2011 at 18:11
1

It means negation. errno.EACCES (permission denied) is the number 13 (positive). The author of that code had a convention where he wanted the error number to be negative to be interpreted by their code later.

Presumably, he has a reason for adopting this convention. E.g., the function returns non-negative integers on non-errors that are used later on in the program.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.