From ee12c698da34cb707899e666f7a57cc4bf241623 Mon Sep 17 00:00:00 2001 From: Paul LeoNerd Evans Date: Sun, 29 Jan 2012 16:13:38 +0000 Subject: Document the errors set by termkey_new(), use errno rather than fprintf() to stderr --- driver-csi.c | 3 --- man/termkey_new.3 | 11 ++++++++++- termkey.c | 4 ++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/driver-csi.c b/driver-csi.c index f138a73..470f996 100644 --- a/driver-csi.c +++ b/driver-csi.c @@ -19,7 +19,6 @@ typedef struct { static void register_csi_ss3_full(TermKeyType type, TermKeySym sym, int modifier_set, int modifier_mask, unsigned char cmd) { if(cmd < 0x40 || cmd >= 0x80) { - fprintf(stderr, "Cannot register CSI/SS3 key at cmd 0x%02x - out of bounds\n", cmd); return; } @@ -37,7 +36,6 @@ static void register_csi_ss3(TermKeyType type, TermKeySym sym, unsigned char cmd static void register_ss3kpalt(TermKeyType type, TermKeySym sym, unsigned char cmd, char kpalt) { if(cmd < 0x40 || cmd >= 0x80) { - fprintf(stderr, "Cannot register SS3 key at cmd 0x%02x - out of bounds\n", cmd); return; } @@ -51,7 +49,6 @@ static void register_ss3kpalt(TermKeyType type, TermKeySym sym, unsigned char cm static void register_csifunc(TermKeyType type, TermKeySym sym, int number) { if(number >= NCSIFUNCS) { - fprintf(stderr, "Cannot register CSI function key at number %d - out of bounds\n", number); return; } diff --git a/man/termkey_new.3 b/man/termkey_new.3 index c727d22..6aa70a4 100644 --- a/man/termkey_new.3 +++ b/man/termkey_new.3 @@ -25,7 +25,16 @@ If a file handle is provided, the terminfo driver may send a string to initialis .SH VERSION CHECK MACRO Before calling any functions in the \fBtermkey\fP library, an application should use the \fBTERMKEY_CHECK_VERSION\fP macro to check that the loaded version of the library is compatible with the version it was compiled against. This should be done early on, ideally just after entering its \fBmain\fP() function. .SH "RETURN VALUE" -If successful, \fBtermkey_new\fP() returns a pointer to the new instance. On failure, \fBNULL\fP is returned. \fBtermkey_destroy\fP() returns no value. +If successful, \fBtermkey_new\fP() returns a pointer to the new instance. On failure, \fBNULL\fP is returned with \fIerrno\fP set to indicate the failure. \fBtermkey_destroy\fP() returns no value. +.SH ERRORS +.TP +.B ENOENT +No driver was able to recognise the given terminal type. +.TP +.B ENOMEM +A call to \fBmalloc\fP(3) failed to allocate memory. +.PP +Additionally, \fBtermkey_new\fP() may fail if \fBfstat\fP(2) or \fBwrite\fP(2) fails on the given file handle. .SH "SEE ALSO" .BR termkey_waitkey (3), .BR termkey_advisereadable (3), diff --git a/termkey.c b/termkey.c index 6df53bd..e3daa3e 100644 --- a/termkey.c +++ b/termkey.c @@ -266,7 +266,7 @@ static int termkey_init(TermKey *tk, const char *term) } if(!tk->drivers) { - fprintf(stderr, "Unable to find a terminal driver\n"); + errno = ENOENT; goto abort_free_keynames; } @@ -1114,7 +1114,7 @@ static TermKeySym register_c0(TermKey *tk, TermKeySym sym, unsigned char ctrl, c static TermKeySym register_c0_full(TermKey *tk, TermKeySym sym, int modifier_set, int modifier_mask, unsigned char ctrl, const char *name) { if(ctrl >= 0x20) { - fprintf(stderr, "Cannot register C0 key at ctrl 0x%02x - out of bounds\n", ctrl); + errno = EINVAL; return -1; } -- cgit v1.2.3-70-g09d2