opnsense-src/share/examples/sunrpc/msg/printmsg.c
Franco Fichtner 402e7dde73 src: initial commit based on FreeBSD-10.0
Taken from:	https://github.com/freebsd/freebsd.git
Commit id:	d44ce30d3054a38723f89a161c5e003e64d1aaae
2014-11-09 09:30:14 +01:00

45 lines
753 B
C

/* @(#)printmsg.c 2.1 88/08/11 4.0 RPCSRC */
/* $FreeBSD$ */
/*
* printmsg.c: print a message on the console
*/
#include <paths.h>
#include <stdio.h>
main(argc, argv)
int argc;
char *argv[];
{
char *message;
if (argc < 2) {
fprintf(stderr, "usage: %s <message>\n", argv[0]);
exit(1);
}
message = argv[1];
if (!printmessage(message)) {
fprintf(stderr, "%s: sorry, couldn't print your message\n",
argv[0]);
exit(1);
}
printf("Message delivered!\n");
}
/*
* Print a message to the console.
* Return a boolean indicating whether the message was actually printed.
*/
printmessage(msg)
char *msg;
{
FILE *f;
f = fopen(_PATH_CONSOLE, "w");
if (f == NULL) {
return (0);
}
fprintf(f, "%s\n", msg);
fclose(f);
return(1);
}