ReactOS  0.4.14-dev-49-gfb4591c
common.c File Reference
#include "vfatlib.h"
#include <debug.h>
Include dependency graph for common.c:

Go to the source code of this file.

Classes

struct  _link
 

Macros

#define NDEBUG
 

Typedefs

typedef struct _link LINK
 

Functions

void die (const char *msg,...)
 
void pdie (const char *msg,...)
 
voidalloc (int size)
 
voidqalloc (void **root, int size)
 
void qfree (void **root)
 
int min (int a, int b)
 
char get_key (const char *valid, const char *prompt)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 29 of file common.c.

Typedef Documentation

◆ LINK

typedef struct _link LINK

Function Documentation

◆ alloc()

void* alloc ( int  size)

Definition at line 94 of file common.c.

95 {
96  void *this;
97 
98  if ((this = malloc(size)))
99  return this;
100  pdie("malloc");
101  return NULL; /* for GCC */
102 }
void pdie(const char *msg,...)
Definition: common.c:74
smooth NULL
Definition: ftsmooth.c:416
GLsizeiptr size
Definition: glext.h:5919
#define malloc
Definition: debug_ros.c:4

Referenced by qalloc().

◆ die()

void die ( const char msg,
  ... 
)

Definition at line 51 of file common.c.

53 {
54  va_list args;
55 
56  va_start(args, msg);
57 #ifndef __REACTOS__
59 #else
60  DPRINT1("Unrecoverable problem!\n");
61  VfatPrintV((char*)msg, args);
62 #endif
63  va_end(args);
64 #ifndef __REACTOS__
65  fprintf(stderr, "\n");
66 #endif
67  exit(1);
68 }
VOID VfatPrintV(PCHAR Format, va_list args)
Definition: vfatlib.c:343
Definition: match.c:390
#define va_end(ap)
Definition: acmsvcex.h:90
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
char * va_list
Definition: acmsvcex.h:78
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define DPRINT1
Definition: precomp.h:8
#define msg(x)
Definition: auth_time.c:54
FILE * stderr
void exit(int exitcode)
Definition: _exit.c:33
_Check_return_opt_ _CRTIMP int __cdecl vfprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format, va_list _ArgList)
#define args
Definition: format.c:66

◆ get_key()

char get_key ( const char valid,
const char prompt 
)

Definition at line 184 of file common.c.

185 {
186 #ifndef __REACTOS__
187  int ch, okay;
188 
189  while (1) {
190  if (prompt)
191  printf("%s ", prompt);
192  fflush(stdout);
193  while (ch = getchar(), ch == ' ' || ch == '\t') ;
194  if (ch == EOF)
195  exit(1);
196  if (!strchr(valid, okay = ch))
197  okay = 0;
198  while (ch = getchar(), ch != '\n' && ch != EOF) ;
199  if (ch == EOF)
200  exit(1);
201  if (okay)
202  return okay;
203  printf("Invalid input.\n");
204  }
205 #else
206  return 0;
207 #endif
208 }
FILE * stdout
_Check_return_ _CRTIMP int __cdecl getchar(void)
Definition: file.c:3627
_Check_return_opt_ _CRTIMP int __cdecl fflush(_Inout_opt_ FILE *_File)
char * strchr(const char *String, int ch)
Definition: utclib.c:501
#define EOF
Definition: stdio.h:24
void exit(int exitcode)
Definition: _exit.c:33
#define printf
Definition: config.h:203

Referenced by check_backup_boot(), check_dir(), check_file(), handle_dot(), lfn_add_slot(), lfn_check_orphaned(), lfn_get(), print_fat_dirty_state(), read_fat(), read_fsinfo(), update_free(), and VfatChkdsk().

◆ min()

int min ( int  a,
int  b 
)

Definition at line 179 of file common.c.

180 {
181  return a < b ? a : b;
182 }
#define a
Definition: ke_i.h:78
#define b
Definition: ke_i.h:79
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204

Referenced by Fast486WriteMemory().

◆ pdie()

void pdie ( const char msg,
  ... 
)

Definition at line 74 of file common.c.

76 {
77  va_list args;
78 
79  va_start(args, msg);
80 #ifndef __REACTOS__
82 #else
83  DPRINT1("Unrecoverable problem!\n");
84  VfatPrintV((char*)msg, args);
85 #endif
86  va_end(args);
87 #ifndef __REACTOS__
88  fprintf(stderr, ":%s\n", strerror(errno));
89 #endif
90  exit(1);
91 }
VOID VfatPrintV(PCHAR Format, va_list args)
Definition: vfatlib.c:343
int errno
Definition: match.c:390
const char * strerror(int err)
Definition: compat_str.c:23
#define va_end(ap)
Definition: acmsvcex.h:90
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
char * va_list
Definition: acmsvcex.h:78
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define DPRINT1
Definition: precomp.h:8
#define msg(x)
Definition: auth_time.c:54
FILE * stderr
void exit(int exitcode)
Definition: _exit.c:33
_Check_return_opt_ _CRTIMP int __cdecl vfprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format, va_list _ArgList)
#define args
Definition: format.c:66

Referenced by alloc(), fs_close(), fs_read(), fs_test(), and fs_write().

◆ qalloc()

void* qalloc ( void **  root,
int  size 
)

Definition at line 139 of file common.c.

140 {
141  LINK *link;
142 
143 #ifndef __REACTOS__
144  link = alloc(sizeof(LINK));
145 #else
146  link = vfalloc(sizeof(LINK));
147 #endif
148  link->next = *root;
149  *root = link;
150 #ifndef __REACTOS__
151  return link->data = alloc(size);
152 #else
153  return link->data = vfalloc(size);
154 #endif
155 }
void * alloc(int size)
Definition: common.c:94
struct _root root
GLsizeiptr size
Definition: glext.h:5919
const WCHAR * link
Definition: db.cpp:988

Referenced by add_file(), and cnv_unicode().

◆ qfree()

void qfree ( void **  root)

Definition at line 157 of file common.c.

158 {
159  LINK *this;
160 
161  while (*root) {
162  this = (LINK *) * root;
163  *root = this->next;
164 #ifndef __REACTOS__
165  free(this->data);
166  free(this);
167 #else
168  vffree(this->data);
169  vffree(this);
170 #endif
171  }
172 }
#define free
Definition: debug_ros.c:5
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
static unsigned __int64 next
Definition: rand_nt.c:6

Referenced by VfatChkdsk().