Simplify string ops with already compiled-in functions

This commit is contained in:
CTCaer 2019-12-04 15:56:53 +02:00
parent 74452074f6
commit 29a51124fd
14 changed files with 54 additions and 63 deletions

View file

@ -227,8 +227,7 @@ static void _config_autoboot_list(void *ent)
else else
boot_text[(i - 1) * 512] = '*'; boot_text[(i - 1) * 512] = '*';
memcpy(boot_text + (i - 1) * 512 + 1, ini_sec->name, strlen(ini_sec->name) + 1); strcpy(boot_text + (i - 1) * 512 + 1, ini_sec->name);
boot_text[strlen(ini_sec->name) + (i - 1) * 512 + 1] = 0;
ments[i].caption = &boot_text[(i - 1) * 512]; ments[i].caption = &boot_text[(i - 1) * 512];
} }
ments[i].type = ini_sec->type; ments[i].type = ini_sec->type;
@ -335,8 +334,7 @@ void config_autoboot()
else else
boot_text[(i - 4) * 512] = '*'; boot_text[(i - 4) * 512] = '*';
memcpy(boot_text + (i - 4) * 512 + 1, ini_sec->name, strlen(ini_sec->name) + 1); strcpy(boot_text + (i - 4) * 512 + 1, ini_sec->name);
boot_text[strlen(ini_sec->name) + (i - 4) * 512 + 1] = 0;
ments[i].caption = &boot_text[(i - 4) * 512]; ments[i].caption = &boot_text[(i - 4) * 512];
} }
ments[i].type = ini_sec->type; ments[i].type = ini_sec->type;
@ -421,7 +419,7 @@ void config_bootdelay()
else else
delay_text[i * 32] = '*'; delay_text[i * 32] = '*';
delay_text[i * 32 + 1] = i + '0'; delay_text[i * 32 + 1] = i + '0';
memcpy(delay_text + i * 32 + 2, " seconds", 9); strcpy(delay_text + i * 32 + 2, " seconds");
ments[i + 2].type = MENT_DATA; ments[i + 2].type = MENT_DATA;
ments[i + 2].caption = delay_text + i * 32; ments[i + 2].caption = delay_text + i * 32;
@ -468,9 +466,9 @@ void config_verification()
ments[1].type = MENT_CHGLINE; ments[1].type = MENT_CHGLINE;
memcpy(vr_text, " Disable (Fastest - Unsafe)", 28); strcpy(vr_text, " Disable (Fastest - Unsafe)");
memcpy(vr_text + 64, " Sparse (Fast - Safe)", 23); strcpy(vr_text + 64, " Sparse (Fast - Safe)");
memcpy(vr_text + 128, " Full (Slow - Safe)", 23); strcpy(vr_text + 128, " Full (Slow - Safe)");
for (u32 i = 0; i < 3; i++) for (u32 i = 0; i < 3; i++)
{ {
@ -530,10 +528,10 @@ void config_backlight()
if (i < 10) if (i < 10)
{ {
bri_text[i * 32 + 1] = i + '0'; bri_text[i * 32 + 1] = i + '0';
memcpy(bri_text + i * 32 + 2, "0%", 3); strcpy(bri_text + i * 32 + 2, "0%");
} }
else else
memcpy(bri_text + i * 32 + 1, "100%", 5); strcpy(bri_text + i * 32 + 1, "100%");
ments[i + 1].type = MENT_DATA; ments[i + 1].type = MENT_DATA;
ments[i + 1].caption = bri_text + i * 32; ments[i + 1].caption = bri_text + i * 32;

View file

@ -78,7 +78,7 @@ int ini_parse(link_t *dst, char *ini_path, bool is_dir)
char *filename = (char *)malloc(256); char *filename = (char *)malloc(256);
memcpy(filename, ini_path, pathlen + 1); strcpy(filename, ini_path);
// Get all ini filenames. // Get all ini filenames.
if (is_dir) if (is_dir)
@ -89,7 +89,7 @@ int ini_parse(link_t *dst, char *ini_path, bool is_dir)
free(filename); free(filename);
return 0; return 0;
} }
memcpy(filename + pathlen, "/", 2); strcpy(filename + pathlen, "/");
pathlen++; pathlen++;
} }
@ -100,7 +100,7 @@ int ini_parse(link_t *dst, char *ini_path, bool is_dir)
{ {
if (filelist[k * 256]) if (filelist[k * 256])
{ {
memcpy(filename + pathlen, &filelist[k * 256], strlen(&filelist[k * 256]) + 1); strcpy(filename + pathlen, &filelist[k * 256]);
k++; k++;
} }
else else

View file

@ -185,7 +185,7 @@ static int _dump_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t
FIL partialIdxFp; FIL partialIdxFp;
char partialIdxFilename[12]; char partialIdxFilename[12];
memcpy(partialIdxFilename, "partial.idx", 12); strcpy(partialIdxFilename, "partial.idx");
gfx_con.fntsz = 8; gfx_con.fntsz = 8;
gfx_printf("\nSD Card free space: %d MiB, Total backup size %d MiB\n\n", gfx_printf("\nSD Card free space: %d MiB, Total backup size %d MiB\n\n",
@ -203,7 +203,7 @@ static int _dump_emmc_part(char *sd_path, sdmmc_storage_t *storage, emmc_part_t
{ {
isSmallSdCard = true; isSmallSdCard = true;
gfx_printf("%k\nSD card free space is smaller than total backup size.%k\n", 0xFFFFBA00, 0xFFCCCCCC); gfx_printf("%k\nSD card free space is smaller than backup size.%k\n", 0xFFFFBA00, 0xFFCCCCCC);
if (!maxSplitParts) if (!maxSplitParts)
{ {
@ -518,7 +518,7 @@ static void _dump_emmc_selected(emmcPartType_t dumpType)
bootPart.lba_end = (BOOT_PART_SIZE / NX_EMMC_BLOCKSIZE) - 1; bootPart.lba_end = (BOOT_PART_SIZE / NX_EMMC_BLOCKSIZE) - 1;
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
{ {
memcpy(bootPart.name, "BOOT", 5); strcpy(bootPart.name, "BOOT");
bootPart.name[4] = (u8)('0' + i); bootPart.name[4] = (u8)('0' + i);
bootPart.name[5] = 0; bootPart.name[5] = 0;
@ -874,7 +874,7 @@ static void _restore_emmc_selected(emmcPartType_t restoreType)
bootPart.lba_end = (BOOT_PART_SIZE / NX_EMMC_BLOCKSIZE) - 1; bootPart.lba_end = (BOOT_PART_SIZE / NX_EMMC_BLOCKSIZE) - 1;
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
{ {
memcpy(bootPart.name, "BOOT", 4); strcpy(bootPart.name, "BOOT");
bootPart.name[4] = (u8)('0' + i); bootPart.name[4] = (u8)('0' + i);
bootPart.name[5] = 0; bootPart.name[5] = 0;

View file

@ -201,40 +201,33 @@ void print_mmc_info()
gfx_printf("%kExtended CSD V1.%d:%k\n", gfx_printf("%kExtended CSD V1.%d:%k\n",
0xFF00DDFF, storage.ext_csd.ext_struct, 0xFFCCCCCC); 0xFF00DDFF, storage.ext_csd.ext_struct, 0xFFCCCCCC);
card_type = storage.ext_csd.card_type; card_type = storage.ext_csd.card_type;
u8 card_type_support[96]; char card_type_support[96];
u8 pos_type = 0;
card_type_support[0] = 0; card_type_support[0] = 0;
if (card_type & EXT_CSD_CARD_TYPE_HS_26) if (card_type & EXT_CSD_CARD_TYPE_HS_26)
{ {
memcpy(card_type_support, "HS26", 4); strcat(card_type_support, "HS26");
speed = (26 << 16) | 26; speed = (26 << 16) | 26;
pos_type += 4;
} }
if (card_type & EXT_CSD_CARD_TYPE_HS_52) if (card_type & EXT_CSD_CARD_TYPE_HS_52)
{ {
memcpy(card_type_support + pos_type, ", HS52", 6); strcat(card_type_support, ", HS52");
speed = (52 << 16) | 52; speed = (52 << 16) | 52;
pos_type += 6;
} }
if (card_type & EXT_CSD_CARD_TYPE_DDR_1_8V) if (card_type & EXT_CSD_CARD_TYPE_DDR_1_8V)
{ {
memcpy(card_type_support + pos_type, ", DDR52_1.8V", 12); strcat(card_type_support, ", DDR52_1.8V");
speed = (52 << 16) | 104; speed = (52 << 16) | 104;
pos_type += 12;
} }
if (card_type & EXT_CSD_CARD_TYPE_HS200_1_8V) if (card_type & EXT_CSD_CARD_TYPE_HS200_1_8V)
{ {
memcpy(card_type_support + pos_type, ", HS200_1.8V", 12); strcat(card_type_support, ", HS200_1.8V");
speed = (200 << 16) | 200; speed = (200 << 16) | 200;
pos_type += 12;
} }
if (card_type & EXT_CSD_CARD_TYPE_HS400_1_8V) if (card_type & EXT_CSD_CARD_TYPE_HS400_1_8V)
{ {
memcpy(card_type_support + pos_type, ", HS400_1.8V", 12); strcat(card_type_support, ", HS400_1.8V");
speed = (200 << 16) | 400; speed = (200 << 16) | 400;
pos_type += 12;
} }
card_type_support[pos_type] = 0;
gfx_printf( gfx_printf(
" Spec Version: %02X\n" " Spec Version: %02X\n"

View file

@ -480,13 +480,13 @@ void _fix_sd_attr(u32 type)
switch (type) switch (type)
{ {
case 0: case 0:
memcpy(path, "/", 2); strcpy(path, "/");
memcpy(label, "SD Card", 8); strcpy(label, "SD Card");
break; break;
case 1: case 1:
default: default:
memcpy(path, "/Nintendo", 10); strcpy(path, "/Nintendo");
memcpy(label, "Nintendo folder", 16); strcpy(label, "Nintendo folder");
break; break;
} }

View file

@ -65,13 +65,13 @@ static int _config_kip1(launch_ctxt_t *ctxt, const char *value)
if (!memcmp(value + strlen(value) - 1, "*", 1)) if (!memcmp(value + strlen(value) - 1, "*", 1))
{ {
char *dir = (char *)malloc(256); char *dir = (char *)malloc(256);
memcpy(dir, value, strlen(value) + 1); strcpy(dir, value);
u32 dirlen = 0; u32 dirlen = 0;
dir[strlen(dir) - 2] = 0; dir[strlen(dir) - 2] = 0;
char *filelist = dirlist(dir, "*.kip*", false); char *filelist = dirlist(dir, "*.kip*", false);
memcpy(dir + strlen(dir), "/", 2); strcat(dir, "/");
dirlen = strlen(dir); dirlen = strlen(dir);
u32 i = 0; u32 i = 0;
@ -82,7 +82,7 @@ static int _config_kip1(launch_ctxt_t *ctxt, const char *value)
if (!filelist[i * 256]) if (!filelist[i * 256])
break; break;
memcpy(dir + dirlen, &filelist[i * 256], strlen(&filelist[i * 256]) + 1); strcpy(dir + dirlen, &filelist[i * 256]);
merge_kip_t *mkip1 = (merge_kip_t *)malloc(sizeof(merge_kip_t)); merge_kip_t *mkip1 = (merge_kip_t *)malloc(sizeof(merge_kip_t));
mkip1->kip1 = sd_file_read(dir, &size); mkip1->kip1 = sd_file_read(dir, &size);

View file

@ -271,10 +271,10 @@ void secmon_exo_check_panic()
// Save context to the SD card. // Save context to the SD card.
char filepath[0x40]; char filepath[0x40];
f_mkdir("atmosphere/fatal_errors"); f_mkdir("atmosphere/fatal_errors");
memcpy(filepath, "/atmosphere/fatal_errors/report_", 33); strcpy(filepath, "/atmosphere/fatal_errors/report_");
itoa((u32)((u64)rpt->report_identifier >> 32), filepath + strlen(filepath), 16); itoa((u32)((u64)rpt->report_identifier >> 32), filepath + strlen(filepath), 16);
itoa((u32)(rpt->report_identifier), filepath + strlen(filepath), 16); itoa((u32)(rpt->report_identifier), filepath + strlen(filepath), 16);
memcpy(filepath + strlen(filepath), ".bin", 5); strcat(filepath, ".bin");
sd_save_to_file((void *)rpt, sizeof(atm_fatal_error_ctx), filepath); sd_save_to_file((void *)rpt, sizeof(atm_fatal_error_ctx), filepath);

View file

@ -42,7 +42,7 @@ char *dirlist(const char *directory, const char *pattern, bool includeHiddenFile
break; break;
if (!(fno.fattrib & AM_DIR) && (fno.fname[0] != '.') && (includeHiddenFiles || !(fno.fattrib & AM_HID))) if (!(fno.fattrib & AM_DIR) && (fno.fname[0] != '.') && (includeHiddenFiles || !(fno.fattrib & AM_HID)))
{ {
memcpy(dir_entries + (k * 256), fno.fname, strlen(fno.fname) + 1); strcpy(dir_entries + (k * 256), fno.fname);
k++; k++;
if (k > (max_entries - 1)) if (k > (max_entries - 1))
break; break;
@ -56,7 +56,7 @@ char *dirlist(const char *directory, const char *pattern, bool includeHiddenFile
{ {
if (!(fno.fattrib & AM_DIR) && (fno.fname[0] != '.') && (includeHiddenFiles || !(fno.fattrib & AM_HID))) if (!(fno.fattrib & AM_DIR) && (fno.fname[0] != '.') && (includeHiddenFiles || !(fno.fattrib & AM_HID)))
{ {
memcpy(dir_entries + (k * 256), fno.fname, strlen(fno.fname) + 1); strcpy(dir_entries + (k * 256), fno.fname);
k++; k++;
if (k > (max_entries - 1)) if (k > (max_entries - 1))
break; break;
@ -81,9 +81,9 @@ char *dirlist(const char *directory, const char *pattern, bool includeHiddenFile
{ {
if (strcmp(&dir_entries[i * 256], &dir_entries[j * 256]) > 0) if (strcmp(&dir_entries[i * 256], &dir_entries[j * 256]) > 0)
{ {
memcpy(temp, &dir_entries[i * 256], strlen(&dir_entries[i * 256]) + 1); strcpy(temp, &dir_entries[i * 256]);
memcpy(&dir_entries[i * 256], &dir_entries[j * 256], strlen(&dir_entries[j * 256]) + 1); strcpy(&dir_entries[i * 256], &dir_entries[j * 256]);
memcpy(&dir_entries[j * 256], temp, strlen(temp) + 1); strcpy(&dir_entries[j * 256], temp);
} }
} }
} }

View file

@ -78,7 +78,7 @@ int ini_parse(link_t *dst, char *ini_path, bool is_dir)
char *filename = (char *)malloc(256); char *filename = (char *)malloc(256);
memcpy(filename, ini_path, pathlen + 1); strcpy(filename, ini_path);
// Get all ini filenames. // Get all ini filenames.
if (is_dir) if (is_dir)
@ -89,7 +89,7 @@ int ini_parse(link_t *dst, char *ini_path, bool is_dir)
free(filename); free(filename);
return 0; return 0;
} }
memcpy(filename + pathlen, "/", 2); strcpy(filename + pathlen, "/");
pathlen++; pathlen++;
} }
@ -100,7 +100,7 @@ int ini_parse(link_t *dst, char *ini_path, bool is_dir)
{ {
if (filelist[k * 256]) if (filelist[k * 256])
{ {
memcpy(filename + pathlen, &filelist[k * 256], strlen(&filelist[k * 256]) + 1); strcpy(filename + pathlen, &filelist[k * 256]);
k++; k++;
} }
else else

View file

@ -363,7 +363,7 @@ static int _dump_emmc_part(emmc_tool_gui_t *gui, char *sd_path, sdmmc_storage_t
FIL partialIdxFp; FIL partialIdxFp;
char partialIdxFilename[12]; char partialIdxFilename[12];
memcpy(partialIdxFilename, "partial.idx", 12); strcpy(partialIdxFilename, "partial.idx");
s_printf(gui->txt_buf, "#96FF00 SD Card free space:# %d MiB\n#96FF00 Total backup size:# %d MiB\n\n", s_printf(gui->txt_buf, "#96FF00 SD Card free space:# %d MiB\n#96FF00 Total backup size:# %d MiB\n\n",
sd_fs.free_clst * sd_fs.csize >> SECTORS_TO_MIB_COEFF, sd_fs.free_clst * sd_fs.csize >> SECTORS_TO_MIB_COEFF,
@ -769,7 +769,7 @@ void dump_emmc_selected(emmcPartType_t dumpType, emmc_tool_gui_t *gui)
bootPart.lba_end = (BOOT_PART_SIZE / NX_EMMC_BLOCKSIZE) - 1; bootPart.lba_end = (BOOT_PART_SIZE / NX_EMMC_BLOCKSIZE) - 1;
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
{ {
memcpy(bootPart.name, "BOOT", 5); strcpy(bootPart.name, "BOOT");
bootPart.name[4] = (u8)('0' + i); bootPart.name[4] = (u8)('0' + i);
bootPart.name[5] = 0; bootPart.name[5] = 0;
@ -1349,7 +1349,7 @@ void restore_emmc_selected(emmcPartType_t restoreType, emmc_tool_gui_t *gui)
bootPart.lba_end = (BOOT_PART_SIZE / NX_EMMC_BLOCKSIZE) - 1; bootPart.lba_end = (BOOT_PART_SIZE / NX_EMMC_BLOCKSIZE) - 1;
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
{ {
memcpy(bootPart.name, "BOOT", 4); strcpy(bootPart.name, "BOOT");
bootPart.name[4] = (u8)('0' + i); bootPart.name[4] = (u8)('0' + i);
bootPart.name[5] = 0; bootPart.name[5] = 0;

View file

@ -368,7 +368,7 @@ void dump_emummc_file(emmc_tool_gui_t *gui)
bootPart.lba_end = (BOOT_PART_SIZE / NX_EMMC_BLOCKSIZE) - 1; bootPart.lba_end = (BOOT_PART_SIZE / NX_EMMC_BLOCKSIZE) - 1;
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
{ {
memcpy(bootPart.name, "BOOT", 5); strcpy(bootPart.name, "BOOT");
bootPart.name[4] = (u8)('0' + i); bootPart.name[4] = (u8)('0' + i);
bootPart.name[5] = 0; bootPart.name[5] = 0;
@ -623,7 +623,7 @@ void dump_emummc_raw(emmc_tool_gui_t *gui, int part_idx, u32 sector_start)
bootPart.lba_end = (BOOT_PART_SIZE / NX_EMMC_BLOCKSIZE) - 1; bootPart.lba_end = (BOOT_PART_SIZE / NX_EMMC_BLOCKSIZE) - 1;
for (i = 0; i < 2; i++) for (i = 0; i < 2; i++)
{ {
memcpy(bootPart.name, "BOOT", 5); strcpy(bootPart.name, "BOOT");
bootPart.name[4] = (u8)('0' + i); bootPart.name[4] = (u8)('0' + i);
bootPart.name[5] = 0; bootPart.name[5] = 0;

View file

@ -278,13 +278,13 @@ static lv_res_t _create_window_fuses_info_status(lv_obj_t *btn)
s_printf(dram_man, "Samsung %s", (!dram_id) ? "4GB" : "6GB"); s_printf(dram_man, "Samsung %s", (!dram_id) ? "4GB" : "6GB");
break; break;
case 1: case 1:
memcpy(dram_man, "Hynix 4GB", 10); strcpy(dram_man, "Hynix 4GB");
break; break;
case 2: case 2:
memcpy(dram_man, "Micron 4GB", 11); strcpy(dram_man, "Micron 4GB");
break; break;
default: default:
memcpy(dram_man, "Unknown", 8); strcpy(dram_man, "Unknown");
break; break;
} }

View file

@ -277,9 +277,9 @@ static lv_res_t _create_window_unset_abit_tool(lv_obj_t *btn)
u32 total = 0; u32 total = 0;
if (!nintendo_folder) if (!nintendo_folder)
memcpy(path, "", 1); path[0] = 0;
else else
memcpy(path, "Nintendo", 9); strcpy(path, "Nintendo");
u32 ufidx = 0; u32 ufidx = 0;
@ -288,7 +288,7 @@ static lv_res_t _create_window_unset_abit_tool(lv_obj_t *btn)
// Also fix the emuMMC Nintendo folders. // Also fix the emuMMC Nintendo folders.
if (nintendo_folder) if (nintendo_folder)
{ {
memcpy(path, "emuMMC", 7); strcpy(path, "emuMMC");
_fix_attributes(&ufidx, lb_val, path, &total, nintendo_folder, nintendo_folder); _fix_attributes(&ufidx, lb_val, path, &total, nintendo_folder, nintendo_folder);
} }

View file

@ -47,7 +47,7 @@ char *dirlist(const char *directory, const char *pattern, bool includeHiddenFile
{ {
if ((fno.fname[0] != '.') && (includeHiddenFiles || !(fno.fattrib & AM_HID))) if ((fno.fname[0] != '.') && (includeHiddenFiles || !(fno.fattrib & AM_HID)))
{ {
memcpy(dir_entries + (k * 256), fno.fname, strlen(fno.fname) + 1); strcpy(dir_entries + (k * 256), fno.fname);
k++; k++;
if (k > (max_entries - 1)) if (k > (max_entries - 1))
break; break;
@ -62,7 +62,7 @@ char *dirlist(const char *directory, const char *pattern, bool includeHiddenFile
{ {
if (!(fno.fattrib & AM_DIR) && (fno.fname[0] != '.') && (includeHiddenFiles || !(fno.fattrib & AM_HID))) if (!(fno.fattrib & AM_DIR) && (fno.fname[0] != '.') && (includeHiddenFiles || !(fno.fattrib & AM_HID)))
{ {
memcpy(dir_entries + (k * 256), fno.fname, strlen(fno.fname) + 1); strcpy(dir_entries + (k * 256), fno.fname);
k++; k++;
if (k > (max_entries - 1)) if (k > (max_entries - 1))
break; break;
@ -87,9 +87,9 @@ char *dirlist(const char *directory, const char *pattern, bool includeHiddenFile
{ {
if (strcmp(&dir_entries[i * 256], &dir_entries[j * 256]) > 0) if (strcmp(&dir_entries[i * 256], &dir_entries[j * 256]) > 0)
{ {
memcpy(temp, &dir_entries[i * 256], strlen(&dir_entries[i * 256]) + 1); strcpy(temp, &dir_entries[i * 256]);
memcpy(&dir_entries[i * 256], &dir_entries[j * 256], strlen(&dir_entries[j * 256]) + 1); strcpy(&dir_entries[i * 256], &dir_entries[j * 256]);
memcpy(&dir_entries[j * 256], temp, strlen(temp) + 1); strcpy(&dir_entries[j * 256], temp);
} }
} }
} }