Skip to content

Commit

Permalink
contribs: port libflac to WinRT
Browse files Browse the repository at this point in the history
Create two patches that remove calls to forbiden funtions in libflac and replace
with authorized function if necessary

Signed-off-by: Hugo Beauzée-Luyssen <[email protected]>
  • Loading branch information
DaemonSnake authored and jbkempf committed May 16, 2016
1 parent f760378 commit 4b79110
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
39 changes: 39 additions & 0 deletions contrib/src/flac/console_write.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--- flac/src/share/win_utf8_io/win_utf8_io.c.orig 2016-05-13 11:27:58.508525189 +0200
+++ flac/src/share/win_utf8_io/win_utf8_io.c 2016-05-13 12:16:51.951811662 +0200
@@ -162,33 +162,14 @@
/* get the console width in characters */
int win_get_console_width(void)
{
- int width = 80;
- CONSOLE_SCREEN_BUFFER_INFO csbi;
- HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
- if (GetConsoleScreenBufferInfo(hOut, &csbi) != 0) width = csbi.dwSize.X;
- return width;
+ return 80;
}

/* print functions */
-
int print_console(FILE *stream, const wchar_t *text, size_t len)
{
- static HANDLE hOut;
- static HANDLE hErr;
- DWORD out;
- hOut = GetStdHandle(STD_OUTPUT_HANDLE);
- hErr = GetStdHandle(STD_ERROR_HANDLE);
- if (stream == stdout && hOut != INVALID_HANDLE_VALUE && GetFileType(hOut) == FILE_TYPE_CHAR) {
- if (WriteConsoleW(hOut, text, len, &out, NULL) == 0) return -1;
- return out;
- } else if (stream == stderr && hErr != INVALID_HANDLE_VALUE && GetFileType(hErr) == FILE_TYPE_CHAR) {
- if (WriteConsoleW(hErr, text, len, &out, NULL) == 0) return -1;
- return out;
- } else {
- int ret = fputws(text, stream);
- if (ret < 0) return ret;
- return len;
- }
+ (void)stream, (void)text;
+ return len;
}

int printf_utf8(const char *format, ...)
38 changes: 38 additions & 0 deletions contrib/src/flac/remove_blocking_code_useless_flaclib.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
--- flac/src/share/grabbag/file.c.orig 2014-11-27 02:19:47.048799991 +0100
+++ flac/src/share/grabbag/file.c 2016-05-13 16:32:33.727811662 +0200
@@ -117,34 +117,7 @@
FLAC__bool grabbag__file_are_same(const char *f1, const char *f2)
{
#if defined _MSC_VER || defined __MINGW32__
- /* see
- * http://www.hydrogenaudio.org/forums/index.php?showtopic=49439&pid=444300&st=0
- * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/getfileinformationbyhandle.asp
- * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/by_handle_file_information_str.asp
- * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/createfile.asp
- * apparently both the files have to be open at the same time for the comparison to work
- */
- FLAC__bool same = false;
- BY_HANDLE_FILE_INFORMATION info1, info2;
- HANDLE h1, h2;
- BOOL ok = 1;
- h1 = CreateFile_utf8(f1, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
- h2 = CreateFile_utf8(f2, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
- if(h1 == INVALID_HANDLE_VALUE || h2 == INVALID_HANDLE_VALUE)
- ok = 0;
- ok &= GetFileInformationByHandle(h1, &info1);
- ok &= GetFileInformationByHandle(h2, &info2);
- if(ok)
- same =
- info1.dwVolumeSerialNumber == info2.dwVolumeSerialNumber &&
- info1.nFileIndexHigh == info2.nFileIndexHigh &&
- info1.nFileIndexLow == info2.nFileIndexLow
- ;
- if(h1 != INVALID_HANDLE_VALUE)
- CloseHandle(h1);
- if(h2 != INVALID_HANDLE_VALUE)
- CloseHandle(h2);
- return same;
+ return true;
#else
struct flac_stat_s s1, s2;
return f1 && f2 && flac_stat(f1, &s1) == 0 && flac_stat(f2, &s2) == 0 && s1.st_ino == s2.st_ino && s1.st_dev == s2.st_dev;
4 changes: 4 additions & 0 deletions contrib/src/flac/rules.mak
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ $(TARBALLS)/flac-$(FLAC_VERSION).tar.xz:

flac: flac-$(FLAC_VERSION).tar.xz .sum-flac
$(UNPACK)
ifdef HAVE_WINRT
$(APPLY) $(SRC)/flac/console_write.patch
$(APPLY) $(SRC)/flac/remove_blocking_code_useless_flaclib.patch
endif
ifdef HAVE_DARWIN_OS
cd $(UNPACK_DIR) && sed -e 's,-dynamiclib,-dynamiclib -arch $(ARCH),' -i.orig configure
endif
Expand Down

0 comments on commit 4b79110

Please sign in to comment.