! Get file stats * * @param[in,out] r newlib reentrancy struct * @param[in] file Path to file * @param[out] st Pointer to file stats to fill * * @returns 0 for success * @returns -1 for error */
| 817 | * @returns -1 for error |
| 818 | */ |
| 819 | static int |
| 820 | archive_stat(struct _reent *r, |
| 821 | const char *file, |
| 822 | struct stat *st) |
| 823 | { |
| 824 | Handle fd; |
| 825 | Result rc; |
| 826 | FS_Path fs_path; |
| 827 | archive_fsdevice *device = r->deviceData; |
| 828 | |
| 829 | fs_path = archive_utf16path(r, file, &device); |
| 830 | if(fs_path.data == NULL) |
| 831 | return -1; |
| 832 | |
| 833 | if(R_SUCCEEDED(rc = FSUSER_OpenFile(&fd, device->archive, fs_path, FS_OPEN_READ, 0))) |
| 834 | { |
| 835 | archive_file_t tmpfd = { .fd = fd }; |
| 836 | rc = archive_fstat(r, &tmpfd, st); |
| 837 | FSFILE_Close(fd); |
| 838 | |
| 839 | return rc; |
| 840 | } |
| 841 | else if(R_SUCCEEDED(rc = FSUSER_OpenDirectory(&fd, device->archive, fs_path))) |
| 842 | { |
| 843 | memset(st, 0, sizeof(struct stat)); |
| 844 | st->st_nlink = 1; |
| 845 | st->st_mode = S_IFDIR | S_IRWXU | S_IRWXG | S_IRWXO; |
| 846 | FSDIR_Close(fd); |
| 847 | return 0; |
| 848 | } |
| 849 | |
| 850 | r->_errno = archive_translate_error(rc); |
| 851 | return -1; |
| 852 | } |
| 853 | |
| 854 | /*! Unlink a file |
| 855 | * |
nothing calls this directly
no test coverage detected