lights: Put back fd checks before closing

While close(NULL) is indeed a harmless noop, fd can
end up being < 0 for us.

Change-Id: I56dcd7fb61c72d3ce750b13329ff42e11ab63c84
This commit is contained in:
Christopher N. Hesse 2017-04-05 18:55:28 +02:00
parent 235c298767
commit e37aedde2e
1 changed files with 6 additions and 4 deletions

View File

@ -31,7 +31,7 @@
* Reads an Integer from a file.
*
* @param path The absolute path string.
* @return The Integer with decimal base, -1 or errno on error.
* @return The Integer with decimal base, -1 or -errno on error.
*/
static int read_int(char const *path)
{
@ -66,7 +66,8 @@ static int read_int(char const *path)
}
exit:
close(fd);
if (fd >= 0)
close(fd);
return ret;
}
@ -75,7 +76,7 @@ exit:
*
* @param path The absolute path string.
* @param value The Integer value to be written.
* @return 0 on success, errno on error.
* @return 0 on success, -errno on error.
*/
static int write_int(char const *path, const int value)
{
@ -100,7 +101,8 @@ static int write_int(char const *path, const int value)
}
exit:
close(fd);
if (fd >= 0)
close(fd);
return ret;
}