summaryrefslogtreecommitdiff
path: root/libps/tty.c
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>2000-01-25 21:37:30 +0000
committerRoland McGrath <roland@gnu.org>2000-01-25 21:37:30 +0000
commit41958de11946ac526a14223cd6d7652e7edd321f (patch)
tree6e7a2c24c1e1626f91d80f86478b2fdd5eb4c244 /libps/tty.c
parent3cc258d903d1a3f0982f1d9de68c133702a863a0 (diff)
2000-01-25 Roland McGrath <roland@baalperazim.frob.com>
* tty.c (struct ps_tty_abbrev): Add const to member types. (ps_tty_abbrevs): Make const. (ps_tty_short_name): Clean up type usage, add consts. Include null terminator in calculation for short_name allocation size. Save lengths and use memcpy instead of using strcpy and strcat.
Diffstat (limited to 'libps/tty.c')
-rw-r--r--libps/tty.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/libps/tty.c b/libps/tty.c
index 9d9ee649..3ab72ee8 100644
--- a/libps/tty.c
+++ b/libps/tty.c
@@ -1,8 +1,8 @@
/* The ps_tty type, for per-tty info.
- Copyright (C) 1995, 1996 Free Software Foundation, Inc.
+ Copyright (C) 1995,1996,2000 Free Software Foundation, Inc.
- Written by Miles Bader <miles@gnu.ai.mit.edu>
+ Written by Miles Bader <miles@gnu.org>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
@@ -91,11 +91,11 @@ ps_tty_name (struct ps_tty *tty)
struct ps_tty_abbrev
{
- char *pfx;
- char *subst;
+ const char *pfx;
+ const char *subst;
};
-struct ps_tty_abbrev ps_tty_abbrevs[] =
+const struct ps_tty_abbrev ps_tty_abbrevs[] =
{
{ "/tmp/console", "oc" }, /* temp hack */
{ "/dev/console", "co" },
@@ -115,14 +115,14 @@ ps_tty_short_name (struct ps_tty *tty)
return tty->short_name;
else
{
- struct ps_tty_abbrev *abbrev;
+ const struct ps_tty_abbrev *abbrev;
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);
+ const char *subst = abbrev->subst;
+ size_t pfx_len = strlen (abbrev->pfx);
if (strncmp (name, abbrev->pfx, pfx_len) == 0)
{
@@ -132,11 +132,13 @@ ps_tty_short_name (struct ps_tty *tty)
tty->short_name = name + pfx_len;
else
{
- char *n = malloc (strlen(subst) + strlen (name + pfx_len));
+ size_t slen = strlen (subst);
+ size_t nlen = strlen (name + pfx_len) + 1;
+ char *n = malloc (slen + nlen);
if (n)
{
- strcpy (n, subst);
- strcat (n, name + pfx_len);
+ memcpy (n, subst, slen);
+ memcpy (&n[slen], &name[pfx_len], nlen);
tty->short_name = n;
tty->short_name_alloced = TRUE;
}