2 * FreeBSD install - a package for the installation and maintainance
3 * of non-core utilities.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
17 * Miscellaneous message routines.
19 * $FreeBSD: src/usr.sbin/pkg_install/lib/msg.c,v 1.12.2.4 2002/08/20 06:35:08 obrien Exp $
20 * $DragonFly: src/usr.sbin/pkg_install/lib/Attic/msg.c,v 1.2 2003/06/17 04:29:59 dillon Exp $
27 /* Die a relatively simple death */
29 upchuck(const char *message)
32 errx(1, "fatal error during execution: %s", message);
36 * As a yes/no question, prompting from the varargs string and using
37 * default if user just hits return.
40 y_or_n(Boolean def, const char *msg, ...)
48 * Need to open /dev/tty because file collection may have been
51 tty = fopen(_PATH_TTY, "r");
54 errx(2, "can't open %s!", _PATH_TTY);
56 while (ch != 'Y' && ch != 'N') {
57 vfprintf(stderr, msg, args);
59 fprintf(stderr, " [yes]? ");
61 fprintf(stderr, " [no]? ");
64 ch = (AutoAnswer == YES) ? 'Y' : 'N';
65 fprintf(stderr, "%c\n", ch);
68 ch = toupper(fgetc(tty));
70 ch = (def) ? 'Y' : 'N';
73 return (ch == 'Y') ? TRUE : FALSE;