Take care of one BSOD in NtGdiDdCreateDirectDrawObject, it is not correct fix, it...
[reactos.git] / rosapps / sysutils / dosfsck / common.c
1 /* common.c - Common functions */
2
3 /* Written 1993 by Werner Almesberger */
4
5 /* FAT32, VFAT, Atari format support, and various fixes additions May 1998
6 * by Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de> */
7
8
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include <string.h>
12 #include <stdarg.h>
13 #include <errno.h>
14
15 #include "common.h"
16
17
18 typedef struct _link {
19 void *data;
20 struct _link *next;
21 } LINK;
22
23
24 void die(char *msg,...)
25 {
26 va_list args;
27
28 va_start(args,msg);
29 vfprintf(stderr,msg,args);
30 va_end(args);
31 fprintf(stderr,"\n");
32 exit(1);
33 }
34
35
36 void pdie(char *msg,...)
37 {
38 va_list args;
39
40 va_start(args,msg);
41 vfprintf(stderr,msg,args);
42 va_end(args);
43 fprintf(stderr,":%s\n",strerror(errno));
44 exit(1);
45 }
46
47
48 void *alloc(int size)
49 {
50 void *this;
51
52 if ((this = malloc(size))) return this;
53 pdie("malloc");
54 return NULL; /* for GCC */
55 }
56
57
58 void *qalloc(void **root,int size)
59 {
60 LINK *link;
61
62 link = alloc(sizeof(LINK));
63 link->next = *root;
64 *root = link;
65 return link->data = alloc(size);
66 }
67
68
69 void qfree(void **root)
70 {
71 LINK *this;
72
73 while (*root) {
74 this = (LINK *) *root;
75 *root = this->next;
76 free(this->data);
77 free(this);
78 }
79 }
80
81
82 #ifdef min
83 #undef min
84 #endif
85 int min(int a,int b)
86 {
87 return a < b ? a : b;
88 }
89
90
91 char get_key(char *valid,char *prompt)
92 {
93 int ch,okay;
94
95 while (1) {
96 if (prompt) printf("%s ",prompt);
97 fflush(stdout);
98 while (ch = getchar(), ch == ' ' || ch == '\t');
99 if (ch == EOF) exit(1);
100 if (!strchr(valid,okay = ch)) okay = 0;
101 while (ch = getchar(), ch != '\n' && ch != EOF);
102 if (ch == EOF) exit(1);
103 if (okay) return okay;
104 printf("Invalid input.\n");
105 }
106 }
107
108 /* Local Variables: */
109 /* tab-width: 8 */
110 /* End: */