* Process the HWID string according to requirements: * - If a colon is found, delete everything before it * - Trim leading/trailing whitespace * - Drop anything after hyphen or space * * Examples: * - 'hardware_id: NOCTURNE D5B-A5F-B47-H6A-A5L' --> Nocturne * - 'BANSHEE-UZTQ B4B-D3A-F3F-D8A-A7O' --> Banshee */
| 19 | * - 'BANSHEE-UZTQ B4B-D3A-F3F-D8A-A7O' --> Banshee |
| 20 | */ |
| 21 | static void process_hwid(char *hwid) |
| 22 | { |
| 23 | char *src = hwid; |
| 24 | char *dst = hwid; |
| 25 | char *colon; |
| 26 | char *end; |
| 27 | |
| 28 | if (!hwid || !*hwid) |
| 29 | return; |
| 30 | |
| 31 | /* Look for a colon and skip everything before it */ |
| 32 | colon = strchr(hwid, ':'); |
| 33 | if (colon) { |
| 34 | src = colon + 1; /* Start after the colon */ |
| 35 | } |
| 36 | |
| 37 | /* Trim leading whitespace */ |
| 38 | while (*src && isspace((unsigned char)*src)) |
| 39 | src++; |
| 40 | |
| 41 | /* Copy characters until we hit a hyphen, space, or end of string */ |
| 42 | while (*src && *src != '-' && !isspace((unsigned char)*src)) { |
| 43 | *dst++ = *src++; |
| 44 | } |
| 45 | |
| 46 | /* Null terminate */ |
| 47 | *dst = '\0'; |
| 48 | |
| 49 | /* Trim trailing whitespace (shouldn't be any based on the logic above, but just in case) */ |
| 50 | end = dst - 1; |
| 51 | while (end >= hwid && isspace((unsigned char)*end)) { |
| 52 | *end = '\0'; |
| 53 | end--; |
| 54 | } |
| 55 | |
| 56 | /* Normalize casing: capitalize first character, lowercase the rest */ |
| 57 | if (*hwid) { |
| 58 | char *p = hwid; |
| 59 | |
| 60 | *p = toupper((unsigned char)*p); |
| 61 | for (p = hwid + 1; *p; p++) |
| 62 | *p = tolower((unsigned char)*p); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | const char *smbios_system_product_name(void) |
| 67 | { |
no test coverage detected