c++ fopen 返回一个带有的文件 *

发布于 2024-07-23 03:40:09 字数 621 浏览 4 评论 0原文

我从 libjpeg 示例复制了这段代码,并将其传递给标准文件;

FILE *soureFile;
if ((soureFile = fopen(sourceFilename, "rb")) == NULL)
{
    fprintf(stderr, "can't open %s\n", sourceFilename);
    exit(1);
}

jpeg_stdio_src(&jpegDecompress, soureFile);
jpeg_read_header(&jpegDecompress, true);

它会导致文件指针不包含任何信息,因此会在最后一行因访问冲突而中断。 有任何想法吗?

编辑:根据托比亚斯的建议,fopen 确实可以正常打开文件,但 jpeg_read_header 又会失败,并且仍然存在访问冲突。

编辑:经过更多挖掘
ijg 支持 JPEG - 获取访问冲突

I copied this code from the libjpeg example and im passing it standard files;

FILE *soureFile;
if ((soureFile = fopen(sourceFilename, "rb")) == NULL)
{
    fprintf(stderr, "can't open %s\n", sourceFilename);
    exit(1);
}

jpeg_stdio_src(&jpegDecompress, soureFile);
jpeg_read_header(&jpegDecompress, true);

It results in a file pointer that contains no information and therefore breaks on the last line with access violations.
Any ideas?

EDIT: On Tobias' advice the fopen does appear to open the file ok but the jpeg_read_header is in turn failing with the access violation still.

EDIT: After a little more digging
JPEG support with ijg - getting access violation

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

软甜啾 2024-07-30 03:40:11

使用 strerror 或 perror 获取确切原因:

FILE *soureFile;
if ((soureFile = fopen(sourceFilename, "rb")) == NULL)
{
    perror("fopen failed");
    exit(1);
}

Use strerror or perror to get exact reason:

FILE *soureFile;
if ((soureFile = fopen(sourceFilename, "rb")) == NULL)
{
    perror("fopen failed");
    exit(1);
}
小清晰的声音 2024-07-30 03:40:11

select 未损坏” 。

如果 fopen 返回了一个有效的文件指针,并且 jpeg_read_header 无法使用它,则表明这两个语句之间有人对其做了坏事。

两者之间唯一的一个是 jpg_stdio_src 调用,如果满足所有先决条件,该调用就不会失败。

底线:了解 jpg_stdio_src 失败的原因。 我的猜测:它需要使用 jpeg_create_decompress 宏。

"select isn't broken".

If fopen returned a valid file pointer, and jpeg_read_header can't use it, someone between those two statements has done something bad to it.

The only one in between is the jpg_stdio_src call, which wouldn't fail if all it's preconditions are fulfilled.

Bottom line: see why jpg_stdio_src fails. My guess: it needs to be constructed using the jpeg_create_decompress macro.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文