Skip to content

Commit

Permalink
archive_dev: Ensure path seperator for local path
Browse files Browse the repository at this point in the history
Fixes issue where fopen("test.txt","r") opens 3dstest.txt instead of test.txt.

Also correct misuse of strncat() as count applies to src not dest.

See:
devkitPro/3ds-hbmenu@8136d94
devkitPro/newlib@806a4d3
  • Loading branch information
oreo639 committed May 7, 2023
1 parent 8d90551 commit ff82d4f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions libctru/source/archive_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,11 @@ archive_fixpath(struct _reent *r,
strncpy(__ctru_dev_path_buf, path, PATH_MAX);
else
{
strncpy(__ctru_dev_path_buf, dev->cwd, PATH_MAX);
size_t cwdlen = strlen(dev->cwd);
strncpy(__ctru_dev_path_buf, dev->cwd, PATH_MAX - 1);
__ctru_dev_path_buf[PATH_MAX] = '\0';
strncat(__ctru_dev_path_buf, path, PATH_MAX);
strncat(__ctru_dev_path_buf, "/", PATH_MAX - cwdlen);
strncat(__ctru_dev_path_buf, path, PATH_MAX - cwdlen - 1);
}

if(__ctru_dev_path_buf[PATH_MAX] != 0)
Expand Down

0 comments on commit ff82d4f

Please sign in to comment.