I'm working on a custom recovery for Android written in c. I'm trying to add a feature to return the current ROM to the user by using fgets to read the build.prop file available on every phone. The code below works on one ROM where ro.modversion appears at line 106, but doesn't work on a similar ROM where ro.modversion appears at line 109.
On the first ROM build.prop it returnsCode:
- char* get_modversion()
- char* result;
- FILE * vers = fopen("/system/build.prop", "r");
- if (vers == NULL)
- return NULL;
- char line;
- while(fgets(line, sizeof(line), vers) != NULL && fgets(line, sizeof(line), vers) != EOF) //read a line
- if (strstr(line, "ro.modversion") != NULL)
- char* strptr = strstr(line, "=") + 1;
- result = calloc(strlen(strptr) + 1, sizeof(char));
- strcpy(result, strptr);
- ui_print("Current ROM: %s\n", result);
- int LENGTH = strlen(result);
- ui_print("LENGTH: %d\n", LENGTH);
- return LENGTH;
Current ROM: Decks_Reloaded
LENGTH:15 (14 characters plus the new line character fgets adds).
On the second ROM build.prop, it returns
Seems like it's returning something if the length is 10, but I don't know what. Also don't know what "moving:" means. I've tried lowering char line to 128 and increasing it up to 4096. I've tried changing calloc to malloc. I've tried changing sizeof(char) to sizeof(line) in result=. No matter what it works on the first but not the second. (wouldn't build when I changed it to malloc). Any help would be greatly appreciated.