Deleted Added
full compact
fmt.c (130895) fmt.c (130896)
1/*-
2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 20 unchanged lines hidden (view full) ---

29
30#if 0
31#ifndef lint
32static char sccsid[] = "@(#)fmt.c 8.4 (Berkeley) 4/15/94";
33#endif
34#endif
35
36#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1992, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 20 unchanged lines hidden (view full) ---

29
30#if 0
31#ifndef lint
32static char sccsid[] = "@(#)fmt.c 8.4 (Berkeley) 4/15/94";
33#endif
34#endif
35
36#include <sys/cdefs.h>
37__FBSDID("$FreeBSD: head/bin/ps/fmt.c 130895 2004-06-22 02:06:42Z gad $");
37__FBSDID("$FreeBSD: head/bin/ps/fmt.c 130896 2004-06-22 02:15:58Z gad $");
38
39#include <sys/types.h>
40#include <sys/time.h>
41#include <sys/resource.h>
42
43#include <err.h>
44#include <limits.h>
45#include <stdio.h>
46#include <stdint.h>
47#include <stdlib.h>
48#include <string.h>
49#include <unistd.h>
50#include <vis.h>
51
52#include "ps.h"
53
38
39#include <sys/types.h>
40#include <sys/time.h>
41#include <sys/resource.h>
42
43#include <err.h>
44#include <limits.h>
45#include <stdio.h>
46#include <stdint.h>
47#include <stdlib.h>
48#include <string.h>
49#include <unistd.h>
50#include <vis.h>
51
52#include "ps.h"
53
54static const char *cmdpart(const char *);
55static const char *shquote(const char **);
54static char *cmdpart(char *);
55static char *shquote(char **);
56
56
57static const char *
58shquote(const char **argv)
57static char *
58shquote(char **argv)
59{
60 long arg_max;
61 static size_t buf_size;
62 size_t len;
59{
60 long arg_max;
61 static size_t buf_size;
62 size_t len;
63 const char **p, *src;
64 char *dst;
63 char **p, *dst, *src;
65 static char *buf = NULL;
66
67 if (buf == NULL) {
68 if ((arg_max = sysconf(_SC_ARG_MAX)) == -1)
69 errx(1, "sysconf _SC_ARG_MAX failed");
70 if (arg_max >= LONG_MAX / 4 || arg_max >= (long)(SIZE_MAX / 4))
71 errx(1, "sysconf _SC_ARG_MAX preposterously large");
72 buf_size = 4 * arg_max + 1;

--- 19 unchanged lines hidden (view full) ---

92 }
93 /* Chop off trailing space */
94 if (dst != buf && dst[-1] == ' ')
95 dst--;
96 *dst = '\0';
97 return (buf);
98}
99
64 static char *buf = NULL;
65
66 if (buf == NULL) {
67 if ((arg_max = sysconf(_SC_ARG_MAX)) == -1)
68 errx(1, "sysconf _SC_ARG_MAX failed");
69 if (arg_max >= LONG_MAX / 4 || arg_max >= (long)(SIZE_MAX / 4))
70 errx(1, "sysconf _SC_ARG_MAX preposterously large");
71 buf_size = 4 * arg_max + 1;

--- 19 unchanged lines hidden (view full) ---

91 }
92 /* Chop off trailing space */
93 if (dst != buf && dst[-1] == ' ')
94 dst--;
95 *dst = '\0';
96 return (buf);
97}
98
100static const char *
101cmdpart(const char *arg0)
99static char *
100cmdpart(char *arg0)
102{
101{
103 const char *cp;
102 char *cp;
104
105 return ((cp = strrchr(arg0, '/')) != NULL ? cp + 1 : arg0);
106}
107
108const char *
103
104 return ((cp = strrchr(arg0, '/')) != NULL ? cp + 1 : arg0);
105}
106
107const char *
109fmt_argv(const char **argv, const char *cmd, size_t maxlen)
108fmt_argv(char **argv, char *cmd, size_t maxlen)
110{
111 size_t len;
109{
110 size_t len;
112 const char *ap;
113 char *cp;
111 char *ap, *cp;
114
115 if (argv == NULL || argv[0] == NULL) {
116 if (cmd == NULL)
117 return ("");
118 ap = NULL;
119 len = maxlen + 3;
120 } else {
121 ap = shquote(argv);

--- 13 unchanged lines hidden ---
112
113 if (argv == NULL || argv[0] == NULL) {
114 if (cmd == NULL)
115 return ("");
116 ap = NULL;
117 len = maxlen + 3;
118 } else {
119 ap = shquote(argv);

--- 13 unchanged lines hidden ---