]> git.ozlabs.org Git - petitboot/blob - lib/types/types.c
lib: Define autoboot_options, device_type helpers
[petitboot] / lib / types / types.c
1 #include <string.h>
2 #include <types/types.h>
3 #include <i18n/i18n.h>
4
5 const char *device_type_display_name(enum device_type type)
6 {
7         switch (type) {
8         case DEVICE_TYPE_DISK:
9                 return _("Disk");
10         case DEVICE_TYPE_OPTICAL:
11                 return _("Optical");
12         case DEVICE_TYPE_NETWORK:
13                 return _("Network");
14         case DEVICE_TYPE_ANY:
15                 return _("Any");
16         case DEVICE_TYPE_UNKNOWN:
17         default:
18                 return _("Unknown");
19         }
20 }
21
22 const char *device_type_name(enum device_type type)
23 {
24         switch (type) {
25         case DEVICE_TYPE_DISK:
26                 return "disk";
27         case DEVICE_TYPE_OPTICAL:
28                 return "optical";
29         case DEVICE_TYPE_NETWORK:
30                 return "network";
31         case DEVICE_TYPE_ANY:
32                 return "any";
33         case DEVICE_TYPE_UNKNOWN:
34         default:
35                 return "unknown";
36         }
37 }
38
39 enum device_type find_device_type(const char *str)
40 {
41         if (!strncmp(str, "disk", strlen("disk")))
42                 return DEVICE_TYPE_DISK;
43         if (!strncmp(str, "optical", strlen("optical")))
44                 return DEVICE_TYPE_OPTICAL;
45         if (!strncmp(str, "network", strlen("network")))
46                 return DEVICE_TYPE_NETWORK;
47         if (!strncmp(str, "any", strlen("any")))
48                 return DEVICE_TYPE_ANY;
49
50         return DEVICE_TYPE_UNKNOWN;
51 }