]>
iEval git - fdkaac.git/blob - src/compat_win32.c
2 * Copyright (C) 2013 nu774
3 * For conditions of distribution and use, see copyright notice in COPYING
18 #include <sys/timeb.h>
20 #define WIN32_LEAN_AND_MEAN
29 int __wgetmainargs(int *, wchar_t ***, wchar_t ***, int, _startupinfo
*);
31 int64_t aacenc_timer(void)
35 return (int64_t)tv
.time
* 1000 + tv
.millitm
;
39 int codepage_decode_wchar(int codepage
, const char *from
, wchar_t **to
)
41 int nc
= MultiByteToWideChar(codepage
, 0, from
, -1, 0, 0);
44 *to
= malloc(nc
* sizeof(wchar_t));
45 MultiByteToWideChar(codepage
, 0, from
, -1, *to
, nc
);
50 int codepage_encode_wchar(int codepage
, const wchar_t *from
, char **to
)
52 int nc
= WideCharToMultiByte(codepage
, 0, from
, -1, 0, 0, 0, 0);
56 WideCharToMultiByte(codepage
, 0, from
, -1, *to
, nc
, 0, 0);
60 FILE *aacenc_fopen(const char *name
, const char *mode
)
62 wchar_t *wname
, *wmode
;
65 if (strcmp(name
, "-") == 0) {
66 fp
= (mode
[0] == 'r') ? stdin
: stdout
;
67 _setmode(_fileno(fp
), _O_BINARY
);
69 codepage_decode_wchar(CP_UTF8
, name
, &wname
);
70 codepage_decode_wchar(CP_UTF8
, mode
, &wmode
);
71 fp
= _wfopen(wname
, wmode
);
78 void aacenc_getmainargs(int *argc
, char ***argv
)
81 wchar_t **wargv
, **envp
;
82 _startupinfo si
= { 0 };
84 __wgetmainargs(argc
, &wargv
, &envp
, 1, &si
);
85 *argv
= malloc((*argc
+ 1) * sizeof(char*));
86 for (i
= 0; i
< *argc
; ++i
)
87 codepage_encode_wchar(CP_UTF8
, wargv
[i
], &(*argv
)[i
]);
91 char *aacenc_to_utf8(const char *s
)
96 #if defined(__MINGW32__) && !defined(HAVE__VSCPRINTF)
97 int _vscprintf(const char *fmt
, va_list ap
)
99 static int (*fp_vscprintf
)(const char *, va_list) = 0;
101 HANDLE h
= GetModuleHandleA("msvcrt.dll");
102 FARPROC fp
= GetProcAddress(h
, "_vscprintf");
103 InterlockedCompareExchangePointer(&fp_vscprintf
, fp
, 0);
105 assert(fp_vscprintf
);
106 return fp_vscprintf(fmt
, ap
);
110 int aacenc_fprintf(FILE *fp
, const char *fmt
, ...)
114 HANDLE fh
= (HANDLE
)_get_osfhandle(_fileno(fp
));
116 if (GetFileType(fh
) != FILE_TYPE_CHAR
) {
118 cnt
= vfprintf(fp
, fmt
, ap
);
126 cnt
= _vscprintf(fmt
, ap
);
132 cnt
= _vsnprintf(s
, cnt
+ 1, fmt
, ap
);
135 codepage_decode_wchar(CP_UTF8
, s
, &ws
);
138 WriteConsoleW(fh
, ws
, cnt
, &nw
, 0);
144 const char *aacenc_basename(const char *path
)
147 * Since path is encoded with UTF-8, naive usage of strrchr() shoule be safe.
149 const char *p
= strrchr(path
, '/');
150 const char *q
= strrchr(path
, '\\');
151 const char *r
= strrchr(path
, ':');
154 return p
? p
+ 1 : path
;
This page took 0.043675 seconds and 4 git commands to generate.