Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 为什么fread()不能在Msys/MinGw下工作(跳过字节)?_C_Windows_Mingw_Fread_Xuggle - Fatal编程技术网

C 为什么fread()不能在Msys/MinGw下工作(跳过字节)?

C 为什么fread()不能在Msys/MinGw下工作(跳过字节)?,c,windows,mingw,fread,xuggle,C,Windows,Mingw,Fread,Xuggle,正在尝试在Windows下构建Xuggler。Xugler是包装到Java中用于声音处理(包括ffmpeg)的核心本机代码函数 我的Windows是x64 Win 7 prof,但所有使用的库都是32位的。我在MinGW/MSys下运行构建过程,在MSys shell下运行,脚本如下: #!/bin/sh export JAVA_HOME=/C/Program\ Files\ \(x86\)/Java/jdk1.6.0_25 export XUGGLE_HOME=/C/Xuggler PATH

正在尝试在Windows下构建Xuggler。Xugler是包装到Java中用于声音处理(包括ffmpeg)的核心本机代码函数

我的Windows是x64 Win 7 prof,但所有使用的库都是32位的。我在MinGW/MSys下运行构建过程,在MSys shell下运行,脚本如下:

#!/bin/sh
export JAVA_HOME=/C/Program\ Files\ \(x86\)/Java/jdk1.6.0_25
export XUGGLE_HOME=/C/Xuggler

PATH=$XUGGLE_HOME/bin:/C/Program\ Files\ \(x86\)/Java/jdk1.6.0_25/bin:/d/APPS/msysgit/msysgit/bin/git:/D/APPS/MinGW/bin:/bin:/D/APPS/apa    che-ant-1.8.2/bin:/D/Users/Dims/Design/MinGW/Util:$PATH
ant -Dbuild.m64=no run-tests
Ant目标最后包含一些测试,这些测试给出了一个错误。错误如下

 [exec] Running 6 tests..
 [exec] In StdioURLProtocolHandlerTest::testRead:
 [exec] ../../../../../../../../../test/csrc/com/xuggle/xuggler/io/StdioURLProtocolHandlerTest.cpp:108: Error: Expected (4546420 == totalBytes), found (4546420 != 1042)
 [exec] In StdioURLProtocolHandlerTest::testReadWrite:
 [exec] ../../../../../../../../../test/csrc/com/xuggle/xuggler/io/StdioURLProtocolHandlerTest.cpp:185: Error: Expected (4546420 == totalBytes), found (4546420 != 1042)
 [exec] In StdioURLProtocolHandlerTest::testSeek:
 [exec] ../../../../../../../../../test/csrc/com/xuggle/xuggler/io/StdioURLProtocolHandlerTest.cpp:139: Error: Expected (4546420 == totalBytes), found (4546420 != 1042)
 [exec] .
 [exec] Failed 3 of 6 tests
 [exec] Success rate: 50%
 [exec] FAIL: xugglerioTestStdioURLProtocolHandler.exe
更新1

测试代码如下:

int32_t totalBytes = 0;
do {
    unsigned char buf[2048];
    retval = handler->url_read(buf, (int)sizeof(buf));
    if (retval > 0)
         totalBytes+= retval;
} while (retval > 0);
VS_TUT_ENSURE_EQUALS("", 4546420, totalBytes);
int
StdioURLProtocolHandler :: url_read(unsigned char* buf, int size)
{
    if (!mFile)
        return -1;
    return (int) fread(buf, 1, size, mFile);
}
url\u read
代码如下:

int32_t totalBytes = 0;
do {
    unsigned char buf[2048];
    retval = handler->url_read(buf, (int)sizeof(buf));
    if (retval > 0)
         totalBytes+= retval;
} while (retval > 0);
VS_TUT_ENSURE_EQUALS("", 4546420, totalBytes);
int
StdioURLProtocolHandler :: url_read(unsigned char* buf, int size)
{
    if (!mFile)
        return -1;
    return (int) fread(buf, 1, size, mFile);
}
我不明白,在什么情况下可以返回1042???64位可能会在这里播放吗

更新2

我打印出了使用的文件名,它是

d:/......./../../../test/fixtures/testfile.flv
路径正确,但以
d://
开头,而不是以
/d/
开头

这能在Msys下发挥作用吗

更新3

我将readen字节与测试文件的实际内容进行了比较,发现fread()由于某种原因跳过了一些字节。还不知道是哪个字节,可能是CR/LF

更新4

我想与CR/LF无关

原始字节是

46 4C 56 01 05 00 00 00 09 00 00 00 00 12 00 00 F4 00 00 00 00 00 00 00 02 00 0A 6F 6E 4D 65 74 61 44 61 74 61 08 00 00 ...
46 4C 56 15 00 09 00 00 12 00 F4 00 00 00 02 0A 6F 6E 4D 65 74 61 44 61 74 61 80 00 B0 86 47 57 26 17 46 96 F6 E0 40 62 ...
读取字节是

46 4C 56 01 05 00 00 00 09 00 00 00 00 12 00 00 F4 00 00 00 00 00 00 00 02 00 0A 6F 6E 4D 65 74 61 44 61 74 61 08 00 00 ...
46 4C 56 15 00 09 00 00 12 00 F4 00 00 00 02 0A 6F 6E 4D 65 74 61 44 61 74 61 80 00 B0 86 47 57 26 17 46 96 F6 E0 40 62 ...
这是FLV文件开始。我不明白腐败的原因

01050000
如何转变为仅仅
15

更新5

文件打开操作如下所示

void
StdioURLProtocolHandlerTest :: testRead()
{
  StdioURLProtocolManager::registerProtocol("test");
  URLProtocolHandler* handler = StdioURLProtocolManager::findHandler("test:foo", 0,0);
  VS_TUT_ENSURE("", handler);

  int retval = 0;
  retval = handler->url_open(mSampleFile, URLProtocolHandler::URL_RDONLY_MODE);
  VS_TUT_ENSURE("", retval >= 0);

  int32_t totalBytes = 0;
  printf("Bytes:\n");
  do {
     //...
url_open()函数如下所示:

int StdioURLProtocolHandler :: url_open(const char *url, int flags)
{
  if (!url || !*url)
    return -1;
  reset();
  const char * mode;

  switch(flags) {
    case URLProtocolHandler::URL_RDONLY_MODE:
      mode="r";
      break;
    case URLProtocolHandler::URL_WRONLY_MODE:
      mode="w";
      break;
    case URLProtocolHandler::URL_RDWR_MODE:
          mode="r+";
          break;
        default:
      return -1;
  }

  // The URL MAY contain a protocol string.  Find it now.
  char proto[256];
  const char* protocol = URLProtocolManager::parseProtocol(proto, sizeof(proto), url);
  if (protocol)
  {
    size_t protoLen = strlen(protocol);
    // skip past it
    url = url + protoLen;
    if (*url == ':' || *url == ',')
      ++url;
  }
//  fprintf(stderr, "protocol: %s; url: %s; mode: %s\n", protocol, url, mode);
  mFile = fopen(url, mode);
  if (!mFile)
    return -1;
  return 0;
}

从今天起,应该在跨编译分支的GIT存储库中修复。我将在本周晚些时候/下周初把这个卷到树梢上


现在,stdio处理程序以二进制方式打开所有文件。

如何打开该文件?请参阅更新5。看起来不可疑,看起来可疑。在开放模式下没有“b”,但是它在linux下怎么工作呢?可能是可以设置默认值的地方?它在Windows和Linux上都可以用“b”。Linux不在乎任何方式(忽略标志,读取二进制),Windows可能会进行大量翻译。谢谢。是否建议用户
cross\u compile
为Windows编译?也就是说,我可以在Linux上运行编译器,但会得到适用于Windows的二进制文件,对吗?master现在包含此修复程序,并且在我们的ivy repo上分发的预构建jar文件包含所有操作系统。如果在Linux中生成,默认情况下将不会获得windows生成。您需要启用交叉编译(在博客中搜索如何实现)。