【发布时间】:2014-10-08 07:20:27
【问题描述】:
我尝试通过读取源文件来复制文件并将数据写入目标 - 失败。 我尝试使用这样的 C 扩展:
static int copy(lua_State *L)
{
char ch;
FILE *source, *target;
const char * source_file = lua_tostring(L, 1);
const char * target_file = lua_tostring(L, 2);
source = fopen(source_file, "r");
if( source == NULL )
{
lua_pushnumber(L, 1);
}
target = fopen(target_file, "w");
if( target == NULL )
{
fclose(source);
lua_pushnumber(L, 1);
}
while( ( ch = fgetc(source) ) != EOF )
fputc(ch, target);
fclose(source);
fclose(target);
return 1;
}
此代码正在运行 - 我成功复制了文本文件,但是当我尝试复制 .png 图像时 - 我再次失败 - 在所有这些方法中,我得到了损坏的图像。 我只能通过以下方式复制图像:
os.execute("cp file1 file2")
但它非常sloooow...
如何在不使用 os.execute 的情况下复制文件?
【问题讨论】:
-
您使用的是 Windows 还是 Unixoid?
-
是的,我使用的是 Windows XP。我真的很喜欢 unix,但现在我需要编写 Windows 应用程序。
标签: lua