Wrapper for fopen in Windows and OSes that implement POSIX

This is a wrapper that I wrote for Vrok to make fopen behave sanely and accept UTF8 strings on all systems. The defines FOPEN_RB, FOPEN_WB…etc had to be defined since systems other than Windows do not have a binary switch for fopen. You can add this code to a header and use fopenu instead of fopen, on POSIX systems there will be no overhead for calling fopenu since it’s just a #define.

#include <cstdio>
#if defined(_WIN32) && defined(UNICODE)
#include <winnls.h>
inline FILE *fopenu(const char *path,const char *opt){
    wchar_t wpath[1024];
    wchar_t wopt[8];
    MultiByteToWideChar(CP_UTF8, 0, path, -1, wpath, 1024);
    MultiByteToWideChar(CP_UTF8, 0, opt, -1, wopt, 8);

    return _wfopen(wpath, wopt);
#define FOPEN_RB "rb"
#define FOPEN_WB "wb"
#define FOPEN_AB "wb+"
#define fopenu fopen
#define FOPEN_RB "r"
#define FOPEN_WB "w"
#define FOPEN_AB "w+"