Should I set errno?

后端 未结 6 856
盖世英雄少女心
盖世英雄少女心 2020-12-14 05:37

I\'m writing a module which exports an interface similar to send and recv.

Since those functions are supposed to return respectively the nu

6条回答
  •  不知归路
    2020-12-14 06:16

    You can just assign a value to errno, but keep in mind that there are other ways to signal an error which, depending on your situation, may be more suitable:

    1. Do not return the number of bytes read, but instead have an output parameter with type int * (or size_t * or whatever you use). You can then return an error code.
    2. Assuming that your return type is a signed type and that a negative sent or received amount of bytes does not make sense, use negative values to signal the respective error conditions.

提交回复
热议问题