linux-sysprog · beginner · ~10 min
Compose `strerror` + `snprintf` with a cap.
Implement void describe_errno(int err, char *out, size_t cap).
Format: "errno=%d (%s)" where the string is strerror(err). Cap-aware: snprintf semantics.
A user-facing error message that says 'errno=2' is useless. Every defensive tool wraps strerror into something readable.
errno value + buffer.
Formatted string in out.
Use snprintf. Cap at cap.
#include <stddef.h>
void describe_errno(int err, char *out, size_t cap) { /* TODO */ }
Calling strerror without a cap.
errno == 0 ("Success"); unknown errno value (strerror returns "Unknown error N").
O(1).
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.