add newlib 1.20.0 patches for pspsdk
[rofl0r-mmix-cross.git] / patches / newlib-1.20.0-psp_dirent.diff
blobed6830a7ca036ab57959161ec03ccc46ff59f03e
1 From a739f92a588c7566a7f38d27f1ff87af5dc93f7f Mon Sep 17 00:00:00 2001
2 From: rofl0r <rofl0r@users.noreply.github.com>
3 Date: Wed, 16 Mar 2022 23:19:19 +0000
4 Subject: [PATCH] fix dirent struct
6 the struct wasnt quite like posix demands, and breaks the build with
7 latest pspsdk.
8 ---
9 newlib/libc/sys/psp/libcglue.c | 10 +++++----
10 newlib/libc/sys/psp/sys/dirent.h | 35 ++++++++++++++++++++++----------
11 2 files changed, 30 insertions(+), 15 deletions(-)
13 diff --git a/newlib/libc/sys/psp/libcglue.c b/newlib/libc/sys/psp/libcglue.c
14 index d64ba4f..9821ae9 100644
15 --- a/newlib/libc/sys/psp/libcglue.c
16 +++ b/newlib/libc/sys/psp/libcglue.c
17 @@ -414,11 +414,9 @@ DIR *opendir(const char *filename)
18 struct dirent *readdir(DIR *dirp)
20 int ret;
21 + SceIoDirent scede = {0};
23 - /* Zero the dirent, to avoid possible problems with sceIoDread */
24 - memset(&dirp->de, 0, sizeof(struct dirent));
26 - ret = sceIoDread(dirp->uid, (SceIoDirent *)&dirp->de);
27 + ret = sceIoDread(dirp->uid, &scede);
28 if (ret == 0) {
29 /* EOF */
30 errno = 0;
31 @@ -428,6 +426,10 @@ struct dirent *readdir(DIR *dirp)
32 (void) __psp_set_errno(ret);
33 return NULL;
35 + memset(&dirp->de, 0, sizeof(struct dirent));
36 + dirp->de.d_reclen = strlen(scede.d_name);
37 + memcpy(dirp->de.d_name, scede.d_name, dirp->de.d_reclen);
38 + /* FIXME figure out the right values for rest of the dirent struct */
40 return &dirp->de;
42 diff --git a/newlib/libc/sys/psp/sys/dirent.h b/newlib/libc/sys/psp/sys/dirent.h
43 index 26e2ccc..5007857 100644
44 --- a/newlib/libc/sys/psp/sys/dirent.h
45 +++ b/newlib/libc/sys/psp/sys/dirent.h
46 @@ -7,25 +7,38 @@
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
51 -#include <pspiofilemgr_dirent.h>
54 #define MAXNAMLEN 255
56 -/* Same as SceIoDirent, just with a different name. */
57 struct dirent {
58 - /** File status. */
59 - SceIoStat d_stat;
60 - /** File name. */
61 - char d_name[256];
62 - /** Device-specific data. */
63 - void * d_private;
64 - int dummy;
65 + ino_t d_fileno; /* file number of entry */
66 + off_t d_off; /* Not an offset; see below */
67 + unsigned short int d_reclen; /* Length of this record */
68 + unsigned char d_type; /* Type of file; not supported by all fs */
69 + char d_name[MAXNAMLEN+1];
72 +#define DT_UNKNOWN 0
73 +#define DT_FIFO 1
74 +#define DT_CHR 2
75 +#define DT_DIR 4
76 +#define DT_BLK 6
77 +#define DT_REG 8
78 +#define DT_LNK 10
79 +#define DT_SOCK 12
80 +#define DT_WHT 14
82 +#include <pspiofilemgr_dirent.h>
84 typedef struct {
85 SceUID uid;
86 struct dirent de;
87 + int dd_fd; /* directory file */
88 + int dd_loc; /* position in buffer */
89 + int dd_seek;
90 + char *dd_buf; /* buffer */
91 + int dd_len; /* buffer length */
92 + int dd_size; /* amount of data in buffer */
93 } DIR;
95 DIR *opendir (const char *);
96 --
97 2.25.0