Skip to content
This repository has been archived by the owner on Aug 15, 2019. It is now read-only.

Fix unused result #12

Merged
merged 2 commits into from
Sep 6, 2017
Merged

Fix unused result #12

merged 2 commits into from
Sep 6, 2017

Conversation

hellerve
Copy link
Owner

@hellerve hellerve commented Sep 6, 2017

This PR fixes #11. It introduces the helper function write_wrapped to ignore warnings on certain versions of GCC/glibc and unused results.

@hellerve hellerve merged commit b84dfe2 into master Sep 6, 2017
@hellerve hellerve deleted the fix-unused-result branch September 6, 2017 08:24
ssize_t x = write(file, str, len);
(void) x;
}

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disclaimer: I'm not a C programmer in what so ever way. ;-)
Wouldn't be nice to check for return value of write and name the function following your naming convention of e_foobar?

void e_write(int file, const char* str, int len) {
    if (write(file, str, len) != len) {
        fprintf(stderr, "Cannot write to file %i with error: %s\n", file, strerror(errno));
    }
}

Copy link
Owner Author

@hellerve hellerve Sep 6, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand your concern here. A lot of the time in C we don’t do all of the error checking we could do because we assume that some calls never fail—in e I also don’t check for failures of malloc/realloc for instance. I’m also not so sure about fprintfing the error here, especially after the last call to write failed and considering that the user could redirect stderr, leading to weird artifacts on the screen (in the best case).

As per the naming convention: the e_<function> convention is only really important for exported functions (as in, functions that are in the header) I feel, but I would agree that it’s less of a code smell to follow it regardless. I shall update it in the next commit.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants