From: Ray Strode Date: Wed, 16 May 2007 20:29:22 +0000 (-0400) Subject: Improve the ply-terminal api X-Git-Tag: 0.1.0~291 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=73879cdf3c4e7c5bd386800809a120c73ed930a1;p=thirdparty%2Fplymouth.git Improve the ply-terminal api Previously, the api for creating the pseudo-terminal was ply_terminal_open (). This is a bit confusing of an api because often a program will want to open the pseudo-terminal after creating it, so you end up with: ply_terminal_open (terminal); pts_fd = open (ply_terminal_get_name (terminal), O_RDWR); or whatever. Now it would be something like: ply_terminal_create_device (terminal); device_name = ply_terminal_get_device_name (terminal); pts_fd = open (device_name, O_RDWR); which I think is a little clearer. --- diff --git a/src/ply-terminal.c b/src/ply-terminal.c index 196ff3a0..1f0f113b 100644 --- a/src/ply-terminal.c +++ b/src/ply-terminal.c @@ -58,17 +58,17 @@ ply_terminal_free (ply_terminal_t *terminal) { assert (terminal != NULL); - ply_terminal_close (terminal); + ply_terminal_destroy_device (terminal); free (terminal); } bool -ply_terminal_open (ply_terminal_t *terminal) +ply_terminal_create_device (ply_terminal_t *terminal) { int saved_errno; assert (terminal != NULL); - assert (!ply_terminal_is_open (terminal)); + assert (!ply_terminal_has_device (terminal)); terminal->fd = posix_openpt (O_RDWR | O_NOCTTY); @@ -78,7 +78,7 @@ ply_terminal_open (ply_terminal_t *terminal) if (grantpt (terminal->fd) < 0) { saved_errno = errno; - ply_terminal_close (terminal); + ply_terminal_destroy_device (terminal); errno = saved_errno; return false; } @@ -86,7 +86,7 @@ ply_terminal_open (ply_terminal_t *terminal) if (unlockpt (terminal->fd) < 0) { saved_errno = errno; - ply_terminal_close (terminal); + ply_terminal_destroy_device (terminal); errno = saved_errno; return false; } @@ -97,7 +97,7 @@ ply_terminal_open (ply_terminal_t *terminal) } bool -ply_terminal_is_open (ply_terminal_t *terminal) +ply_terminal_has_device (ply_terminal_t *terminal) { assert (terminal != NULL); @@ -105,7 +105,7 @@ ply_terminal_is_open (ply_terminal_t *terminal) } void -ply_terminal_close (ply_terminal_t *terminal) +ply_terminal_destroy_device (ply_terminal_t *terminal) { assert (terminal != NULL); @@ -125,10 +125,10 @@ ply_terminal_get_fd (ply_terminal_t *terminal) } const char * -ply_terminal_get_name (ply_terminal_t *terminal) +ply_terminal_get_device_name (ply_terminal_t *terminal) { assert (terminal != NULL); - assert (ply_terminal_is_open (terminal)); + assert (ply_terminal_has_device (terminal)); assert (terminal->name != NULL); return terminal->name; @@ -151,14 +151,14 @@ main (int argc, terminal = ply_terminal_new (); - if (!ply_terminal_open (terminal)) + if (!ply_terminal_create_device (terminal)) { exit_code = errno; perror ("could not open new terminal"); return exit_code; } - name = ply_terminal_get_name (terminal); + name = ply_terminal_get_device_name (terminal); printf ("terminal name is '%s'\n", name); while (read (ply_terminal_get_fd (terminal), diff --git a/src/ply-terminal.h b/src/ply-terminal.h index 4821ed26..ae9aa331 100644 --- a/src/ply-terminal.h +++ b/src/ply-terminal.h @@ -31,11 +31,11 @@ typedef struct _ply_terminal ply_terminal_t; #ifndef PLY_HIDE_FUNCTION_DECLARATIONS ply_terminal_t *ply_terminal_new (); void ply_terminal_free (ply_terminal_t *terminal); -bool ply_terminal_open (ply_terminal_t *terminal); -bool ply_terminal_is_open (ply_terminal_t *terminal); -void ply_terminal_close (ply_terminal_t *terminal); +bool ply_terminal_create_device (ply_terminal_t *terminal); +bool ply_terminal_has_device (ply_terminal_t *terminal); +void ply_terminal_destroy_device (ply_terminal_t *terminal); int ply_terminal_get_fd (ply_terminal_t *terminal); -const char *ply_terminal_get_name (ply_terminal_t *terminal); +const char *ply_terminal_get_device_name (ply_terminal_t *terminal); #endif #endif /* PLY_TERMINAL_H */