diff options
author | Miles Bader <miles@gnu.org> | 1996-03-26 23:09:11 +0000 |
---|---|---|
committer | Miles Bader <miles@gnu.org> | 1996-03-26 23:09:11 +0000 |
commit | fb800f0088c508fc8a405249270206b7ac3704a2 (patch) | |
tree | d6144be68d4ab46db18beb0874aaa47c99624a9c /libps | |
parent | 2bad3d5bf7be55762191c26ca898761b37c6e5f3 (diff) |
Get rid of mega typedefs, and just use structure pointers like other hurd
libraries. Other misc cleanups.
Diffstat (limited to 'libps')
-rw-r--r-- | libps/context.c | 86 | ||||
-rw-r--r-- | libps/filters.c | 34 | ||||
-rw-r--r-- | libps/fmt.c | 120 | ||||
-rw-r--r-- | libps/host.c | 28 | ||||
-rw-r--r-- | libps/proclist.c | 262 | ||||
-rw-r--r-- | libps/procstat.c | 108 | ||||
-rw-r--r-- | libps/tty.c | 55 | ||||
-rw-r--r-- | libps/user.c | 48 | ||||
-rw-r--r-- | libps/write.c | 36 |
9 files changed, 391 insertions, 386 deletions
diff --git a/libps/context.c b/libps/context.c index 3d343c9a..4c5aeaf0 100644 --- a/libps/context.c +++ b/libps/context.c @@ -1,6 +1,6 @@ -/* The type ps_context_t, for per-procserver and somewhat global state. +/* The ps_context type, for per-procserver and somewhat global state. - Copyright (C) 1995 Free Software Foundation, Inc. + Copyright (C) 1995, 1996 Free Software Foundation, Inc. Written by Miles Bader <miles@gnu.ai.mit.edu> @@ -29,42 +29,42 @@ /* ---------------------------------------------------------------- */ -/* Returns in PC a new ps_context_t for the proc server SERVER. If a memory +/* Returns in PC a new ps_context for the proc server SERVER. If a memory allocation error occurs, ENOMEM is returned, otherwise 0. */ error_t -ps_context_create(process_t server, ps_context_t *pc) +ps_context_create (process_t server, struct ps_context **pc) { error_t err_procs, err_ttys, err_ttys_by_cttyid, err_users; - *pc = NEW(struct ps_context); + *pc = NEW (struct ps_context); if (*pc == NULL) return ENOMEM; (*pc)->server = server; (*pc)->user_hooks = 0; - err_procs = ihash_create(&(*pc)->procs); - err_ttys = ihash_create(&(*pc)->ttys); - err_ttys_by_cttyid = ihash_create(&(*pc)->ttys_by_cttyid); - err_users = ihash_create(&(*pc)->users); + err_procs = ihash_create (&(*pc)->procs); + err_ttys = ihash_create (&(*pc)->ttys); + err_ttys_by_cttyid = ihash_create (&(*pc)->ttys_by_cttyid); + err_users = ihash_create (&(*pc)->users); if (err_procs || err_ttys || err_ttys_by_cttyid) /* Some allocation error occurred, backout any successful ones and fail. */ { - if (!err_procs) ihash_free((*pc)->procs); - if (!err_users) ihash_free((*pc)->users); - if (!err_ttys) ihash_free((*pc)->ttys); - if (!err_ttys_by_cttyid) ihash_free((*pc)->ttys_by_cttyid); - free(*pc); + if (!err_procs) ihash_free ((*pc)->procs); + if (!err_users) ihash_free ((*pc)->users); + if (!err_ttys) ihash_free ((*pc)->ttys); + if (!err_ttys_by_cttyid) ihash_free ((*pc)->ttys_by_cttyid); + free (*pc); return ENOMEM; } - ihash_set_cleanup((*pc)->procs, + ihash_set_cleanup ((*pc)->procs, (void (*)(void *, void *arg))_proc_stat_free, NULL); - ihash_set_cleanup((*pc)->ttys, + ihash_set_cleanup ((*pc)->ttys, (void (*)(void *, void *arg))ps_tty_free, NULL); - ihash_set_cleanup((*pc)->users, + ihash_set_cleanup ((*pc)->users, (void (*)(void *, void *arg))ps_user_free, NULL); @@ -73,11 +73,11 @@ ps_context_create(process_t server, ps_context_t *pc) /* Frees PC and any resources it consumes. */ void -ps_context_free(ps_context_t pc) +ps_context_free (struct ps_context *pc) { - ihash_free(pc->procs); - ihash_free(pc->procs); - free(pc); + ihash_free (pc->procs); + ihash_free (pc->procs); + free (pc); } /* ---------------------------------------------------------------- */ @@ -87,49 +87,51 @@ ps_context_free(ps_context_t pc) (CREATE should return either an error-code or 0 if no error occurs), and cache it in HT. */ static error_t -lookup(int id, ihash_t ht, error_t (*create)(int id, void **), void **value) +lookup (int id, ihash_t ht, error_t (*create)(int id, void **), void **value) { - *value = ihash_find(ht, id); + *value = ihash_find (ht, id); if (*value == NULL) { - error_t err = create(id, value); + error_t err = create (id, value); if (err) return err; - ihash_add(ht, id, *value, NULL); + ihash_add (ht, id, *value, NULL); } return 0; } -/* Find a proc_stat_t for the process referred to by PID, and return it in +/* Find a proc_stat for the process referred to by PID, and return it in PS. If an error occurs, it is returned, otherwise 0. */ error_t -ps_context_find_proc_stat(ps_context_t pc, pid_t pid, proc_stat_t *ps) +ps_context_find_proc_stat (struct ps_context *pc, pid_t pid, struct proc_stat **ps) { - error_t create(int pid, void **value) + error_t create (int pid, void **value) { - return _proc_stat_create(pid, pc, (proc_stat_t *)value); + return _proc_stat_create (pid, pc, (struct proc_stat **)value); } - return lookup(pid, pc->procs, create, (void **)ps); + return lookup (pid, pc->procs, create, (void **)ps); } -/* Find a ps_tty_t for the terminal referred to by the port TTY_PORT, and +/* Find a ps_tty for the terminal referred to by the port TTY_PORT, and return it in TTY. If an error occurs, it is returned, otherwise 0. */ error_t -ps_context_find_tty(ps_context_t pc, mach_port_t tty_port, ps_tty_t *tty) +ps_context_find_tty (struct ps_context *pc, mach_port_t tty_port, + struct ps_tty **tty) { - return lookup(tty_port, + return lookup (tty_port, pc->ttys, (error_t (*)(int id, void **result))ps_tty_create, (void **)tty); } -/* Find a ps_tty_t for the terminal referred to by the ctty id port +/* Find a ps_tty for the terminal referred to by the ctty id port CTTYID_PORT, and return it in TTY. If an error occurs, it is returned, otherwise 0. */ error_t -ps_context_find_tty_by_cttyid(ps_context_t pc, mach_port_t cttyid_port, ps_tty_t *tty) +ps_context_find_tty_by_cttyid (struct ps_context *pc, mach_port_t cttyid_port, + struct ps_tty **tty) { - error_t create(int cttyid_port, void **value) + error_t create (int cttyid_port, void **value) { if (cttyid_port == MACH_PORT_NULL) { @@ -139,22 +141,22 @@ ps_context_find_tty_by_cttyid(ps_context_t pc, mach_port_t cttyid_port, ps_tty_t else { int tty_port; - error_t err = termctty_open_terminal(cttyid_port, 0, &tty_port); + error_t err = termctty_open_terminal (cttyid_port, 0, &tty_port); if (err) return err; else - return ps_context_find_tty(pc, tty_port, (ps_tty_t *)value); + return ps_context_find_tty (pc, tty_port, (struct ps_tty **)value); } } - return lookup(cttyid_port, pc->ttys, create, (void **)tty); + return lookup (cttyid_port, pc->ttys, create, (void **)tty); } -/* Find a ps_user_t for the user referred to by UID, and return it in U. */ +/* Find a ps_user for the user referred to by UID, and return it in U. */ error_t -ps_context_find_user(ps_context_t pc, uid_t uid, ps_user_t *u) +ps_context_find_user (struct ps_context *pc, uid_t uid, struct ps_user **u) { - return lookup(uid, + return lookup (uid, pc->users, (error_t (*)(int id, void **result))ps_user_create, (void **)u); diff --git a/libps/filters.c b/libps/filters.c index ffbb8376..4fac0390 100644 --- a/libps/filters.c +++ b/libps/filters.c @@ -1,4 +1,4 @@ -/* Some ps_filter_t's to restrict proc_stat_list's in various ways. +/* Some ps_filters to restrict proc_stat_lists in various ways. Copyright (C) 1995, 1996 Free Software Foundation, Inc. @@ -30,8 +30,8 @@ /* ---------------------------------------------------------------- */ -static bool -ps_own_p (proc_stat_t ps) +static int +ps_own_p (struct proc_stat *ps) { static int own_uid = -2; /* -1 means no uid at all. */ if (own_uid == -2) @@ -41,19 +41,19 @@ ps_own_p (proc_stat_t ps) struct ps_filter ps_own_filter = {"own", PSTAT_OWNER_UID, ps_own_p}; -static bool -ps_not_leader_p (proc_stat_t ps) +static int +ps_not_leader_p (struct proc_stat *ps) { return - !(proc_stat_state(ps) & (PSTAT_STATE_P_SESSLDR | PSTAT_STATE_P_LOGINLDR)); + !(proc_stat_state (ps) & (PSTAT_STATE_P_SESSLDR | PSTAT_STATE_P_LOGINLDR)); } struct ps_filter ps_not_leader_filter = {"not-sess-leader", PSTAT_STATE, ps_not_leader_p}; -static bool -ps_unorphaned_p(proc_stat_t ps) +static int +ps_unorphaned_p (struct proc_stat *ps) { - int state = proc_stat_state(ps); + int state = proc_stat_state (ps); return !(state & PSTAT_STATE_P_ORPHAN) || (state & (PSTAT_STATE_P_SESSLDR | PSTAT_STATE_P_LOGINLDR)); @@ -61,24 +61,24 @@ ps_unorphaned_p(proc_stat_t ps) struct ps_filter ps_unorphaned_filter = {"unorphaned", PSTAT_STATE, ps_unorphaned_p}; -static bool -ps_ctty_p(proc_stat_t ps) +static int +ps_ctty_p (struct proc_stat *ps) { - return proc_stat_cttyid(ps) != MACH_PORT_NULL; + return proc_stat_cttyid (ps) != MACH_PORT_NULL; } struct ps_filter ps_ctty_filter = {"ctty", PSTAT_CTTYID, ps_ctty_p}; -static bool -ps_parent_p(proc_stat_t ps) +static int +ps_parent_p (struct proc_stat *ps) { - return !(proc_stat_state(ps) & PSTAT_STATE_P_NOPARENT); + return !(proc_stat_state (ps) & PSTAT_STATE_P_NOPARENT); } struct ps_filter ps_parent_filter = {"parent", PSTAT_STATE, ps_parent_p}; -static bool -ps_alive_p (proc_stat_t ps) +static int +ps_alive_p (struct proc_stat *ps) { ps_flags_t test_flag = proc_stat_is_thread (ps) ? PSTAT_THREAD_BASIC : PSTAT_PROC_INFO; diff --git a/libps/fmt.c b/libps/fmt.c index 0e1e5023..af11a6e9 100644 --- a/libps/fmt.c +++ b/libps/fmt.c @@ -1,7 +1,7 @@ -/* Implements the type ps_fmt_t, which describes how to output a user-readable - version of a proc_stat_t. +/* Implements the ps_fmt type, which describes how to output a user-readable + version of a proc_stat. - Copyright (C) 1995 Free Software Foundation, Inc. + Copyright (C) 1995, 1996 Free Software Foundation, Inc. Written by Miles Bader <miles@gnu.ai.mit.edu> @@ -36,33 +36,33 @@ field name, EINVAL is returned. Otherwise 0 is returned. See ps.h for an explanation of how FMT is derived from SRC. */ error_t -ps_fmt_create(char *src, ps_fmt_specs_t fmt_specs, ps_fmt_t *fmt) +ps_fmt_create (char *src, struct ps_fmt_specs *fmt_specs, struct ps_fmt **fmt) { - ps_fmt_t new_fmt; + struct ps_fmt *new_fmt; int needs = 0; int fields_alloced = 10; - ps_fmt_field_t fields = NEWVEC(struct ps_fmt_field, fields_alloced); - ps_fmt_field_t field = fields; /* current last field */ + struct ps_fmt_field *fields = NEWVEC (struct ps_fmt_field, fields_alloced); + struct ps_fmt_field *field = fields; /* current last field */ if (fields == NULL) return ENOMEM; - new_fmt = NEW(struct ps_fmt); + new_fmt = NEW (struct ps_fmt); if (fmt == NULL) { - FREE(fields); + FREE (fields); return ENOMEM; } /* Make a private copy of SRC so we can mutate it. */ - new_fmt->src = NEWVEC(char, strlen(src) + 1); + new_fmt->src = NEWVEC (char, strlen (src) + 1); if (new_fmt->src == NULL) { - FREE(fields); - FREE(new_fmt); + FREE (fields); + FREE (new_fmt); return ENOMEM; } - strcpy(new_fmt->src, src); + strcpy (new_fmt->src, src); src = new_fmt->src; while (*src != '\0') @@ -73,12 +73,12 @@ ps_fmt_create(char *src, ps_fmt_specs_t fmt_specs, ps_fmt_t *fmt) int offs = field - fields; fields_alloced += 10; - fields = GROWVEC(fields, struct ps_fmt_field, fields_alloced); + fields = GROWVEC (fields, struct ps_fmt_field, fields_alloced); if (fields == NULL) { - FREE(new_fmt); - FREE(new_fmt->src); + FREE (new_fmt); + FREE (new_fmt->src); return ENOMEM; } @@ -101,14 +101,14 @@ ps_fmt_create(char *src, ps_fmt_specs_t fmt_specs, ps_fmt_t *fmt) { char *name; int sign = 1; - bool explicit_width = FALSE; /* True if the width set from SRC. */ + int explicit_width = FALSE; /* True if the width set from SRC. */ char *spec_start = src++; /* Read an explicit field width. */ field->width = 0; if (*src == '-') sign = -1, src++; - while (isdigit(*src)) + while (isdigit (*src)) { field->width = field->width * 10 + (*src++ - '0'); explicit_width = TRUE; @@ -120,7 +120,7 @@ ps_fmt_create(char *src, ps_fmt_specs_t fmt_specs, ps_fmt_t *fmt) /* The name of the spec, or `TITLE=NAME'. */ name = src; - while (*src != '\0' && !isspace(*src) && *src != '/' && *src != '=') + while (*src != '\0' && !isspace (*src) && *src != '/' && *src != '=') src++; if (*src == '=') @@ -132,7 +132,7 @@ ps_fmt_create(char *src, ps_fmt_specs_t fmt_specs, ps_fmt_t *fmt) /* Now read the real name. */ name = src; - while (*src != '\0' && !isspace(*src) && *src != '/') + while (*src != '\0' && !isspace (*src) && *src != '/') src++; } @@ -152,9 +152,9 @@ ps_fmt_create(char *src, ps_fmt_specs_t fmt_specs, ps_fmt_t *fmt) if (!field->spec) /* Failed to find any named spec called NAME. */ { - FREE(new_fmt->src); - FREE(fields); - FREE(new_fmt); + FREE (new_fmt->src); + FREE (fields); + FREE (new_fmt); return EINVAL; } @@ -166,10 +166,10 @@ ps_fmt_create(char *src, ps_fmt_specs_t fmt_specs, ps_fmt_t *fmt) field->title = name; /* Just use the field name. */ /* Add FIELD's required pstat_flags to FMT's set */ - needs |= ps_getter_needs(ps_fmt_spec_getter(field->spec)); + needs |= ps_getter_needs (ps_fmt_spec_getter (field->spec)); if (!explicit_width) - field->width = ps_fmt_spec_width(field->spec); + field->width = ps_fmt_spec_width (field->spec); /* Skip optional trailing `/' after the spec name. */ if (*src == '/') @@ -183,8 +183,8 @@ ps_fmt_create(char *src, ps_fmt_specs_t fmt_specs, ps_fmt_t *fmt) { /* Force the field to be wide enough to hold the title. */ int width = field->width; - int tlen = strlen(field->title); - if (width != 0 && tlen > ABS(width)) + int tlen = strlen (field->title); + if (width != 0 && tlen > ABS (width)) field->width = (width > 0 ? tlen : -tlen); } } @@ -204,11 +204,11 @@ ps_fmt_create(char *src, ps_fmt_specs_t fmt_specs, ps_fmt_t *fmt) /* Free FMT, and any resources it consumes. */ void -ps_fmt_free(ps_fmt_t fmt) +ps_fmt_free (struct ps_fmt *fmt) { - FREE(fmt->src); - FREE(fmt->fields); - FREE(fmt); + FREE (fmt->src); + FREE (fmt->fields); + FREE (fmt); } /* ---------------------------------------------------------------- */ @@ -219,24 +219,24 @@ ps_fmt_free(ps_fmt_t fmt) number number of characters output is added to the integer it points to. If any fatal error occurs, the error code is returned, otherwise 0. */ error_t -ps_fmt_write_titles (ps_fmt_t fmt, ps_stream_t stream) +ps_fmt_write_titles (struct ps_fmt *fmt, struct ps_stream *stream) { error_t err = 0; - ps_fmt_field_t field = ps_fmt_fields(fmt); - int left = ps_fmt_num_fields(fmt); + struct ps_fmt_field *field = ps_fmt_fields (fmt); + int left = ps_fmt_num_fields (fmt); while (left-- > 0 && !err) { - char *pfx = ps_fmt_field_prefix(field); - int pfx_len = ps_fmt_field_prefix_length(field); + const char *pfx = ps_fmt_field_prefix (field); + int pfx_len = ps_fmt_field_prefix_length (field); if (pfx_len > 0) err = ps_stream_write (stream, pfx, pfx_len); - if (ps_fmt_field_fmt_spec(field) != NULL && !err) + if (ps_fmt_field_fmt_spec (field) != NULL && !err) { - char *title = ps_fmt_field_title(field); - int width = ps_fmt_field_width(field); + const char *title = ps_fmt_field_title (field); + int width = ps_fmt_field_width (field); if (title == NULL) title = "??"; @@ -255,34 +255,34 @@ ps_fmt_write_titles (ps_fmt_t fmt, ps_stream_t stream) number number of characters output is added to the integer it points to. If any fatal error occurs, the error code is returned, otherwise 0. */ error_t -ps_fmt_write_proc_stat (ps_fmt_t fmt, proc_stat_t ps, ps_stream_t stream) +ps_fmt_write_proc_stat (struct ps_fmt *fmt, struct proc_stat *ps, struct ps_stream *stream) { error_t err = 0; - ps_fmt_field_t field = ps_fmt_fields(fmt); - int nfields = ps_fmt_num_fields(fmt); - int have = proc_stat_flags(ps); + struct ps_fmt_field *field = ps_fmt_fields (fmt); + int nfields = ps_fmt_num_fields (fmt); + int have = proc_stat_flags (ps); while (nfields-- > 0 && !err) { - ps_fmt_spec_t spec = ps_fmt_field_fmt_spec(field); - char *pfx = ps_fmt_field_prefix(field); - int pfx_len = ps_fmt_field_prefix_length(field); + const struct ps_fmt_spec *spec = ps_fmt_field_fmt_spec (field); + const char *pfx = ps_fmt_field_prefix (field); + int pfx_len = ps_fmt_field_prefix_length (field); if (pfx_len > 0) err = ps_stream_write (stream, pfx, pfx_len); if (spec != NULL && !err) { - int need = ps_getter_needs(ps_fmt_spec_getter(spec)); - int width = ps_fmt_field_width(field); + int need = ps_getter_needs (ps_fmt_spec_getter (spec)); + int width = ps_fmt_field_width (field); /* do we have the resources to print this field? */ if ((need & have) == need) /* Yup */ { - int (*output_fn)() = (int (*)())ps_fmt_spec_output_fn(spec); - ps_getter_t getter = ps_fmt_spec_getter(spec); - err = output_fn(ps, getter, width, stream); + int (*output_fn)() = (int (*)())ps_fmt_spec_output_fn (spec); + const struct ps_getter *getter = ps_fmt_spec_getter (spec); + err = output_fn (ps, getter, width, stream); } else /* Something to display in invalid fields. */ @@ -302,31 +302,31 @@ ps_fmt_write_proc_stat (ps_fmt_t fmt, proc_stat_t ps, ps_stream_t stream) also removed: those *following* deleted fields at the beginning of the fmt, and those *preceeding* deleted fields *not* at the beginning. */ void -ps_fmt_squash (ps_fmt_t fmt, bool (*fn)(ps_fmt_spec_t spec)) +ps_fmt_squash (struct ps_fmt *fmt, int (*fn)(const struct ps_fmt_spec *spec)) { int nfields = fmt->num_fields; - ps_fmt_field_t fields = fmt->fields, field = fields; + struct ps_fmt_field *fields = fmt->fields, *field = fields; /* As we're removing some fields, we must recalculate the set of ps flags needed by all fields. */ ps_flags_t need = 0; while ((field - fields) < nfields) { - ps_fmt_spec_t spec = field->spec; + const struct ps_fmt_spec *spec = field->spec; if (spec != NULL && (*fn)(spec)) /* Squash this field! */ { /* Save the old prefix, in case we're deleting the first field, and need to prepend it to the next field. */ - char *beg_pfx = field->pfx; + const char *beg_pfx = field->pfx; int beg_pfx_len = field->pfx_len; nfields--; /* Shift down all following fields over this one. */ if (nfields > 0) - bcopy(field + 1, field, + bcopy (field + 1, field, (nfields - (field - fields)) * sizeof *field); if (field == fields) @@ -356,7 +356,7 @@ ps_fmt_squash (ps_fmt_t fmt, bool (*fn)(ps_fmt_spec_t spec)) { field->pfx -= beg_pfx_len; field->pfx_len += beg_pfx_len; - bcopy(beg_pfx, field->pfx, beg_pfx_len); + bcopy (beg_pfx, (char *)field->pfx, beg_pfx_len); } else /* otherwise just replace the next field's prefix with @@ -386,9 +386,9 @@ ps_fmt_squash (ps_fmt_t fmt, bool (*fn)(ps_fmt_spec_t spec)) deleted fields at the beginning of the fmt, and those *preceeding* deleted fields *not* at the beginning. */ void -ps_fmt_squash_flags(ps_fmt_t fmt, ps_flags_t flags) +ps_fmt_squash_flags (struct ps_fmt *fmt, ps_flags_t flags) { - bool squashable_spec (ps_fmt_spec_t spec) + int squashable_spec (const struct ps_fmt_spec *spec) { return ps_getter_needs (ps_fmt_spec_getter (spec)) & flags; } @@ -400,7 +400,7 @@ ps_fmt_squash_flags(ps_fmt_t fmt, ps_flags_t flags) /* Try and restrict the number of output columns in FMT to WIDTH. */ void -ps_fmt_set_output_width (ps_fmt_t fmt, int width) +ps_fmt_set_output_width (struct ps_fmt *fmt, int width) { struct ps_fmt_field *field = ps_fmt_fields (fmt); int nfields = ps_fmt_num_fields (fmt); diff --git a/libps/host.c b/libps/host.c index f966fc93..26be9a31 100644 --- a/libps/host.c +++ b/libps/host.c @@ -1,6 +1,6 @@ /* Routines to get global host 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> @@ -38,11 +38,11 @@ /* Return the current host port. */ host_t -ps_get_host() +ps_get_host () { static host_t host = MACH_PORT_NULL; if (host == MACH_PORT_NULL) - host = mach_host_self(); + host = mach_host_self (); return host; } @@ -50,15 +50,15 @@ ps_get_host() this is static global information we just use a static buffer. If a system error occurs, the error code is returned, otherwise 0. */ error_t -ps_host_basic_info(host_basic_info_t *info) +ps_host_basic_info (host_basic_info_t *info) { - bool initialized = FALSE; + int initialized = FALSE; static host_basic_info_data_t buf; if (!initialized) { - int size = sizeof(buf); - error_t err = host_info(ps_get_host(), HOST_BASIC_INFO, + int size = sizeof (buf); + error_t err = host_info (ps_get_host (), HOST_BASIC_INFO, (host_info_t) &buf, &size); if (err) return err; @@ -73,15 +73,15 @@ ps_host_basic_info(host_basic_info_t *info) Since this is static global information we just use a static buffer. If a system error occurs, the error code is returned, otherwise 0. */ error_t -ps_host_sched_info(host_sched_info_t *info) +ps_host_sched_info (host_sched_info_t *info) { - bool initialized = FALSE; + int initialized = FALSE; static host_sched_info_data_t buf; if (!initialized) { - int size = sizeof(buf); - error_t err = host_info(ps_get_host(), HOST_SCHED_INFO, + int size = sizeof (buf); + error_t err = host_info (ps_get_host (), HOST_SCHED_INFO, (host_info_t) &buf, &size); if (err) return err; @@ -97,11 +97,11 @@ ps_host_sched_info(host_sched_info_t *info) to keep old load info, they should copy the buffer we return a pointer to). If a system error occurs, the error code is returned, otherwise 0. */ error_t -ps_host_load_info(host_load_info_t *info) +ps_host_load_info (host_load_info_t *info) { static host_load_info_data_t buf; - int size = sizeof(buf); - error_t err = host_info(ps_get_host(), HOST_LOAD_INFO, + int size = sizeof (buf); + error_t err = host_info (ps_get_host (), HOST_LOAD_INFO, (host_info_t) &buf, &size); if (err) diff --git a/libps/proclist.c b/libps/proclist.c index 68541f68..c92f8b69 100644 --- a/libps/proclist.c +++ b/libps/proclist.c @@ -1,4 +1,4 @@ -/* The type proc_stat_list_t, which holds lists of proc_stat_t's. +/* The type proc_stat_list_t, which holds lists of proc_stats. Copyright (C) 1995, 1996 Free Software Foundation, Inc. @@ -32,9 +32,9 @@ returned in PP, and returns 0, or else returns ENOMEM if there wasn't enough memory. */ error_t -proc_stat_list_create(ps_context_t context, proc_stat_list_t *pp) +proc_stat_list_create (struct ps_context *context, struct proc_stat_list **pp) { - *pp = NEW(struct proc_stat_list); + *pp = NEW (struct proc_stat_list); if (*pp == NULL) return ENOMEM; @@ -48,26 +48,27 @@ proc_stat_list_create(ps_context_t context, proc_stat_list_t *pp) /* Free PP, and any resources it consumes. */ void -proc_stat_list_free(proc_stat_list_t pp) +proc_stat_list_free (struct proc_stat_list *pp) { - proc_stat_list_remove_threads(pp); - FREE(pp->proc_stats); - FREE(pp); + proc_stat_list_remove_threads (pp); + FREE (pp->proc_stats); + FREE (pp); } /* ---------------------------------------------------------------- */ /* Make sure there are at least AMOUNT new locations allocated in PP's - proc_stat_t array (but without changing NUM_PROCS). Returns ENOMEM if a + proc_stat array (but without changing NUM_PROCS). Returns ENOMEM if a memory allocation error occurred, 0 otherwise. */ static error_t -proc_stat_list_grow(proc_stat_list_t pp, int amount) +proc_stat_list_grow (struct proc_stat_list *pp, int amount) { amount += pp->num_procs; if (amount > pp->alloced) { - proc_stat_t *new_procs = GROWVEC(pp->proc_stats, proc_stat_t, amount); + struct proc_stat **new_procs = + GROWVEC (pp->proc_stats, struct proc_stat *, amount); if (new_procs == NULL) return ENOMEM; @@ -79,7 +80,7 @@ proc_stat_list_grow(proc_stat_list_t pp, int amount) return 0; } -/* Add proc_stat_t entries to PP for each process with a process id in the +/* Add proc_stat entries to PP for each process with a process id in the array PIDS (where NUM_PROCS is the length of PIDS). Entries are only added for processes not already in PP. ENOMEM is returned if a memory allocation error occurs, otherwise 0. PIDs is not referenced by the @@ -87,9 +88,9 @@ proc_stat_list_grow(proc_stat_list_t pp, int amount) PROC_STATS is non-NULL, a malloced array NUM_PROCS entries long of the resulting proc_stats is returned in it. */ error_t -proc_stat_list_add_pids (proc_stat_list_t pp, +proc_stat_list_add_pids (struct proc_stat_list *pp, pid_t *pids, unsigned num_procs, - proc_stat_t **proc_stats) + struct proc_stat ***proc_stats) { error_t err = proc_stat_list_grow (pp, num_procs); @@ -98,19 +99,19 @@ proc_stat_list_add_pids (proc_stat_list_t pp, else { int i; - proc_stat_t *end = pp->proc_stats + pp->num_procs; + struct proc_stat **end = pp->proc_stats + pp->num_procs; if (proc_stats) - *proc_stats = NEWVEC (proc_stat_t, num_procs); + *proc_stats = NEWVEC (struct proc_stat *, num_procs); for (i = 0; i < num_procs; i++) { int pid = *pids++; - proc_stat_t ps = proc_stat_list_pid_proc_stat (pp, pid); + struct proc_stat *ps = proc_stat_list_pid_proc_stat (pp, pid); if (ps == NULL) { - err = ps_context_find_proc_stat(pp->context, pid, end); + err = ps_context_find_proc_stat (pp->context, pid, end); if (err) { if (proc_stats) @@ -131,14 +132,14 @@ proc_stat_list_add_pids (proc_stat_list_t pp, } } -/* Add a proc_stat_t for the process designated by PID at PP's proc context to +/* Add a proc_stat for the process designated by PID at PP's proc context to PP. If PID already has an entry in PP, nothing is done. If a memory allocation error occurs, ENOMEM is returned, otherwise 0. If PS is non-NULL, the resulting entry is returned in it. */ error_t -proc_stat_list_add_pid (proc_stat_list_t pp, pid_t pid, proc_stat_t *ps) +proc_stat_list_add_pid (struct proc_stat_list *pp, pid_t pid, struct proc_stat **ps) { - proc_stat_t _ps = proc_stat_list_pid_proc_stat(pp, pid); + struct proc_stat *_ps = proc_stat_list_pid_proc_stat (pp, pid); if (_ps == NULL) { @@ -146,7 +147,7 @@ proc_stat_list_add_pid (proc_stat_list_t pp, pid_t pid, proc_stat_t *ps) if (pp->num_procs == pp->alloced) { - err = proc_stat_list_grow(pp, 32); + err = proc_stat_list_grow (pp, 32); if (err) return err; } @@ -166,16 +167,16 @@ proc_stat_list_add_pid (proc_stat_list_t pp, pid_t pid, proc_stat_t *ps) /* ---------------------------------------------------------------- */ -/* Returns the proc_stat_t in PP with a process-id of PID, if there's one, +/* Returns the proc_stat in PP with a process-id of PID, if there's one, otherwise, NULL. */ -proc_stat_t -proc_stat_list_pid_proc_stat(proc_stat_list_t pp, pid_t pid) +struct proc_stat * +proc_stat_list_pid_proc_stat (struct proc_stat_list *pp, pid_t pid) { unsigned nprocs = pp->num_procs; - proc_stat_t *procs = pp->proc_stats; + struct proc_stat **procs = pp->proc_stats; while (nprocs-- > 0) - if (proc_stat_pid(*procs) == pid) + if (proc_stat_pid (*procs) == pid) return *procs; else procs++; @@ -185,43 +186,43 @@ proc_stat_list_pid_proc_stat(proc_stat_list_t pp, pid_t pid) /* ---------------------------------------------------------------- */ -/* Adds all proc_stat_t's in MERGEE to PP that don't correspond to processes - already in PP; the resulting order of proc_stat_t's in PP is undefined. +/* Adds all proc_stats in MERGEE to PP that don't correspond to processes + already in PP; the resulting order of proc_stats in PP is undefined. If MERGEE and PP point to different proc contexts, EINVAL is returned. If a memory allocation error occurs, ENOMEM is returned. Otherwise 0 is returned, and MERGEE is freed. */ error_t -proc_stat_list_merge(proc_stat_list_t pp, proc_stat_list_t mergee) +proc_stat_list_merge (struct proc_stat_list *pp, struct proc_stat_list *mergee) { if (pp->context != mergee->context) return EINVAL; else { /* Make sure there's room for the max number of new elements in PP. */ - error_t err = proc_stat_list_grow(pp, mergee->num_procs); + error_t err = proc_stat_list_grow (pp, mergee->num_procs); if (err) return err; else { int mnprocs = mergee->num_procs; - proc_stat_t *mprocs = mergee->proc_stats; + struct proc_stat **mprocs = mergee->proc_stats; int nprocs = pp->num_procs; - proc_stat_t *procs = pp->proc_stats; + struct proc_stat **procs = pp->proc_stats; - /* Transfer over any proc_stat_t's from MERGEE to PP that don't + /* Transfer over any proc_stats from MERGEE to PP that don't already exist there; for each of these, we set its entry in MERGEE's proc_stat array to NULL, which prevents - proc_list_free() from freeing them. */ + proc_list_free () from freeing them. */ while (mnprocs-- > 0) - if (proc_stat_list_pid_proc_stat(pp, proc_stat_pid(mprocs[mnprocs])) + if (proc_stat_list_pid_proc_stat(pp, proc_stat_pid (mprocs[mnprocs])) == NULL) { procs[nprocs++] = mprocs[mnprocs]; mprocs[mnprocs] = NULL; } - proc_stat_list_free(mergee); + proc_stat_list_free (mergee); return 0; } @@ -239,17 +240,17 @@ proc_stat_list_merge(proc_stat_list_t pp, proc_stat_list_t mergee) error code is returned, otherwise 0. If PROC_STATS and NUM_PROCS are non-NULL, a malloced vector of the resulting entries is returned in them. */ static error_t -proc_stat_list_add_fn_pids (proc_stat_list_t pp, +proc_stat_list_add_fn_pids (struct proc_stat_list *pp, kern_return_t (*fetch_fn)(process_t proc, pid_t **pids, unsigned *num_pids), - proc_stat_t **proc_stats, unsigned *num_procs) + struct proc_stat ***proc_stats, unsigned *num_procs) { error_t err; pid_t pid_array[STATICPIDS], *pids = pid_array; unsigned num_pids = STATICPIDS; - err = (*fetch_fn)(ps_context_server(pp->context), &pids, &num_pids); + err = (*fetch_fn)(ps_context_server (pp->context), &pids, &num_pids); if (err) return err; @@ -258,7 +259,7 @@ proc_stat_list_add_fn_pids (proc_stat_list_t pp, *num_procs = num_pids; if (pids != pid_array) - VMFREE(pids, sizeof(pid_t) * num_pids); + VMFREE(pids, sizeof (pid_t) * num_pids); return err; } @@ -269,12 +270,12 @@ proc_stat_list_add_fn_pids (proc_stat_list_t pp, are non-NULL, a malloced vector of the resulting entries is returned in them. */ static error_t -proc_stat_list_add_id_fn_pids (proc_stat_list_t pp, unsigned id, +proc_stat_list_add_id_fn_pids (struct proc_stat_list *pp, unsigned id, kern_return_t (*fetch_fn)(process_t proc, pid_t id, pid_t **pids, unsigned *num_pids), - proc_stat_t **proc_stats, unsigned *num_procs) + struct proc_stat ***proc_stats, unsigned *num_procs) { error_t id_fetch_fn (process_t proc, pid_t **pids, unsigned *num_pids) { @@ -290,8 +291,8 @@ proc_stat_list_add_id_fn_pids (proc_stat_list_t pp, unsigned id, NUM_PROCS are non-NULL, a malloced vector of the resulting entries is returned in them. */ error_t -proc_stat_list_add_all (proc_stat_list_t pp, - proc_stat_t **proc_stats, unsigned *num_procs) +proc_stat_list_add_all (struct proc_stat_list *pp, + struct proc_stat ***proc_stats, unsigned *num_procs) { return proc_stat_list_add_fn_pids (pp, proc_getallpids, proc_stats, num_procs); @@ -302,8 +303,8 @@ proc_stat_list_add_all (proc_stat_list_t pp, otherwise 0. If PROC_STATS and NUM_PROCS are non-NULL, a malloced vector of the resulting entries is returned in them. */ error_t -proc_stat_list_add_login_coll (proc_stat_list_t pp, pid_t login_id, - proc_stat_t **proc_stats, unsigned *num_procs) +proc_stat_list_add_login_coll (struct proc_stat_list *pp, pid_t login_id, + struct proc_stat ***proc_stats, unsigned *num_procs) { return proc_stat_list_add_id_fn_pids (pp, login_id, proc_getloginpids, @@ -315,8 +316,8 @@ proc_stat_list_add_login_coll (proc_stat_list_t pp, pid_t login_id, 0. If PROC_STATS and NUM_PROCS are non-NULL, a malloced vector of the resulting entries is returned in them. */ error_t -proc_stat_list_add_session (proc_stat_list_t pp, pid_t session_id, - proc_stat_t **proc_stats, unsigned *num_procs) +proc_stat_list_add_session (struct proc_stat_list *pp, pid_t session_id, + struct proc_stat ***proc_stats, unsigned *num_procs) { return proc_stat_list_add_id_fn_pids (pp, session_id, proc_getsessionpids, @@ -328,8 +329,8 @@ proc_stat_list_add_session (proc_stat_list_t pp, pid_t session_id, 0. If PROC_STATS and NUM_PROCS are non-NULL, a malloced vector of the resulting entries is returned in them. */ error_t -proc_stat_list_add_pgrp (proc_stat_list_t pp, pid_t pgrp, - proc_stat_t **proc_stats, unsigned *num_procs) +proc_stat_list_add_pgrp (struct proc_stat_list *pp, pid_t pgrp, + struct proc_stat ***proc_stats, unsigned *num_procs) { return proc_stat_list_add_id_fn_pids (pp, pgrp, proc_getpgrppids, @@ -338,22 +339,22 @@ proc_stat_list_add_pgrp (proc_stat_list_t pp, pid_t pgrp, /* ---------------------------------------------------------------- */ -/* Try to set FLAGS in each proc_stat_t in PP (but they may still not be set +/* Try to set FLAGS in each proc_stat in PP (but they may still not be set -- you have to check). If a fatal error occurs, the error code is returned, otherwise 0. */ error_t -proc_stat_list_set_flags(proc_stat_list_t pp, ps_flags_t flags) +proc_stat_list_set_flags (struct proc_stat_list *pp, ps_flags_t flags) { unsigned nprocs = pp->num_procs; - proc_stat_t *procs = pp->proc_stats; + struct proc_stat **procs = pp->proc_stats; while (nprocs-- > 0) { - proc_stat_t ps = *procs++; + struct proc_stat *ps = *procs++; - if (!proc_stat_has(ps, flags)) + if (!proc_stat_has (ps, flags)) { - error_t err = proc_stat_set_flags(ps, flags); + error_t err = proc_stat_set_flags (ps, flags); if (err) return err; } @@ -364,25 +365,25 @@ proc_stat_list_set_flags(proc_stat_list_t pp, ps_flags_t flags) /* ---------------------------------------------------------------- */ -/* Destructively modify PP to only include proc_stat_t's for which the - function PREDICATE returns true; if INVERT is true, only proc_stat_t's for +/* Destructively modify PP to only include proc_stats for which the + function PREDICATE returns true; if INVERT is true, only proc_stats for which PREDICATE returns false are kept. FLAGS is the set of pstat_flags that PREDICATE requires be set as precondition. Regardless of the value - of INVERT, all proc_stat_t's for which the predicate's preconditions can't + of INVERT, all proc_stats for which the predicate's preconditions can't be satisfied are kept. If a fatal error occurs, the error code is returned, it returns 0. */ error_t -proc_stat_list_filter1(proc_stat_list_t pp, - bool (*predicate)(proc_stat_t ps), ps_flags_t flags, - bool invert) +proc_stat_list_filter1(struct proc_stat_list *pp, + int (*predicate)(struct proc_stat *ps), ps_flags_t flags, + int invert) { unsigned which = 0; unsigned num_procs = pp->num_procs; - proc_stat_t *procs = pp->proc_stats; + struct proc_stat **procs = pp->proc_stats; /* We compact the proc array as we filter, and KEPT points to end of the compacted part that we've already processed. */ - proc_stat_t *kept = procs; - error_t err = proc_stat_list_set_flags(pp, flags); + struct proc_stat **kept = procs; + error_t err = proc_stat_list_set_flags (pp, flags); if (err) return err; @@ -391,12 +392,12 @@ proc_stat_list_filter1(proc_stat_list_t pp, while (which < num_procs) { - proc_stat_t ps = procs[which++]; + struct proc_stat *ps = procs[which++]; /* See if we should keep PS; if PS doesn't satisfy the set of flags we need, we don't attempt to call PREDICATE at all, and keep PS. */ - if (!proc_stat_has(ps, flags) || !!predicate(ps) != invert) + if (!proc_stat_has(ps, flags) || !!predicate (ps) != invert) *kept++ = ps; /* ... otherwise implicitly delete PS from PP by not putting it in the KEPT sequence. */ @@ -407,19 +408,20 @@ proc_stat_list_filter1(proc_stat_list_t pp, return 0; } -/* Destructively modify PP to only include proc_stat_t's for which the +/* Destructively modify PP to only include proc_stats for which the predicate function in FILTER returns true; if INVERT is true, only - proc_stat_t's for which the predicate returns false are kept. Regardless - of the value of INVERT, all proc_stat_t's for which the predicate's + proc_stats for which the predicate returns false are kept. Regardless + of the value of INVERT, all proc_stats for which the predicate's preconditions can't be satisfied are kept. If a fatal error occurs, the error code is returned, it returns 0. */ error_t -proc_stat_list_filter(proc_stat_list_t pp, ps_filter_t filter, bool invert) +proc_stat_list_filter (struct proc_stat_list *pp, + const struct ps_filter *filter, int invert) { return proc_stat_list_filter1(pp, - ps_filter_predicate(filter), - ps_filter_needs(filter), + ps_filter_predicate (filter), + ps_filter_needs (filter), invert); } @@ -430,27 +432,28 @@ proc_stat_list_filter(proc_stat_list_t pp, ps_filter_t filter, bool invert) opposite order. If a fatal error occurs, the error code is returned, it returns 0. */ error_t -proc_stat_list_sort1(proc_stat_list_t pp, - ps_getter_t getter, - int (*cmp_fn)(proc_stat_t ps1, proc_stat_t ps2, - ps_getter_t getter), - bool reverse) +proc_stat_list_sort1 (struct proc_stat_list *pp, + const struct ps_getter *getter, + int (*cmp_fn)(struct proc_stat *ps1, + struct proc_stat *ps2, + const struct ps_getter *getter), + int reverse) { - int needs = ps_getter_needs(getter); - proc_stat_t *procs = pp->proc_stats; - error_t err = proc_stat_list_set_flags(pp, needs); + int needs = ps_getter_needs (getter); + struct proc_stat **procs = pp->proc_stats; + error_t err = proc_stat_list_set_flags (pp, needs); /* Lessp is a nested function so it may use state variables from proc_stat_list_sort1, which qsort gives no other way of passing in. */ - int lessp(const void *p1, const void *p2) + int lessp (const void *p1, const void *p2) { - proc_stat_t ps1 = *(proc_stat_t *)p1; - proc_stat_t ps2 = *(proc_stat_t *)p2; - bool is_th_1 = proc_stat_is_thread(ps1); - bool is_th_2 = proc_stat_is_thread(ps2); + struct proc_stat *ps1 = *(struct proc_stat **)p1; + struct proc_stat *ps2 = *(struct proc_stat **)p2; + int is_th_1 = proc_stat_is_thread (ps1); + int is_th_2 = proc_stat_is_thread (ps2); if (!is_th_1 || !is_th_2 - || proc_stat_thread_origin(ps1) != proc_stat_thread_origin(ps2)) + || proc_stat_thread_origin(ps1) != proc_stat_thread_origin (ps2)) /* Compare the threads' origins to keep them ordered after their respective processes. The exception is when they're both from the same process, in which case we want to compare them directly so that @@ -460,27 +463,27 @@ proc_stat_list_sort1(proc_stat_list_t pp, order). */ { if (is_th_1) - ps1 = proc_stat_thread_origin(ps1); + ps1 = proc_stat_thread_origin (ps1); if (is_th_2) - ps2 = proc_stat_thread_origin(ps2); + ps2 = proc_stat_thread_origin (ps2); } - if (ps1 == ps2 || !proc_stat_has(ps1, needs) || !proc_stat_has(ps2, needs)) + if (ps1 == ps2 || !proc_stat_has(ps1, needs) || !proc_stat_has (ps2, needs)) /* If we're comparing a thread with it's process (and so the thread's been replaced by the process), or we can't call CMP_FN on either - proc_stat_t due to lack of the necessary preconditions, then compare + proc_stat due to lack of the necessary preconditions, then compare their original positions, to retain the same order. */ return p1 - p2; else if (reverse) - return cmp_fn(ps2, ps1, getter); + return cmp_fn (ps2, ps1, getter); else - return cmp_fn(ps1, ps2, getter); + return cmp_fn (ps1, ps2, getter); } if (err) return err; - qsort((void *)procs, (size_t)pp->num_procs, sizeof(proc_stat_t), lessp); + qsort((void *)procs, (size_t)pp->num_procs, sizeof (struct proc_stat *), lessp); return 0; } @@ -490,14 +493,15 @@ proc_stat_list_sort1(proc_stat_list_t pp, key, EINVAL is returned. If a fatal error occurs the error code is returned. Otherwise, 0 is returned. */ error_t -proc_stat_list_sort(proc_stat_list_t pp, ps_fmt_spec_t key, bool reverse) +proc_stat_list_sort (struct proc_stat_list *pp, + struct ps_fmt_spec *key, int reverse) { - int (*cmp_fn)() = ps_fmt_spec_compare_fn(key); + int (*cmp_fn)() = ps_fmt_spec_compare_fn (key); if (cmp_fn == NULL) return EINVAL; else return - proc_stat_list_sort1(pp, ps_fmt_spec_getter(key), cmp_fn, reverse); + proc_stat_list_sort1 (pp, ps_fmt_spec_getter (key), cmp_fn, reverse); } /* ---------------------------------------------------------------- */ @@ -506,11 +510,12 @@ proc_stat_list_sort(proc_stat_list_t pp, ps_fmt_spec_t key, bool reverse) STREAM, separated by newlines (and with a terminating newline). If a fatal error occurs, the error code is returned, otherwise 0. */ error_t -proc_stat_list_fmt (proc_stat_list_t pp, ps_fmt_t fmt, ps_stream_t stream) +proc_stat_list_fmt (struct proc_stat_list *pp, struct ps_fmt *fmt, + struct ps_stream *stream) { unsigned nprocs = pp->num_procs; - proc_stat_t *procs = pp->proc_stats; - error_t err = proc_stat_list_set_flags(pp, ps_fmt_needs(fmt)); + struct proc_stat **procs = pp->proc_stats; + error_t err = proc_stat_list_set_flags(pp, ps_fmt_needs (fmt)); while (!err && nprocs-- > 0) { @@ -524,22 +529,22 @@ proc_stat_list_fmt (proc_stat_list_t pp, ps_fmt_t fmt, ps_stream_t stream) /* ---------------------------------------------------------------- */ -/* Modifies FLAGS to be the subset which can't be set in any proc_stat_t in - PP (and as a side-effect, adds as many bits from FLAGS to each proc_stat_t +/* Modifies FLAGS to be the subset which can't be set in any proc_stat in + PP (and as a side-effect, adds as many bits from FLAGS to each proc_stat as possible). If a fatal error occurs, the error code is returned, otherwise 0. */ error_t -proc_stat_list_find_bogus_flags(proc_stat_list_t pp, ps_flags_t *flags) +proc_stat_list_find_bogus_flags (struct proc_stat_list *pp, ps_flags_t *flags) { unsigned nprocs = pp->num_procs; - proc_stat_t *procs = pp->proc_stats; - error_t err = proc_stat_list_set_flags(pp, *flags); + struct proc_stat **procs = pp->proc_stats; + error_t err = proc_stat_list_set_flags (pp, *flags); if (err) return err; while (nprocs-- > 0 && *flags != 0) - *flags &= ~proc_stat_flags(*procs++); + *flags &= ~proc_stat_flags (*procs++); return 0; } @@ -552,9 +557,9 @@ proc_stat_list_find_bogus_flags(proc_stat_list_t pp, ps_flags_t *flags) order of the thread entries themselves may change. If a fatal error occurs, the error code is returned, otherwise 0. */ error_t -proc_stat_list_add_threads(proc_stat_list_t pp) +proc_stat_list_add_threads (struct proc_stat_list *pp) { - error_t err = proc_stat_list_set_flags(pp, PSTAT_NUM_THREADS); + error_t err = proc_stat_list_set_flags (pp, PSTAT_NUM_THREADS); if (err) return err; @@ -562,37 +567,37 @@ proc_stat_list_add_threads(proc_stat_list_t pp) { int new_entries = 0; int nprocs = pp->num_procs; - proc_stat_t *procs = pp->proc_stats; + struct proc_stat **procs = pp->proc_stats; /* First, count the number of threads that will be added. */ while (nprocs-- > 0) { - proc_stat_t ps = *procs++; - if (proc_stat_has(ps, PSTAT_NUM_THREADS)) - new_entries += proc_stat_num_threads(ps); + struct proc_stat *ps = *procs++; + if (proc_stat_has (ps, PSTAT_NUM_THREADS)) + new_entries += proc_stat_num_threads (ps); } /* And make room for them... */ - err = proc_stat_list_grow(pp, new_entries); + err = proc_stat_list_grow (pp, new_entries); if (err) return err; else /* Now add thread entries for every existing entry in PP; we go through them backwards so we can do it in place. */ { - proc_stat_t *end = pp->proc_stats + pp->num_procs + new_entries; + struct proc_stat **end = pp->proc_stats + pp->num_procs + new_entries; nprocs = pp->num_procs; procs = pp->proc_stats + nprocs; while (nprocs-- > 0) { - proc_stat_t ps = *--procs; - if (proc_stat_has(ps, PSTAT_NUM_THREADS)) + struct proc_stat *ps = *--procs; + if (proc_stat_has (ps, PSTAT_NUM_THREADS)) { - int nthreads = proc_stat_num_threads(ps); + int nthreads = proc_stat_num_threads (ps); while (nthreads-- > 0) - proc_stat_thread_create(ps, nthreads, --end); + proc_stat_thread_create (ps, nthreads, --end); } *--end = ps; } @@ -605,11 +610,11 @@ proc_stat_list_add_threads(proc_stat_list_t pp) } error_t -proc_stat_list_remove_threads(proc_stat_list_t pp) +proc_stat_list_remove_threads (struct proc_stat_list *pp) { - bool is_thread(proc_stat_t ps) + int is_thread (struct proc_stat *ps) { - return proc_stat_is_thread(ps); + return proc_stat_is_thread (ps); } return proc_stat_list_filter1(pp, is_thread, 0, FALSE); } @@ -620,10 +625,10 @@ proc_stat_list_remove_threads(proc_stat_list_t pp) value, then the iteration is stopped, and the value is returned immediately; otherwise, 0 is returned. */ int -proc_stat_list_for_each (proc_stat_list_t pp, int (*fn)(proc_stat_t ps)) +proc_stat_list_for_each (struct proc_stat_list *pp, int (*fn)(struct proc_stat *ps)) { unsigned nprocs = pp->num_procs; - proc_stat_t *procs = pp->proc_stats; + struct proc_stat **procs = pp->proc_stats; while (nprocs-- > 0) { @@ -638,19 +643,20 @@ proc_stat_list_for_each (proc_stat_list_t pp, int (*fn)(proc_stat_t ps)) /* ---------------------------------------------------------------- */ /* Returns true if SPEC is `nominal' in every entry in PP. */ -bool -proc_stat_list_spec_nominal (proc_stat_list_t pp, ps_fmt_spec_t spec) +int +proc_stat_list_spec_nominal (struct proc_stat_list *pp, + struct ps_fmt_spec *spec) { - bool (*nominal_fn)(proc_stat_t ps, ps_getter_t getter) = + int (*nominal_fn)(struct proc_stat *ps, const struct ps_getter *getter) = ps_fmt_spec_nominal_fn (spec); if (nominal_fn == NULL) return FALSE; else { - ps_getter_t getter = ps_fmt_spec_getter (spec); + const struct ps_getter *getter = ps_fmt_spec_getter (spec); ps_flags_t needs = ps_getter_needs (getter); - int interesting (proc_stat_t ps) + int interesting (struct proc_stat *ps) { return proc_stat_has (ps, needs) && !(*nominal_fn)(ps, getter); } diff --git a/libps/procstat.c b/libps/procstat.c index a319edd9..6c162ced 100644 --- a/libps/procstat.c +++ b/libps/procstat.c @@ -1,4 +1,4 @@ -/* The type proc_stat_t, which holds information about a hurd process. +/* The proc_stat type, which holds information about a hurd process. Copyright (C) 1995, 1996 Free Software Foundation, Inc. @@ -38,7 +38,7 @@ char *proc_stat_state_tags = "TZRHDSIN<u+slfmpoxwg"; /* Return the PSTAT_STATE_ bits describing the state of an individual thread, from that thread's thread_basic_info_t struct */ static int -thread_state(thread_basic_info_t bi) +thread_state (thread_basic_info_t bi) { int state = 0; @@ -170,7 +170,7 @@ merge_procinfo (process_t server, pid_t pid, /* Returns FLAGS augmented with any other flags that are necessary preconditions to setting them. */ static ps_flags_t -add_preconditions (ps_flags_t flags, ps_context_t context) +add_preconditions (ps_flags_t flags, struct ps_context *context) { /* Implement any inter-flag dependencies: if the new flags in FLAGS depend on some other set of flags to be set, make sure those are also in FLAGS. */ @@ -216,7 +216,7 @@ add_preconditions (ps_flags_t flags, ps_context_t context) PS's msg port. For this routine to work correctly, PS's flags should contain as many flags in PSTAT_TEST_MSGPORT as possible. */ static int -should_suppress_msgport (proc_stat_t ps) +should_suppress_msgport (struct proc_stat *ps) { ps_flags_t have = ps->flags; @@ -259,7 +259,7 @@ summarize_thread_basic_info (struct procinfo *pi) if (!tbi) return 0; - bzero(tbi, sizeof *tbi); + bzero (tbi, sizeof *tbi); for (i = 0; i < pi->nthreads; i++) if (! pi->threadinfos[i].died) @@ -346,7 +346,7 @@ summarize_thread_sched_info (struct procinfo *pi) if (!tsi) return 0; - bzero(tsi, sizeof *tsi); + bzero (tsi, sizeof *tsi); for (i = 0; i < pi->nthreads; i++) if (! pi->threadinfos[i].died) @@ -380,7 +380,7 @@ summarize_thread_states (struct procinfo *pi) /* The union of all thread state bits... */ for (i = 0; i < pi->nthreads; i++) if (! pi->threadinfos[i].died) - state |= thread_state(&pi->threadinfos[i].pis_bi); + state |= thread_state (&pi->threadinfos[i].pis_bi); return state; } @@ -474,13 +474,13 @@ clone (void *src, size_t size) field before using new fields, as something might have failed. Returns a system error code if a fatal error occurred, or 0 if none. */ error_t -proc_stat_set_flags (proc_stat_t ps, ps_flags_t flags) +proc_stat_set_flags (struct proc_stat *ps, ps_flags_t flags) { ps_flags_t have = ps->flags; /* flags set in ps */ ps_flags_t need; /* flags not set in ps, but desired to be */ ps_flags_t no_msgport_flags; /* a version of FLAGS for use when we can't use the msg port. */ - process_t server = ps_context_server(ps->context); + process_t server = ps_context_server (ps->context); /* Turn off use of the msg port if we decide somewhere along the way that it's hosed. */ @@ -532,7 +532,7 @@ proc_stat_set_flags (proc_stat_t ps, ps_flags_t flags) port if a call to it times out. It also implies a precondition of PSTAT_MSGPORT. */ #define MP_MGET(flag, precond, call) \ - ({ error_t err = MGET(flag, (precond) | PSTAT_MSGPORT, call); \ + ({ error_t err = MGET (flag, (precond) | PSTAT_MSGPORT, call); \ if (err) suppress_msgport (); \ err; \ }) @@ -596,7 +596,7 @@ proc_stat_set_flags (proc_stat_t ps, ps_flags_t flags) else /* For a thread, we get use the proc_info from the containing process. */ { - proc_stat_t origin = ps->thread_origin; + struct proc_stat *origin = ps->thread_origin; ps_flags_t oflags = need & PSTAT_PROCINFO_THREAD; proc_stat_set_flags (origin, oflags); @@ -657,18 +657,18 @@ proc_stat_set_flags (proc_stat_t ps, ps_flags_t flags) suppress_msgport (); /* The process's libc msg port (see <hurd/msg.defs>). */ - MGET(PSTAT_MSGPORT, PSTAT_PID, proc_getmsgport(server, ps->pid, &ps->msgport)); + MGET(PSTAT_MSGPORT, PSTAT_PID, proc_getmsgport (server, ps->pid, &ps->msgport)); /* The process's process port. */ - MGET(PSTAT_PROCESS, PSTAT_PID, proc_pid2proc(server, ps->pid, &ps->process)); + MGET(PSTAT_PROCESS, PSTAT_PID, proc_pid2proc (server, ps->pid, &ps->process)); /* The process's task port. */ - MGET(PSTAT_TASK, PSTAT_PID, proc_pid2task(server, ps->pid, &ps->task)); + MGET(PSTAT_TASK, PSTAT_PID, proc_pid2task (server, ps->pid, &ps->task)); /* VM statistics for the task. See <mach/task_info.h>. */ if ((need & PSTAT_TASK_EVENTS) && (have & PSTAT_TASK)) { ps->task_events_info = &ps->task_events_info_buf; ps->task_events_info_size = TASK_EVENTS_INFO_COUNT; - if (task_info(ps->task, TASK_EVENTS_INFO, + if (task_info (ps->task, TASK_EVENTS_INFO, (task_info_t)&ps->task_events_info, &ps->task_events_info_size) == 0) @@ -676,8 +676,8 @@ proc_stat_set_flags (proc_stat_t ps, ps_flags_t flags) } /* Get the process's exec flags (see <hurd/hurd_types.h>). */ - MP_MGET(PSTAT_EXEC_FLAGS, PSTAT_TASK, - msg_get_exec_flags(ps->msgport, ps->task, &ps->exec_flags)); + MP_MGET (PSTAT_EXEC_FLAGS, PSTAT_TASK, + msg_get_exec_flags (ps->msgport, ps->task, &ps->exec_flags)); /* PSTAT_STATE_ bits for the process and all its threads. */ if ((need & PSTAT_STATE) && (have & (PSTAT_PROC_INFO | PSTAT_THREAD_BASIC))) @@ -728,7 +728,7 @@ proc_stat_set_flags (proc_stat_t ps, ps_flags_t flags) if ((need & PSTAT_ARGS) && (have & PSTAT_PID)) { ps->args_len = 0; - if (proc_getprocargs(server, ps->pid, &ps->args, &ps->args_len)) + if (proc_getprocargs (server, ps->pid, &ps->args, &ps->args_len)) ps->args_len = 0; else have |= PSTAT_ARGS; @@ -737,24 +737,24 @@ proc_stat_set_flags (proc_stat_t ps, ps_flags_t flags) /* The ctty id port; note that this is just a magic cookie; we use it to fetch a port to the actual terminal -- it's not useful for much else. */ - MP_MGET(PSTAT_CTTYID, PSTAT_TASK, - msg_get_init_port(ps->msgport, ps->task, + MP_MGET (PSTAT_CTTYID, PSTAT_TASK, + msg_get_init_port (ps->msgport, ps->task, INIT_PORT_CTTYID, &ps->cttyid)); /* A port to the process's current working directory. */ - MP_MGET(PSTAT_CWDIR, PSTAT_TASK, - msg_get_init_port(ps->msgport, ps->task, + MP_MGET (PSTAT_CWDIR, PSTAT_TASK, + msg_get_init_port (ps->msgport, ps->task, INIT_PORT_CWDIR, &ps->cwdir)); /* The process's auth port, which we can use to determine who the process is authenticated as. */ - MP_MGET(PSTAT_AUTH, PSTAT_TASK, - msg_get_init_port(ps->msgport, ps->task, INIT_PORT_AUTH, &ps->auth)); + MP_MGET (PSTAT_AUTH, PSTAT_TASK, + msg_get_init_port (ps->msgport, ps->task, INIT_PORT_AUTH, &ps->auth)); /* The process's umask, which controls which protection bits won't be set when creating a file. */ - MP_MGET(PSTAT_UMASK, PSTAT_TASK, - msg_get_init_int(ps->msgport, ps->task, INIT_UMASK, &ps->umask)); + MP_MGET (PSTAT_UMASK, PSTAT_TASK, + msg_get_init_int (ps->msgport, ps->task, INIT_UMASK, &ps->umask)); if ((need & PSTAT_OWNER_UID) && (have & PSTAT_PROC_INFO)) { @@ -765,20 +765,20 @@ proc_stat_set_flags (proc_stat_t ps, ps_flags_t flags) have |= PSTAT_OWNER_UID; } - /* A ps_user_t object for the process's owner. */ + /* A ps_user object for the process's owner. */ if ((need & PSTAT_OWNER) && (have & PSTAT_OWNER_UID)) if (ps->owner_uid < 0) { ps->owner = 0; have |= PSTAT_OWNER; } - else if (! ps_context_find_user(ps->context, ps->owner_uid, &ps->owner)) + else if (! ps_context_find_user (ps->context, ps->owner_uid, &ps->owner)) have |= PSTAT_OWNER; - /* A ps_tty_t for the process's controlling terminal, or NULL if it + /* A ps_tty for the process's controlling terminal, or NULL if it doesn't have one. */ if ((need & PSTAT_TTY) && (have & PSTAT_CTTYID)) - if (ps_context_find_tty_by_cttyid(ps->context, ps->cttyid, &ps->tty) == 0) + if (ps_context_find_tty_by_cttyid (ps->context, ps->cttyid, &ps->tty) == 0) have |= PSTAT_TTY; /* Update PS's flag state. We haven't tried user flags yet, so don't mark @@ -803,8 +803,8 @@ proc_stat_set_flags (proc_stat_t ps, ps_flags_t flags) /* ---------------------------------------------------------------- */ /* Discard PS and any resources it holds. */ void -_proc_stat_free(ps) - proc_stat_t ps; +_proc_stat_free (ps) + struct proc_stat *ps; { if (ps->context->user_hooks && ps->context->user_hooks->cleanup) /* Free any user state. */ @@ -813,7 +813,7 @@ _proc_stat_free(ps) /* Free the mach port PORT if FLAG is set in PS's flags. */ #define MFREEPORT(flag, port) \ ((ps->flags & (flag)) \ - ? mach_port_deallocate(mach_task_self(), (ps->port)) : 0) + ? mach_port_deallocate(mach_task_self (), (ps->port)) : 0) /* If FLAG is set in PS's flags, vm_deallocate MEM, consisting of SIZE elements of type ELTYPE, *unless* MEM == SBUF, which usually means @@ -821,38 +821,38 @@ _proc_stat_free(ps) memory. */ #define MFREEVM(flag, mem, size, sbuf, eltype) \ (((ps->flags & (flag)) && ps->mem != sbuf) \ - ? (VMFREE(ps->mem, ps->size * sizeof(eltype))) : 0) + ? (VMFREE(ps->mem, ps->size * sizeof (eltype))) : 0) /* if FLAG is set in PS's flags, free the malloc'd memory MEM. */ #define MFREEM(flag, mem) ((ps->flags & (flag)) ? free (ps->mem) : 0) /* free PS's ports */ - MFREEPORT(PSTAT_PROCESS, process); - MFREEPORT(PSTAT_TASK, task); - MFREEPORT(PSTAT_MSGPORT, msgport); - MFREEPORT(PSTAT_CTTYID, cttyid); - MFREEPORT(PSTAT_CWDIR, cwdir); - MFREEPORT(PSTAT_AUTH, auth); + MFREEPORT (PSTAT_PROCESS, process); + MFREEPORT (PSTAT_TASK, task); + MFREEPORT (PSTAT_MSGPORT, msgport); + MFREEPORT (PSTAT_CTTYID, cttyid); + MFREEPORT (PSTAT_CWDIR, cwdir); + MFREEPORT (PSTAT_AUTH, auth); /* free any allocated memory pointed to by PS */ - MFREEVM(PSTAT_PROCINFO, proc_info, proc_info_size, 0, char); - MFREEM(PSTAT_THREAD_BASIC, thread_basic_info); - MFREEM(PSTAT_THREAD_SCHED, thread_sched_info); - MFREEVM(PSTAT_ARGS, args, args_len, 0, char); - MFREEVM(PSTAT_TASK_EVENTS, + MFREEVM (PSTAT_PROCINFO, proc_info, proc_info_size, 0, char); + MFREEM (PSTAT_THREAD_BASIC, thread_basic_info); + MFREEM (PSTAT_THREAD_SCHED, thread_sched_info); + MFREEVM (PSTAT_ARGS, args, args_len, 0, char); + MFREEVM (PSTAT_TASK_EVENTS, task_events_info, task_events_info_size, &ps->task_events_info_buf, char); - FREE(ps); + FREE (ps); } -/* Returns in PS a new proc_stat_t for the process PID at the process context +/* Returns in PS a new proc_stat for the process PID at the process context CONTEXT. If a memory allocation error occurs, ENOMEM is returned, otherwise 0. */ error_t -_proc_stat_create(pid_t pid, ps_context_t context, proc_stat_t *ps) +_proc_stat_create (pid_t pid, struct ps_context *context, struct proc_stat **ps) { - *ps = NEW(struct proc_stat); + *ps = NEW (struct proc_stat); if (*ps == NULL) return ENOMEM; @@ -867,17 +867,17 @@ _proc_stat_create(pid_t pid, ps_context_t context, proc_stat_t *ps) /* ---------------------------------------------------------------- */ -/* Returns in THREAD_PS a proc_stat_t for the Nth thread in the proc_stat_t +/* Returns in THREAD_PS a proc_stat for the Nth thread in the proc_stat PS (N should be between 0 and the number of threads in the process). The - resulting proc_stat_t isn't fully functional -- most flags can't be set in + resulting proc_stat isn't fully functional -- most flags can't be set in it. It also contains a pointer to PS, so PS shouldn't be freed without also freeing THREAD_PS. If N was out of range, EINVAL is returned. If a memory allocation error occured, ENOMEM is returned. Otherwise, 0 is returned. */ error_t -proc_stat_thread_create(proc_stat_t ps, unsigned index, proc_stat_t *thread_ps) +proc_stat_thread_create (struct proc_stat *ps, unsigned index, struct proc_stat **thread_ps) { - error_t err = proc_stat_set_flags(ps, PSTAT_NUM_THREADS); + error_t err = proc_stat_set_flags (ps, PSTAT_NUM_THREADS); if (err) return err; @@ -885,7 +885,7 @@ proc_stat_thread_create(proc_stat_t ps, unsigned index, proc_stat_t *thread_ps) return EINVAL; else { - proc_stat_t tps = NEW(struct proc_stat); + struct proc_stat *tps = NEW (struct proc_stat); if (tps == NULL) return ENOMEM; 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; diff --git a/libps/user.c b/libps/user.c index 2a4f7057..940b13d1 100644 --- a/libps/user.c +++ b/libps/user.c @@ -1,6 +1,6 @@ -/* The type ps_user_t, for per-user info. +/* The ps_user type, for per-user 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> @@ -28,12 +28,12 @@ /* ---------------------------------------------------------------- */ -/* Create a ps_user_t for the user referred to by UID, returning it in U. +/* Create a ps_user for the user referred to by UID, returning it in U. If a memory allocation error occurs, ENOMEM is returned, otherwise 0. */ error_t -ps_user_create(uid_t uid, ps_user_t *u) +ps_user_create (uid_t uid, struct ps_user **u) { - *u = NEW(struct ps_user); + *u = NEW (struct ps_user); if (*u == NULL) return ENOMEM; @@ -45,18 +45,18 @@ ps_user_create(uid_t uid, ps_user_t *u) /* Free U and any resources it consumes. */ void -ps_user_free(ps_user_t u) +ps_user_free (struct ps_user *u) { if (u->passwd_state == PS_USER_PASSWD_OK) - free(u->storage); - free(u); + free (u->storage); + free (u); } /* ---------------------------------------------------------------- */ /* Returns the password file entry (struct passwd, from <pwd.h>) for the user referred to by U, or NULL if it can't be gotten. */ -struct passwd *ps_user_passwd(ps_user_t u) +struct passwd *ps_user_passwd (struct ps_user *u) { if (u->passwd_state == PS_USER_PASSWD_OK) return &u->passwd; @@ -64,19 +64,19 @@ struct passwd *ps_user_passwd(ps_user_t u) return NULL; else { - struct passwd *pw = getpwuid(u->uid); + struct passwd *pw = getpwuid (u->uid); if (pw != NULL) { int needed = 0; #define COUNT(field) if (pw->field != NULL) (needed += strlen(pw->field) + 1) - COUNT(pw_name); - COUNT(pw_passwd); - COUNT(pw_gecos); - COUNT(pw_dir); - COUNT(pw_shell); + COUNT (pw_name); + COUNT (pw_passwd); + COUNT (pw_gecos); + COUNT (pw_dir); + COUNT (pw_shell); - u->storage = malloc(needed); + u->storage = malloc (needed); if (u->storage != NULL) { char *p = u->storage; @@ -86,12 +86,12 @@ struct passwd *ps_user_passwd(ps_user_t u) storage that pw currently points to. */ #define COPY(field) \ if (pw->field != NULL) \ - strcpy(p, pw->field), (pw->field = p), (p += strlen(p) + 1) - COPY(pw_name); - COPY(pw_passwd); - COPY(pw_gecos); - COPY(pw_dir); - COPY(pw_shell); + strcpy(p, pw->field), (pw->field = p), (p += strlen (p) + 1) + COPY (pw_name); + COPY (pw_passwd); + COPY (pw_gecos); + COPY (pw_dir); + COPY (pw_shell); u->passwd = *pw; u->passwd_state = PS_USER_PASSWD_OK; @@ -107,9 +107,9 @@ struct passwd *ps_user_passwd(ps_user_t u) /* Returns the user name for the user referred to by U, or NULL if it can't be gotten. */ -char *ps_user_name(ps_user_t u) +char *ps_user_name (struct ps_user *u) { - struct passwd *pw = ps_user_passwd(u); + struct passwd *pw = ps_user_passwd (u); if (pw) return pw->pw_name; else diff --git a/libps/write.c b/libps/write.c index 8282113e..3c57f94f 100644 --- a/libps/write.c +++ b/libps/write.c @@ -34,9 +34,9 @@ about it is what caused the flush), and update *BEG to be NEW. True is returned if a write error occurs. */ static int -flush (char **beg, char *new, FILE *s) +flush (const char **beg, const char *new, FILE *s) { - char *b = *beg; + const char *b = *beg; if (new > b) *beg = new; if (new - 1 > b) @@ -52,10 +52,10 @@ flush (char **beg, char *new, FILE *s) /* Write T to S, up to MAX characters (unless MAX == 0), making sure not to write any unprintable characters. */ error_t -noise_write (unsigned char *t, ssize_t max, FILE *s) +noise_write (const unsigned char *t, ssize_t max, FILE *s) { int ch; - char *ok = t; + const char *ok = t; size_t len = 0; while ((ch = *t++) && (max < 0 || len < max)) @@ -86,7 +86,7 @@ noise_write (unsigned char *t, ssize_t max, FILE *s) /* Return what noise_write would write with arguments of T and MAX. */ size_t -noise_len (char *t, ssize_t max) +noise_len (const char *t, ssize_t max) { int ch; size_t len = 0; @@ -111,7 +111,7 @@ noise_len (char *t, ssize_t max) length of STRING, then write all of it; if MAX_LEN == -1, then write all of STRING regardless). */ error_t -ps_stream_write (ps_stream_t stream, char *string, ssize_t max_len) +ps_stream_write (struct ps_stream *stream, const char *string, ssize_t max_len) { size_t len = noise_len (string, max_len); @@ -149,7 +149,7 @@ ps_stream_write (ps_stream_t stream, char *string, ssize_t max_len) consumed if possible. If an error occurs, the error code is returned, otherwise 0. */ error_t -ps_stream_space (ps_stream_t stream, ssize_t num) +ps_stream_space (struct ps_stream *stream, ssize_t num) { stream->spaces += num; return 0; @@ -159,14 +159,14 @@ ps_stream_space (ps_stream_t stream, ssize_t num) be at least WIDTH characters wide (the absolute value of WIDTH is used). If an error occurs, the error code is returned, otherwise 0. */ error_t -ps_stream_pad (ps_stream_t stream, ssize_t sofar, ssize_t width) +ps_stream_pad (struct ps_stream *stream, ssize_t sofar, ssize_t width) { return ps_stream_space (stream, ABS (width) - sofar); } /* Write a newline to STREAM, resetting its position to zero. */ error_t -ps_stream_newline (ps_stream_t stream) +ps_stream_newline (struct ps_stream *stream) { putc ('\n', stream->stream); stream->spaces = 0; @@ -179,8 +179,9 @@ ps_stream_newline (ps_stream_t stream) side, otherwise on the right side. If an error occurs, the error code is returned, otherwise 0. */ error_t -_ps_stream_write_field (ps_stream_t stream, char *buf, size_t max_width, - int width) +_ps_stream_write_field (struct ps_stream *stream, + const char *buf, size_t max_width, + int width) { error_t err; size_t len; @@ -213,14 +214,15 @@ _ps_stream_write_field (ps_stream_t stream, char *buf, size_t max_width, side, otherwise on the right side. If an error occurs, the error code is returned, otherwise 0. */ error_t -ps_stream_write_field (ps_stream_t stream, char *buf, int width) +ps_stream_write_field (struct ps_stream *stream, const char *buf, int width) { return _ps_stream_write_field (stream, buf, -1, width); } /* Like ps_stream_write_field, but truncates BUF to make it fit into WIDTH. */ error_t -ps_stream_write_trunc_field (ps_stream_t stream, char *buf, int width) +ps_stream_write_trunc_field (struct ps_stream *stream, + const char *buf, int width) { return _ps_stream_write_field (stream, buf, width ? ABS (width) : -1, width); } @@ -230,16 +232,16 @@ ps_stream_write_trunc_field (ps_stream_t stream, char *buf, int width) 0, then on the left side, otherwise on the right side. If an error occurs, the error code is returned, otherwise 0. */ error_t -ps_stream_write_int_field (ps_stream_t stream, int value, int width) +ps_stream_write_int_field (struct ps_stream *stream, int value, int width) { char buf[20]; - sprintf(buf, "%d", value); + sprintf (buf, "%d", value); return ps_stream_write_field (stream, buf, width); } /* Create a stream outputing to DEST, and return it in STREAM, or an error. */ error_t -ps_stream_create (FILE *dest, ps_stream_t *stream) +ps_stream_create (FILE *dest, struct ps_stream **stream) { *stream = malloc (sizeof (struct ps_stream)); if (! *stream) @@ -252,7 +254,7 @@ ps_stream_create (FILE *dest, ps_stream_t *stream) /* Frees STREAM. The destination file is *not* closed. */ void -ps_stream_free (ps_stream_t stream) +ps_stream_free (struct ps_stream *stream) { free (stream); } |