Changes for kernel and Busybox
[tomato.git] / release / src / router / busybox / e2fsprogs / e2p / ostype.c
blob6a2f178f337fb226c85990eb71fb54216b9d7f65
1 /* vi: set sw=4 ts=4: */
2 /*
3 * getostype.c - Get the Filesystem OS type
5 * Copyright (C) 2004,2005 Theodore Ts'o <tytso@mit.edu>
7 * This file can be redistributed under the terms of the GNU Library General
8 * Public License
9 */
11 #include "e2p.h"
12 #include <string.h>
13 #include <stdlib.h>
15 static const char *const os_tab[] =
16 { "Linux",
17 "Hurd",
18 "Masix",
19 "FreeBSD",
20 "Lites",
21 0 };
24 * Convert an os_type to a string
26 char *e2p_os2string(int os_type)
28 const char *os;
29 char *ret;
31 if (os_type <= EXT2_OS_LITES)
32 os = os_tab[os_type];
33 else
34 os = "(unknown os)";
36 ret = xstrdup(os);
37 return ret;
41 * Convert an os_type to a string
43 int e2p_string2os(char *str)
45 const char *const *cpp;
46 int i = 0;
48 for (cpp = os_tab; *cpp; cpp++, i++) {
49 if (!strcasecmp(str, *cpp))
50 return i;
52 return -1;
55 #ifdef TEST_PROGRAM
56 int main(int argc, char **argv)
58 char *s;
59 int i, os;
61 for (i=0; i <= EXT2_OS_LITES; i++) {
62 s = e2p_os2string(i);
63 os = e2p_string2os(s);
64 printf("%d: %s (%d)\n", i, s, os);
65 if (i != os) {
66 fprintf(stderr, "Failure!\n");
67 exit(1);
70 exit(0);
72 #endif