1 /* common.c - Common functions
3 Copyright (C) 1993 Werner Almesberger <werner.almesberger@lrc.di.epfl.ch>
4 Copyright (C) 1998 Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de>
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 On Debian systems, the complete text of the GNU General Public License
20 can be found in /usr/share/common-licenses/GPL-3 file.
23 /* FAT32, VFAT, Atari format support, and various fixes additions May 1998
24 * by Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de> */
36 typedef struct _link {
42 void die(char *msg,...)
47 vfprintf(stderr,msg,args);
54 void pdie(char *msg,...)
59 vfprintf(stderr,msg,args);
61 fprintf(stderr,":%s\n",strerror(errno));
70 if ((this = malloc(size))) return this;
72 return NULL; /* for GCC */
76 void *qalloc(void **root,int size)
80 link = alloc(sizeof(LINK));
83 return link->data = alloc(size);
87 void qfree(void **root)
92 this = (LINK *) *root;
102 return a < b ? a : b;
106 char get_key(char *valid,char *prompt)
111 if (prompt) printf("%s ",prompt);
113 while (ch = getchar(), ch == ' ' || ch == '\t');
114 if (ch == EOF) exit(1);
115 if (!strchr(valid,okay = ch)) okay = 0;
116 while (ch = getchar(), ch != '\n' && ch != EOF);
117 if (ch == EOF) exit(1);
118 if (okay) return okay;
119 printf("Invalid input.\n");