@@ -36,7 +36,8 @@ FileImplPtr VFSImpl::open(const char* fpath, const char* mode, const bool create
36
36
return FileImplPtr ();
37
37
}
38
38
39
- sprintf (temp," %s%s" , _mountpoint, fpath);
39
+ strcpy (temp, _mountpoint);
40
+ strcat (temp, fpath);
40
41
41
42
struct stat st;
42
43
// file found
@@ -136,19 +137,25 @@ bool VFSImpl::rename(const char* pathFrom, const char* pathTo)
136
137
log_e (" %s does not exists" , pathFrom);
137
138
return false ;
138
139
}
139
- char * temp1 = (char *)malloc (strlen (pathFrom)+strlen (_mountpoint)+1 );
140
+ size_t mountpointLen = strlen (_mountpoint);
141
+ char * temp1 = (char *)malloc (strlen (pathFrom)+mountpointLen+1 );
140
142
if (!temp1) {
141
143
log_e (" malloc failed" );
142
144
return false ;
143
145
}
144
- char * temp2 = (char *)malloc (strlen (pathTo)+strlen (_mountpoint) +1 );
146
+ char * temp2 = (char *)malloc (strlen (pathTo)+mountpointLen +1 );
145
147
if (!temp2) {
146
148
free (temp1);
147
149
log_e (" malloc failed" );
148
150
return false ;
149
151
}
150
- sprintf (temp1," %s%s" , _mountpoint, pathFrom);
151
- sprintf (temp2," %s%s" , _mountpoint, pathTo);
152
+
153
+ strcpy (temp1, _mountpoint);
154
+ strcat (temp1, pathFrom);
155
+
156
+ strcpy (temp2, _mountpoint);
157
+ strcat (temp2, pathTo);
158
+
152
159
auto rc = ::rename (temp1, temp2);
153
160
free (temp1);
154
161
free (temp2);
@@ -182,7 +189,10 @@ bool VFSImpl::remove(const char* fpath)
182
189
log_e (" malloc failed" );
183
190
return false ;
184
191
}
185
- sprintf (temp," %s%s" , _mountpoint, fpath);
192
+
193
+ strcpy (temp, _mountpoint);
194
+ strcat (temp, fpath);
195
+
186
196
auto rc = unlink (temp);
187
197
free (temp);
188
198
return rc == 0 ;
@@ -211,7 +221,10 @@ bool VFSImpl::mkdir(const char *fpath)
211
221
log_e (" malloc failed" );
212
222
return false ;
213
223
}
214
- sprintf (temp," %s%s" , _mountpoint, fpath);
224
+
225
+ strcpy (temp, _mountpoint);
226
+ strcat (temp, fpath);
227
+
215
228
auto rc = ::mkdir (temp, ACCESSPERMS);
216
229
free (temp);
217
230
return rc == 0 ;
@@ -244,7 +257,10 @@ bool VFSImpl::rmdir(const char *fpath)
244
257
log_e (" malloc failed" );
245
258
return false ;
246
259
}
247
- sprintf (temp," %s%s" , _mountpoint, fpath);
260
+
261
+ strcpy (temp, _mountpoint);
262
+ strcat (temp, fpath);
263
+
248
264
auto rc = ::rmdir (temp);
249
265
free (temp);
250
266
return rc == 0 ;
@@ -265,7 +281,9 @@ VFSFileImpl::VFSFileImpl(VFSImpl* fs, const char* fpath, const char* mode)
265
281
if (!temp) {
266
282
return ;
267
283
}
268
- sprintf (temp," %s%s" , _fs->_mountpoint , fpath);
284
+
285
+ strcpy (temp, _fs->_mountpoint );
286
+ strcat (temp, fpath);
269
287
270
288
_path = strdup (fpath);
271
289
if (!_path) {
@@ -362,7 +380,10 @@ void VFSFileImpl::_getStat() const
362
380
if (!temp) {
363
381
return ;
364
382
}
365
- sprintf (temp," %s%s" , _fs->_mountpoint , _path);
383
+
384
+ strcpy (temp, _fs->_mountpoint );
385
+ strcat (temp, _path);
386
+
366
387
if (!stat (temp, &_stat)) {
367
388
_written = false ;
368
389
}
@@ -466,14 +487,27 @@ FileImplPtr VFSFileImpl::openNextFile(const char* mode)
466
487
if (file->d_type != DT_REG && file->d_type != DT_DIR) {
467
488
return openNextFile (mode);
468
489
}
469
- String fname = String (file->d_name );
470
- String name = String (_path);
471
- if (!fname.startsWith (" /" ) && !name.endsWith (" /" )) {
472
- name += " /" ;
490
+
491
+ size_t pathLen = strlen (_path);
492
+ size_t fileNameLen = strlen (file->d_name );
493
+ char * name = (char *)malloc (pathLen+fileNameLen+2 );
494
+
495
+ if (name == NULL ) {
496
+ return FileImplPtr ();
473
497
}
474
- name += fname;
475
498
476
- return std::make_shared<VFSFileImpl>(_fs, name.c_str (), mode);
499
+ strcpy (name, _path);
500
+
501
+ if ((file->d_name [0 ] != ' /' ) && (_path[pathLen - 1 ] != ' /' ))
502
+ {
503
+ strcat (name, " /" );
504
+ }
505
+
506
+ strcat (name, file->d_name );
507
+
508
+ FileImplPtr fileImplPtr = std::make_shared<VFSFileImpl>(_fs, name, mode);
509
+ free (name);
510
+ return fileImplPtr;
477
511
}
478
512
479
513
void VFSFileImpl::rewindDirectory (void )
0 commit comments