I have legacy code that does this all over the place:
int fd; // open a file if(fd == -1) { close(fd); }
It looks very wrong to me.
Does the invalid file handle close?
According to the manual:
After successful completion, the value 0 is returned. Otherwise, the value is from -1 and the global integer variable errno is set to indicate an error.
and then:
The close() system call will fail if: [EBADF] fildes is not a valid, active file descriptor.
Then nothing harmful will happen.
It returns an error code. There is nothing wrong, but it is also not useful, since in any case the return values ββare not checked.
return
Citation reference page
Return valueclose() returns zero on success. On error, -1 is returned, and errno is set accordingly.
Return value
close() returns zero on success. On error, -1 is returned, and errno is set accordingly.
close()
and
MistakesEBADFfd not a valid open file descriptor.
Mistakes
EBADFfd not a valid open file descriptor.
EBADF
fd
Source: https://habr.com/ru/post/1260662/More articles:Django views in the project directory - djangoInstall / Uninstall Apache2 on MacOS Sierra 10.12.1 - phpAnswer does not load when using utf-8 characters in header with spring-boot rest and Swagger - javaWhich browser will use PWA (Progressive Web App) after adding to the main screen? - progressive-web-appsChange inline colors - angularExceptional Python spark characters from data frame - python-2.7Using Jupyter Laptop for Java - javaReact Native cached error cannot read getScrollableNode undefined property - caching"Definition not defined" in Jest when testing es6 module with RequireJS requirement - reactjsPostgis syntax PARALLEL error - postgresqlAll Articles