Make insmod quiet by default (patch from Yann E. Morin).
[oweals/busybox.git] / e2fsprogs / e2p / ostype.c
1 /*
2  * getostype.c          - Get the Filesystem OS type
3  *
4  * Copyright (C) 2004,2005  Theodore Ts'o <tytso@mit.edu>
5  *
6  * This file can be redistributed under the terms of the GNU Library General
7  * Public License
8  */
9
10 #include "e2p.h"
11 #include <string.h>
12
13 static const char * const os_tab[] =
14         { "Linux", 
15           "Hurd", 
16           "Masix", 
17           "FreeBSD", 
18           "Lites",
19           0 };
20
21 /*
22  * Convert an os_type to a string
23  */
24 char *e2p_os2string(int os_type)
25 {
26         const char *os;
27         char *ret;
28
29         if (os_type <= EXT2_OS_LITES)
30                 os = os_tab[os_type];
31         else
32                 os = "(unknown os)";
33
34         ret = bb_xstrdup(os);
35         return ret;
36 }
37
38 /*
39  * Convert an os_type to a string
40  */
41 int e2p_string2os(char *str)
42 {
43         const char * const *cpp;
44         int i = 0;
45
46         for (cpp = os_tab; *cpp; cpp++, i++) {
47                 if (!strcasecmp(str, *cpp))
48                         return i;
49         }
50         return -1;
51 }
52
53 #ifdef TEST_PROGRAM
54 int main(int argc, char **argv)
55 {
56         char    *s;
57         int     i, os;
58
59         for (i=0; i <= EXT2_OS_LITES; i++) {
60                 s = e2p_os2string(i);
61                 os = e2p_string2os(s);
62                 printf("%d: %s (%d)\n", i, s, os);
63                 if (i != os) {
64                         fprintf(stderr, "Failure!\n");
65                         exit(1);
66                 }
67         }
68         exit(0);
69 }
70 #endif
71
72