#define FD_ERRORS \
PARA_ERROR(NOTDIR, "error: not a directory"), \
- PARA_ERROR(F_GETFL, "failed to get fd flags"), \
- PARA_ERROR(F_SETFL, "failed to set fd flags"), \
PARA_ERROR(FGETS, "fgets error"), \
PARA_ERROR(EXIST, "file or directory already exists"), \
PARA_ERROR(ISDIR, "error: is a directory"), \
}
/**
- * set a file descriptor to non-blocking mode
+ * Set a file descriptor to non-blocking mode.
*
- * \param fd The file descriptor
+ * \param fd The file descriptor.
*
- * \returns 1 on success, -E_F_GETFL, -E_F_SETFL, on errors.
+ * \return Standard.
*/
int mark_fd_nonblock(int fd)
{
int flags = fcntl(fd, F_GETFL);
if (flags < 0)
- return -E_F_GETFL;
- if (fcntl(fd, F_SETFL, ((long)flags) | O_NONBLOCK) < 0)
- return -E_F_SETFL;
+ return -ERRNO_TO_PARA_ERROR(errno);
+ flags = fcntl(fd, F_SETFL, ((long)flags) | O_NONBLOCK);
+ if (flags < 0)
+ return -ERRNO_TO_PARA_ERROR(errno);
return 1;
}