File: carefulputc.c

package info (click to toggle)
loop-aes-utils 2.12r-15%2Betch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 8,876 kB
  • ctags: 5,077
  • sloc: ansic: 46,163; sh: 11,326; makefile: 886; perl: 86; csh: 62; sed: 55
file content (26 lines) | stat: -rw-r--r-- 722 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/* putc() for use in write and wall (that sometimes are sgid tty) */
/* Avoid control characters in our locale, and also ASCII control characters.
   Note that the locale of the recipient is unknown. */
#include <stdio.h>
#include <ctype.h>
#include "carefulputc.h"

#define iso8859x_iscntrl(c) \
	(((c) & 0x7f) < 0x20 || (c) == 0x7f)

int
carefulputc(int c, FILE *fp) {
	int ret;

	if (c == '\007' || c == '\t' || c == '\r' || c == '\n' ||
	    (!iso8859x_iscntrl(c) && (isprint(c) || isspace(c))))
		ret = putc(c, fp);
	else if ((c & 0x80) || !isprint(c^0x40))
		ret = fprintf(fp, "\\%3o", (unsigned char) c);
	else {
		ret = putc('^', fp);
		if (ret != EOF)
			ret = putc(c^0x40, fp);
	}
	return (ret < 0) ? EOF : 0;
}