Changeset 5158c3af473f61e501440e1fb499271d69b6fe55
- Timestamp:
- 16/01/08 18:18:30
(9 months ago)
- Author:
- Rémi Duraffort <ivoire@videolan.org>
- git-committer:
- Rémi Duraffort <ivoire@videolan.org> 1200503910 +0000
- git-parent:
[d70106fdacae2af05ad20df231768cf59d4af191]
- git-author:
- Rémi Duraffort <ivoire@videolan.org> 1200503910 +0000
- Message:
Implementation of utf8_unlink. If someone can test this function on Windows please ?
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| rbe6a13d |
r5158c3a |
|
| 564 | 564 | |
|---|
| 565 | 565 | /** |
|---|
| | 566 | * utf8_unlink: Calls unlink() after conversion of file name to OS locale |
|---|
| | 567 | * |
|---|
| | 568 | * @param filename a UTF-8 string with the name of the file you want to delete. |
|---|
| | 569 | * @return A 0 return value indicates success. A -1 return value indicates an |
|---|
| | 570 | * error, and an error code is stored in errno |
|---|
| | 571 | */ |
|---|
| | 572 | int utf8_unlink( const char *filename ) |
|---|
| | 573 | { |
|---|
| | 574 | #if defined (WIN32) || defined (UNDER_CE) |
|---|
| | 575 | if( GetVersion() < 0x80000000 ) |
|---|
| | 576 | { |
|---|
| | 577 | /* for Windows NT and above */ |
|---|
| | 578 | wchar_t wpath[MAX_PATH + 1]; |
|---|
| | 579 | |
|---|
| | 580 | if( !MultiByteToWideChar( CP_UTF8, 0, filename, -1, wpath, MAX_PATH ) ) |
|---|
| | 581 | { |
|---|
| | 582 | errno = ENOENT; |
|---|
| | 583 | return -1; |
|---|
| | 584 | } |
|---|
| | 585 | wpath[MAX_PATH] = L'\0'; |
|---|
| | 586 | |
|---|
| | 587 | /* |
|---|
| | 588 | * unlink() cannot open files with non-“ANSI” characters on Windows. |
|---|
| | 589 | * We use _wunlink() instead. |
|---|
| | 590 | */ |
|---|
| | 591 | return _wunlink( wpath ); |
|---|
| | 592 | } |
|---|
| | 593 | #endif |
|---|
| | 594 | const char *local_name = ToLocale( filename ); |
|---|
| | 595 | |
|---|
| | 596 | if( local_name == NULL ) |
|---|
| | 597 | { |
|---|
| | 598 | errno = ENOENT; |
|---|
| | 599 | return -1; |
|---|
| | 600 | } |
|---|
| | 601 | |
|---|
| | 602 | int ret = unlink( local_name ); |
|---|
| | 603 | LocaleFree( local_name ); |
|---|
| | 604 | return ret; |
|---|
| | 605 | } |
|---|
| | 606 | |
|---|
| | 607 | |
|---|
| | 608 | |
|---|
| | 609 | /** |
|---|
| 566 | 610 | * utf8_*printf: *printf with conversion from UTF-8 to local encoding |
|---|
| 567 | 611 | */ |
|---|