summaryrefslogtreecommitdiff
path: root/libps/tty.c
diff options
context:
space:
mode:
authorMiles Bader <miles@gnu.org>1996-03-26 23:09:11 +0000
committerMiles Bader <miles@gnu.org>1996-03-26 23:09:11 +0000
commitfb800f0088c508fc8a405249270206b7ac3704a2 (patch)
treed6144be68d4ab46db18beb0874aaa47c99624a9c /libps/tty.c
parent2bad3d5bf7be55762191c26ca898761b37c6e5f3 (diff)
Get rid of mega typedefs, and just use structure pointers like other hurd
libraries. Other misc cleanups.
Diffstat (limited to 'libps/tty.c')
-rw-r--r--libps/tty.c55
1 files changed, 25 insertions, 30 deletions
diff --git a/libps/tty.c b/libps/tty.c
index f7602a96..9d89c665 100644
--- a/libps/tty.c
+++ b/libps/tty.c
@@ -1,6 +1,6 @@
-/* The type ps_tty_t, for per-tty info.
+/* The ps_tty type, for per-tty info.
- Copyright (C) 1995 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1996 Free Software Foundation, Inc.
Written by Miles Bader <miles@gnu.ai.mit.edu>
@@ -30,12 +30,12 @@
/* ---------------------------------------------------------------- */
-/* Create a ps_tty_t for the tty referred to by PORT, returning it in TTY.
+/* Create a ps_tty for the tty referred to by PORT, returning it in TTY.
If a memory allocation error occurs, ENOMEM is returned, otherwise 0. */
error_t
-ps_tty_create(file_t port, ps_tty_t *tty)
+ps_tty_create (file_t port, struct ps_tty **tty)
{
- *tty = NEW(struct ps_tty);
+ *tty = NEW (struct ps_tty);
if (*tty == NULL)
return ENOMEM;
@@ -49,38 +49,33 @@ ps_tty_create(file_t port, ps_tty_t *tty)
/* Frees TTY and any resources it consumes. */
void
-ps_tty_free(ps_tty_t tty)
+ps_tty_free (struct ps_tty *tty)
{
- mach_port_deallocate(mach_task_self(), tty->port);
+ mach_port_deallocate(mach_task_self (), tty->port);
if (tty->name_state == PS_TTY_NAME_OK && tty->name != NULL)
- free(tty->name);
+ free ((char *)tty->name);
if (tty->short_name_alloced)
- free(tty->short_name);
- free(tty);
+ free ((char *)tty->short_name);
+ free (tty);
}
/* ---------------------------------------------------------------- */
/* Returns the name of the tty, or NULL if it can't be figured out. */
-char *ps_tty_name(ps_tty_t tty)
+const char *
+ps_tty_name (struct ps_tty *tty)
{
if (tty->name_state == PS_TTY_NAME_PENDING)
{
string_t buf;
- if (term_get_nodename(tty->port, buf) != 0)
+ if (term_get_nodename (tty->port, buf) != 0)
/* There is a terminal there, but we can't figure out its name. */
tty->name_state = PS_TTY_NAME_ERROR;
else
{
- tty->name = NEWVEC(char, strlen(buf) + 1);
- if (tty->name == NULL)
- tty->name_state = PS_TTY_NAME_ERROR;
- else
- {
- strcpy(tty->name, buf);
- tty->name_state = PS_TTY_NAME_OK;
- }
+ tty->name = strdup (buf);
+ tty->name_state = (tty->name ? PS_TTY_NAME_OK : PS_TTY_NAME_ERROR);
}
}
@@ -110,23 +105,23 @@ struct ps_tty_abbrev ps_tty_abbrevs[] =
/* Returns the standard abbreviated name of the tty, the whole name if there
is no standard abbreviation, or NULL if it can't be figured out. */
-char *
-ps_tty_short_name(ps_tty_t tty)
+const char *
+ps_tty_short_name (struct ps_tty *tty)
{
if (tty->short_name != NULL)
return tty->short_name;
else
{
struct ps_tty_abbrev *abbrev;
- char *name = ps_tty_name(tty);
+ const char *name = ps_tty_name (tty);
if (name)
for (abbrev = ps_tty_abbrevs; abbrev->pfx != NULL; abbrev++)
{
char *subst = abbrev->subst;
- unsigned pfx_len = strlen(abbrev->pfx);
+ unsigned pfx_len = strlen (abbrev->pfx);
- if (strncmp(name, abbrev->pfx, pfx_len) == 0)
+ if (strncmp (name, abbrev->pfx, pfx_len) == 0)
{
if (name[pfx_len] == '\0')
tty->short_name = abbrev->subst;
@@ -134,13 +129,13 @@ ps_tty_short_name(ps_tty_t tty)
tty->short_name = name + pfx_len;
else
{
- tty->short_name =
- malloc(strlen(subst) + strlen(name + pfx_len));
- if (tty->short_name)
+ char *n = malloc (strlen(subst) + strlen (name + pfx_len));
+ if (n)
{
+ strcpy (n, subst);
+ strcat (n, name + pfx_len);
+ tty->short_name = n;
tty->short_name_alloced = TRUE;
- strcpy(tty->short_name, subst);
- strcat(tty->short_name, name + pfx_len);
}
}
break;