diff options
author | Steve Bavin <pondlife@pondlife.me> | 2009-02-27 21:25:17 +0000 |
---|---|---|
committer | Steve Bavin <pondlife@pondlife.me> | 2009-02-27 21:25:17 +0000 |
commit | b61f0c688483c8f17ebcf12ae3d1fb20cdd59ab9 (patch) | |
tree | ad4a773474a3cdf9c7d500cd78d12e2c8b382d9e /uisimulator | |
parent | 6eea66fbc102e383b7b860b6209e1ee5af5ff6bd (diff) | |
download | rockbox-b61f0c688483c8f17ebcf12ae3d1fb20cdd59ab9.tar.gz rockbox-b61f0c688483c8f17ebcf12ae3d1fb20cdd59ab9.zip |
FS#9964 take 2. Including the whole patch is a good idea.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@20133 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'uisimulator')
-rw-r--r-- | uisimulator/common/io.c | 125 |
1 files changed, 21 insertions, 104 deletions
diff --git a/uisimulator/common/io.c b/uisimulator/common/io.c index d6c197677b..d87e331970 100644 --- a/uisimulator/common/io.c +++ b/uisimulator/common/io.c | |||
@@ -140,7 +140,7 @@ extern int _wrmdir(const wchar_t*); | |||
140 | 140 | ||
141 | #ifdef HAVE_DIRCACHE | 141 | #ifdef HAVE_DIRCACHE |
142 | void dircache_remove(const char *name); | 142 | void dircache_remove(const char *name); |
143 | void dircache_rename(const char *oldpath, const char *newpath); | 143 | void dircache_rename(const char *oldname, const char *newname); |
144 | #endif | 144 | #endif |
145 | 145 | ||
146 | 146 | ||
@@ -264,11 +264,11 @@ static const char *get_sim_pathname(const char *name) | |||
264 | 264 | ||
265 | if(name[0] == '/') | 265 | if(name[0] == '/') |
266 | { | 266 | { |
267 | snprintf(buffer, sizeof(buffer), "%s%s", | 267 | snprintf(buffer, sizeof(buffer), "%s%s", |
268 | sim_root_dir != NULL ? sim_root_dir : SIMULATOR_DEFAULT_ROOT, name); | 268 | sim_root_dir != NULL ? sim_root_dir : SIMULATOR_DEFAULT_ROOT, name); |
269 | return buffer; | 269 | return buffer; |
270 | } | 270 | } |
271 | DEBUGF("warning, filename lacks leading slash: %s\n", name); | 271 | fprintf(stderr, "WARNING, bad file name lacks slash: %s\n", name); |
272 | return name; | 272 | return name; |
273 | } | 273 | } |
274 | #else | 274 | #else |
@@ -308,7 +308,7 @@ struct sim_dirent *sim_readdir(MYDIR *dir) | |||
308 | strcpy((char *)secret.d_name, OS_TO_UTF8(x11->d_name)); | 308 | strcpy((char *)secret.d_name, OS_TO_UTF8(x11->d_name)); |
309 | 309 | ||
310 | /* build file name */ | 310 | /* build file name */ |
311 | snprintf(buffer, sizeof(buffer), "%s/%s", | 311 | snprintf(buffer, sizeof(buffer), "%s/%s", |
312 | get_sim_pathname(dir->name), secret.d_name); | 312 | get_sim_pathname(dir->name), secret.d_name); |
313 | STAT(buffer, &s); /* get info */ | 313 | STAT(buffer, &s); /* get info */ |
314 | 314 | ||
@@ -337,62 +337,30 @@ void sim_closedir(MYDIR *dir) | |||
337 | 337 | ||
338 | int sim_open(const char *name, int o) | 338 | int sim_open(const char *name, int o) |
339 | { | 339 | { |
340 | char buffer[MAX_PATH]; /* sufficiently big */ | ||
341 | int opts = rockbox2sim(o); | 340 | int opts = rockbox2sim(o); |
342 | int ret; | 341 | int ret; |
343 | 342 | ||
344 | if (num_openfiles >= MAX_OPEN_FILES) | 343 | if (num_openfiles >= MAX_OPEN_FILES) |
345 | return -2; | 344 | return -2; |
346 | 345 | ||
347 | #ifndef __PCTOOL__ | 346 | ret = OPEN(get_sim_pathname(name), opts, 0666); |
348 | if(name[0] == '/') | ||
349 | { | ||
350 | snprintf(buffer, sizeof(buffer), "%s%s", get_sim_rootdir(), name); | ||
351 | |||
352 | /* debugf("We open the real file '%s'\n", buffer); */ | ||
353 | if (num_openfiles < MAX_OPEN_FILES) | ||
354 | { | ||
355 | ret = OPEN(buffer, opts, 0666); | ||
356 | if (ret >= 0) num_openfiles++; | ||
357 | return ret; | ||
358 | } | ||
359 | } | ||
360 | |||
361 | fprintf(stderr, "WARNING, bad file name lacks slash: %s\n", | ||
362 | name); | ||
363 | return -1; | ||
364 | #else | ||
365 | ret = OPEN(name, opts, 0666); | ||
366 | if (ret >= 0) | 347 | if (ret >= 0) |
367 | num_openfiles++; | 348 | num_openfiles++; |
368 | return ret; | 349 | return ret; |
369 | #endif | ||
370 | } | 350 | } |
371 | 351 | ||
372 | int sim_close(int fd) | 352 | int sim_close(int fd) |
373 | { | 353 | { |
374 | int ret; | 354 | int ret; |
375 | ret = CLOSE(fd); | 355 | ret = CLOSE(fd); |
376 | if (ret == 0) num_openfiles--; | 356 | if (ret == 0) |
357 | num_openfiles--; | ||
377 | return ret; | 358 | return ret; |
378 | } | 359 | } |
379 | 360 | ||
380 | int sim_creat(const char *name) | 361 | int sim_creat(const char *name) |
381 | { | 362 | { |
382 | #ifndef __PCTOOL__ | 363 | return OPEN(get_sim_pathname(name), O_BINARY | O_WRONLY | O_CREAT | O_TRUNC, 0666); |
383 | char buffer[MAX_PATH]; /* sufficiently big */ | ||
384 | if(name[0] == '/') | ||
385 | { | ||
386 | snprintf(buffer, sizeof(buffer), "%s%s", get_sim_rootdir(), name); | ||
387 | |||
388 | /* debugf("We create the real file '%s'\n", buffer); */ | ||
389 | return OPEN(buffer, O_BINARY | O_WRONLY | O_CREAT | O_TRUNC, 0666); | ||
390 | } | ||
391 | fprintf(stderr, "WARNING, bad file name lacks slash: %s\n", name); | ||
392 | return -1; | ||
393 | #else | ||
394 | return OPEN(name, O_BINARY | O_WRONLY | O_CREAT | O_TRUNC, 0666); | ||
395 | #endif | ||
396 | } | 364 | } |
397 | 365 | ||
398 | ssize_t sim_read(int fd, void *buf, size_t count) | 366 | ssize_t sim_read(int fd, void *buf, size_t count) |
@@ -432,79 +400,28 @@ ssize_t sim_write(int fd, const void *buf, size_t count) | |||
432 | 400 | ||
433 | int sim_mkdir(const char *name) | 401 | int sim_mkdir(const char *name) |
434 | { | 402 | { |
435 | #ifdef __PCTOOL__ | 403 | return MKDIR(get_sim_pathname(name), 0777); |
436 | return MKDIR(name, 0777); | ||
437 | #else | ||
438 | char buffer[MAX_PATH]; /* sufficiently big */ | ||
439 | |||
440 | snprintf(buffer, sizeof(buffer), "%s%s", get_sim_rootdir(), name); | ||
441 | |||
442 | /* debugf("We create the real directory '%s'\n", buffer); */ | ||
443 | return MKDIR(buffer, 0777); | ||
444 | #endif | ||
445 | } | 404 | } |
446 | 405 | ||
447 | int sim_rmdir(const char *name) | 406 | int sim_rmdir(const char *name) |
448 | { | 407 | { |
449 | #ifdef __PCTOOL__ | 408 | return RMDIR(get_sim_pathname(name)); |
450 | return RMDIR(name); | ||
451 | #else | ||
452 | char buffer[MAX_PATH]; /* sufficiently big */ | ||
453 | if(name[0] == '/') | ||
454 | { | ||
455 | snprintf(buffer, sizeof(buffer), "%s%s", get_sim_rootdir(), name); | ||
456 | |||
457 | /* debugf("We remove the real directory '%s'\n", buffer); */ | ||
458 | return RMDIR(buffer); | ||
459 | } | ||
460 | return RMDIR(name); | ||
461 | #endif | ||
462 | } | 409 | } |
463 | 410 | ||
464 | int sim_remove(const char *name) | 411 | int sim_remove(const char *name) |
465 | { | 412 | { |
466 | #ifdef __PCTOOL__ | ||
467 | return REMOVE(name); | ||
468 | #else | ||
469 | char buffer[MAX_PATH]; /* sufficiently big */ | ||
470 | |||
471 | #ifdef HAVE_DIRCACHE | 413 | #ifdef HAVE_DIRCACHE |
472 | dircache_remove(name); | 414 | dircache_remove(name); |
473 | #endif | 415 | #endif |
474 | 416 | return REMOVE(get_sim_pathname(name)); | |
475 | if(name[0] == '/') { | ||
476 | snprintf(buffer, sizeof(buffer), "%s%s", get_sim_rootdir(), name); | ||
477 | |||
478 | /* debugf("We remove the real file '%s'\n", buffer); */ | ||
479 | return REMOVE(buffer); | ||
480 | } | ||
481 | return REMOVE(name); | ||
482 | #endif | ||
483 | } | 417 | } |
484 | 418 | ||
485 | int sim_rename(const char *oldpath, const char* newpath) | 419 | int sim_rename(const char *oldname, const char *newname) |
486 | { | 420 | { |
487 | #ifdef __PCTOOL__ | ||
488 | return RENAME(oldpath, newpath); | ||
489 | #else | ||
490 | char buffer1[MAX_PATH]; | ||
491 | char buffer2[MAX_PATH]; | ||
492 | |||
493 | #ifdef HAVE_DIRCACHE | 421 | #ifdef HAVE_DIRCACHE |
494 | dircache_rename(oldpath, newpath); | 422 | dircache_rename(oldname, newname); |
495 | #endif | ||
496 | |||
497 | if(oldpath[0] == '/') { | ||
498 | snprintf(buffer1, sizeof(buffer1), "%s%s", get_sim_rootdir(), | ||
499 | oldpath); | ||
500 | snprintf(buffer2, sizeof(buffer2), "%s%s", get_sim_rootdir(), | ||
501 | newpath); | ||
502 | |||
503 | /* debugf("We rename the real file '%s' to '%s'\n", buffer1, buffer2); */ | ||
504 | return RENAME(buffer1, buffer2); | ||
505 | } | ||
506 | return -1; | ||
507 | #endif | 423 | #endif |
424 | return RENAME(get_sim_pathname(oldname), get_sim_pathname(newname)); | ||
508 | } | 425 | } |
509 | 426 | ||
510 | /* rockbox off_t may be different from system off_t */ | 427 | /* rockbox off_t may be different from system off_t */ |
@@ -588,11 +505,10 @@ int sim_fsync(int fd) | |||
588 | #include <dlfcn.h> | 505 | #include <dlfcn.h> |
589 | #endif | 506 | #endif |
590 | 507 | ||
591 | #define TEMP_CODEC_FILE SIMULATOR_DEFAULT_ROOT "/_temp_codec%d.dll" | ||
592 | |||
593 | void *sim_codec_load_ram(char* codecptr, int size, void **pd) | 508 | void *sim_codec_load_ram(char* codecptr, int size, void **pd) |
594 | { | 509 | { |
595 | void *hdr; | 510 | void *hdr; |
511 | char name[MAX_PATH]; | ||
596 | char path[MAX_PATH]; | 512 | char path[MAX_PATH]; |
597 | int fd; | 513 | int fd; |
598 | int codec_count; | 514 | int codec_count; |
@@ -608,8 +524,8 @@ void *sim_codec_load_ram(char* codecptr, int size, void **pd) | |||
608 | to find an unused filename */ | 524 | to find an unused filename */ |
609 | for (codec_count = 0; codec_count < 10; codec_count++) | 525 | for (codec_count = 0; codec_count < 10; codec_count++) |
610 | { | 526 | { |
611 | snprintf(path, sizeof(path), TEMP_CODEC_FILE, codec_count); | 527 | snprintf(name, sizeof(name), "/_temp_codec%d.dll", codec_count); |
612 | 528 | snprintf(path, sizeof(path), "%s", get_sim_pathname(name)); | |
613 | fd = OPEN(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRWXU); | 529 | fd = OPEN(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, S_IRWXU); |
614 | if (fd >= 0) | 530 | if (fd >= 0) |
615 | break; /* Created a file ok */ | 531 | break; /* Created a file ok */ |
@@ -620,7 +536,8 @@ void *sim_codec_load_ram(char* codecptr, int size, void **pd) | |||
620 | return NULL; | 536 | return NULL; |
621 | } | 537 | } |
622 | 538 | ||
623 | if (write(fd, codecptr, size) != size) { | 539 | if (write(fd, codecptr, size) != size) |
540 | { | ||
624 | DEBUGF("write failed"); | 541 | DEBUGF("write failed"); |
625 | return NULL; | 542 | return NULL; |
626 | } | 543 | } |
@@ -628,7 +545,7 @@ void *sim_codec_load_ram(char* codecptr, int size, void **pd) | |||
628 | 545 | ||
629 | /* Now load the library. */ | 546 | /* Now load the library. */ |
630 | *pd = dlopen(path, RTLD_NOW); | 547 | *pd = dlopen(path, RTLD_NOW); |
631 | if (*pd == NULL) | 548 | if (*pd == NULL) |
632 | { | 549 | { |
633 | DEBUGF("failed to load %s\n", path); | 550 | DEBUGF("failed to load %s\n", path); |
634 | #ifdef WIN32 | 551 | #ifdef WIN32 |
@@ -661,7 +578,7 @@ void *sim_plugin_load(char *plugin, void **pd) | |||
661 | char buf[MAX_PATH]; | 578 | char buf[MAX_PATH]; |
662 | #endif | 579 | #endif |
663 | 580 | ||
664 | snprintf(path, sizeof(path), SIMULATOR_DEFAULT_ROOT "%s", plugin); | 581 | snprintf(path, sizeof(path), "%s", get_sim_pathname(plugin)); |
665 | 582 | ||
666 | *pd = NULL; | 583 | *pd = NULL; |
667 | 584 | ||