dosfstools  4.2
About: dosfstools are utilities to create, check and label (MS-DOS) FAT filesystems.
  Fossies Dox: dosfstools-4.2.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

common.h
Go to the documentation of this file.
1 /* common.h - Common functions
2 
3  Copyright (C) 1993 Werner Almesberger <werner.almesberger@lrc.di.epfl.ch>
4  Copyright (C) 2008-2014 Daniel Baumann <mail@daniel-baumann.ch>
5 
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.
10 
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.
15 
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/>.
18 
19  The complete text of the GNU General Public License
20  can be found in /usr/share/common-licenses/GPL-3 file.
21 */
22 
23 #ifndef _COMMON_H
24 #define _COMMON_H
25 
26 #include <sys/types.h>
27 
28 #include <limits.h>
29 #include <stdint.h>
30 
31 #ifndef OFF_MAX
32  #define OFF_MAX (off_t)((1ULL << (sizeof(off_t) * CHAR_BIT - 1)) - 1)
33 #endif
34 
35 extern int interactive;
36 extern int write_immed;
37 extern int atari_format; /* Use Atari variation of MS-DOS FS format */
38 
39 /* program_name used for printing messages; no name will be printed when it is
40  * left as NULL */
41 extern const char *program_name;
42 
43 void die(const char *msg, ...)
44  __attribute((noreturn, format(printf, 1, 2)));
45 
46 /* Displays a prinf-style message and terminates the program. */
47 
48 void pdie(const char *msg, ...)
49  __attribute((noreturn, format(printf, 1, 2)));
50 
51 /* Like die, but appends an error message according to the state of errno. */
52 
53 void *alloc(int size);
54 
55 /* mallocs SIZE bytes and returns a pointer to the data. Terminates the program
56  if malloc fails. */
57 
58 void *qalloc(void **root, int size);
59 
60 /* Like alloc, but registers the data area in a list described by ROOT. */
61 
62 void qfree(void **root);
63 
64 /* Deallocates all qalloc'ed data areas described by ROOT. */
65 
66 int min(int a, int b);
67 
68 /* Returns the smaller integer value of a and b. */
69 
70 int xasprintf(char **strp, const char *fmt, ...)
71  __attribute((format(printf, 2, 3)));
72 
73 /* Runs asprintf() and terminates the program if it fails. */
74 
75 int get_choice(int noninteractive_result, const char *noninteractive_msg,
76  int choices, ...);
77 
78 /*
79  * Display a numbered list of choices and accept user input to select one. If
80  * interactive is false, it will instead print noninteractive_msg and return
81  * noninteractive_result. The number of options must be given in choices and
82  * must be more than one and less then ten.
83  *
84  * The variable arguments are choices times <int val, const char *desc>, where
85  * val is the value that is returned when the user selects this option and desc
86  * is the string describing this option.
87  */
88 
89 char *get_line(const char *prompt, char *dest, size_t length);
90 
91 /*
92  * Display prompt and read a line, placing it in dest with at most length-1
93  * characters plus a null byte. This behaves like printing a prompt and fgets()
94  * afterwards with the addition of temporarily enabling canonical input mode
95  * with echo if needed.
96  */
97 
98 void check_atari(void);
99 
100 /*
101  * ++roman: On m68k Linux, check if this is an Atari; if yes, turn on Atari
102  * variant of MS-DOS filesystem by default.
103  */
104 
105 uint32_t generate_volume_id(void);
106 
107 /*
108  * Generate a 32 bit volume ID
109  */
110 
111 int validate_volume_label(char *doslabel);
112 
113 /*
114  * Validate volume label
115  */
116 
117 #endif
static DOS_FILE * root
Definition: check.c:51
int int get_choice(int noninteractive_result, const char *noninteractive_msg, int choices,...)
Definition: common.c:157
void pdie(const char *msg,...) __attribute((noreturn
void qfree(void **root)
Definition: common.c:101
int validate_volume_label(char *doslabel)
Definition: common.c:324
void * alloc(int size)
Definition: common.c:81
void format(printf, 1, 2)))
void check_atari(void)
Definition: common.c:273
int atari_format
Definition: common.c:44
int write_immed
Definition: common.c:43
void die(const char *msg,...) __attribute((noreturn
int min(int a, int b)
Definition: common.c:113
void * qalloc(void **root, int size)
Definition: common.c:91
int xasprintf(char **strp, const char *fmt,...) __attribute((format(printf
uint32_t generate_volume_id(void)
Definition: common.c:298
const char * program_name
Definition: common.c:45
int interactive
Definition: common.c:42
char * get_line(const char *prompt, char *dest, size_t length)
Definition: common.c:245