1

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

return -errno.EACCES

Chris Allen
  • 653
  • 4
  • 9
  • 17
  • What does a minus in front of any other expression (take `1` as a super-simple example) mean? –  May 20 '11 at 17:52
  • 1
    Even Google search did not explain what you are actually doing. –  May 20 '11 at 17:52

3 Answers3

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

log0
  • 10,489
  • 4
  • 28
  • 62
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)

Community
  • 1
  • 1
Doug T.
  • 64,223
  • 27
  • 138
  • 202
  • 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 '11 at 18:03
  • @Ugo, this question (http://stackoverflow.com/questions/1848729/c-why-return-a-negative-errno-e-g-return-eio) 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 '11 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.

dr jimbob
  • 17,259
  • 7
  • 59
  • 81