Last change
on this file since 2899 was 1765, checked in by Bruno Cornec, 17 years ago |
Update to busybox 1.7.2
|
-
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 |
|
---|
15 | static 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 | */
|
---|
26 | char *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 | */
|
---|
43 | int 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
|
---|
56 | int 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
|
---|
73 |
|
---|
74 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.