c99
This commit is contained in:
@@ -7,16 +7,17 @@
|
||||
#include <string.h>
|
||||
#include "procps.h"
|
||||
|
||||
#if 0
|
||||
/* output a string, converting unprintables to octal as we go, and stopping after
|
||||
processing max chars of output (accounting for expansion due to octal rep).
|
||||
*/
|
||||
unsigned print_str(FILE* file, char *s, unsigned max) {
|
||||
int i;
|
||||
unsigned print_str(FILE *restrict file, const char *restrict const s, unsigned max) {
|
||||
unsigned i;
|
||||
for (i=0; s[i] && i < max; i++)
|
||||
if (isprint(s[i]) || s[i] == ' ')
|
||||
fputc(s[i], file);
|
||||
else {
|
||||
if (max - i > 3) {
|
||||
if (max > i+3) {
|
||||
fprintf(file, "\\%03o", (unsigned char)s[i]);
|
||||
i += 3; /* 4 printed, but i counts one */
|
||||
} else
|
||||
@@ -24,19 +25,20 @@ unsigned print_str(FILE* file, char *s, unsigned max) {
|
||||
}
|
||||
return max - i;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* output an argv style NULL-terminated string list, converting unprintables
|
||||
to octal as we go, separating items of the list by 'sep' and stopping after
|
||||
processing max chars of output (accounting for expansion due to octal rep).
|
||||
*/
|
||||
unsigned print_strlist(FILE* file, char **strs, unsigned max) {
|
||||
int i, n;
|
||||
unsigned print_strlist(FILE *restrict file, const char *restrict const *restrict strs, unsigned max) {
|
||||
unsigned i, n;
|
||||
for (n=0; *strs && n < max; strs++) {
|
||||
for (i=0; strs[0][i] && n+i < max; i++)
|
||||
if (isprint(strs[0][i]) || strs[0][i] == ' ')
|
||||
fputc(strs[0][i], file);
|
||||
else {
|
||||
if (max-(n+i) > 3) {
|
||||
if (max > n+i+3) {
|
||||
fprintf(file, "\\%03o", (unsigned char)strs[0][i]);
|
||||
n += 3; /* 4 printed, but i counts one */
|
||||
} else
|
||||
|
||||
Reference in New Issue
Block a user