Cross-platform wrapper for qoi_write that handles Unicode paths properly
| 38 | |
| 39 | // Cross-platform wrapper for qoi_write that handles Unicode paths properly |
| 40 | int qoiWritePath( const fs::path &path, const void *data, const qoi_desc *desc ) |
| 41 | { |
| 42 | #if defined( CINDER_MSW ) |
| 43 | FILE *f = _wfopen( path.wstring().c_str(), L"wb" ); |
| 44 | #else |
| 45 | FILE *f = fopen( path.string().c_str(), "wb" ); |
| 46 | #endif |
| 47 | |
| 48 | if( ! f ) |
| 49 | return 0; |
| 50 | |
| 51 | int size; |
| 52 | void *encoded = qoi_encode( data, desc, &size ); |
| 53 | if( ! encoded ) { |
| 54 | fclose( f ); |
| 55 | return 0; |
| 56 | } |
| 57 | |
| 58 | fwrite( encoded, 1, size, f ); |
| 59 | fflush( f ); |
| 60 | int err = ferror( f ); |
| 61 | fclose( f ); |
| 62 | |
| 63 | free( encoded ); |
| 64 | return err ? 0 : size; |
| 65 | } |
| 66 | |
| 67 | } // anonymous namespace |
| 68 |
no test coverage detected