source: MondoRescue/branches/2.2.9/mindi-busybox/e2fsprogs/old_e2fsprogs/e2p/ostype.c@ 3320

Last change on this file since 3320 was 3320, checked in by Bruno Cornec, 9 years ago
  • Re-add (thanks git BTW) the 2.2.9 branch which had been destroyed in the move to 3.0
  • Property svn:eol-style set to native
File size: 1.1 KB
Line 
1/* vi: set sw=4 ts=4: */
2/*
3 * getostype.c - Get the Filesystem OS type
4 *
5 * Copyright (C) 2004,2005 Theodore Ts'o <tytso@mit.edu>
6 *
7 * This file can be redistributed under the terms of the GNU Library General
8 * Public License
9 */
10
11#include "e2p.h"
12#include <string.h>
13#include <stdlib.h>
14
15static const char *const os_tab[] =
16 { "Linux",
17 "Hurd",
18 "Masix",
19 "FreeBSD",
20 "Lites",
21 0 };
22
23/*
24 * Convert an os_type to a string
25 */
26char *e2p_os2string(int os_type)
27{
28 const char *os;
29 char *ret;
30
31 if (os_type <= EXT2_OS_LITES)
32 os = os_tab[os_type];
33 else
34 os = "(unknown os)";
35
36 ret = xstrdup(os);
37 return ret;
38}
39
40/*
41 * Convert an os_type to a string
42 */
43int e2p_string2os(char *str)
44{
45 const char *const *cpp;
46 int i = 0;
47
48 for (cpp = os_tab; *cpp; cpp++, i++) {
49 if (!strcasecmp(str, *cpp))
50 return i;
51 }
52 return -1;
53}
54
55#ifdef TEST_PROGRAM
56int main(int argc, char **argv)
57{
58 char *s;
59 int i, os;
60
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);
68 }
69 }
70 exit(0);
71}
72#endif
Note: See TracBrowser for help on using the repository browser.