@@ -78,14 +78,9 @@ static bool mmap_refresh(RIOMMapFileObj *mmo) {
7878 }
7979 if (mmo -> rawio ) {
8080 mmo -> fd = open_file (mmo -> filename , mmo -> perm , mmo -> mode );
81- if (mmo -> nocache ) {
82- #ifdef F_NOCACHE
83- fcntl (mmo -> fd , F_NOCACHE , 1 );
84- #endif
85- }
86- return mmo -> fd != -1 ;
81+ goto done ;
8782 }
88- int fd = open_file (mmo -> filename , mmo -> perm , mmo -> mode );
83+ const int fd = open_file (mmo -> filename , mmo -> perm , mmo -> mode );
8984 if (fd == -1 ) {
9085 return false;
9186 }
@@ -96,6 +91,7 @@ static bool mmap_refresh(RIOMMapFileObj *mmo) {
9691 }
9792 mmo -> rawio = true;
9893 mmo -> fd = fd ;
94+ done :
9995#ifdef F_NOCACHE
10096 if (mmo -> nocache ) {
10197 fcntl (mmo -> fd , F_NOCACHE , 1 );
@@ -121,8 +117,12 @@ static RIOMMapFileObj *mmap_create(RIO *io, const char *filename, int perm, int
121117 } else if (r_str_startswith (filename , "stdio://" )) {
122118 filename += strlen ("stdio://" );
123119 mmo -> rawio = true;
120+ } else if (r_str_startswith (filename , "nocache://" )) {
121+ mmo -> rawio = true;
122+ mmo -> nocache = true;
123+ } else {
124+ // TODO later: mmo->rawio = true;
124125 }
125- mmo -> nocache = r_str_startswith (filename , "nocache://" );
126126 if (mmo -> nocache ) {
127127 filename += strlen ("nocache://" );
128128 }
@@ -162,6 +162,8 @@ static bool uricheck(const char *filename) {
162162 filename += strlen ("file://" );
163163 } else if (r_str_startswith (filename , "stdio://" )) {
164164 filename += strlen ("stdio://" );
165+ } else if (r_str_startswith (filename , "nocache://" )) {
166+ filename += strlen ("nocache://" );
165167 } else {
166168 return false;
167169 }
@@ -176,9 +178,6 @@ static int r_io_def_mmap_read(RIO *io, RIODesc *fd, ut8 *buf, int count) {
176178 memset (buf , io -> Oxff , count );
177179 return count ;
178180 }
179- if (!mmo ) {
180- return -1 ;
181- }
182181 if (mmo -> rawio ) {
183182 if (lseek (mmo -> fd , mmo -> addr , SEEK_SET ) < 0 ) {
184183 return -1 ;
@@ -210,7 +209,7 @@ static int mmap_write(RIO *io, RIODesc *fd, const ut8 *buf, int count) {
210209 return write (mmo -> fd , buf , count );
211210 }
212211
213- if (mmo && mmo -> buf ) {
212+ if (mmo -> buf ) {
214213 if (!(mmo -> perm & R_PERM_W )) {
215214 return -1 ;
216215 }
@@ -222,6 +221,7 @@ static int mmap_write(RIO *io, RIODesc *fd, const ut8 *buf, int count) {
222221
223222 int len = r_file_mmap_write (mmo -> filename , addr , buf , count );
224223 if (len != count ) {
224+ // XXX this is wrong. what about non-fd baked mmos?
225225 // aim to hack some corner cases?
226226 if (lseek (fd -> fd , addr , 0 ) < 0 ) {
227227 return -1 ;
0 commit comments