请问有没有与Win32 API "SetEndOfFile"对应的c函数呢?

OverIsOver 2006-10-17 11:14:14
比如这样,可以快速建立一个1G的文件:
if (fp=fopen(FileName,"w")) {
fseek(fp, 1024*1024*1024, SEEK_SET);
/************************************
//这里怎样写入EOF标记呢?Win32 API "SetEndOfFile"可以实现,可我是在GNU C里编译的,用不了该函数
************************************/
fclose(fp);
}

谢谢指点一二了 :-)
...全文
408 2 打赏 收藏 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
westdot 2006-10-17
  • 打赏
  • 举报
回复
定位到1024*1024*1024-1的位置,写个空字符进去。
fseek(fp, (long)(1024*1024*1024-1), SEEK_SET);
fputc('\0',fp);
因为是以"w"方式打开,即使重新运行设定另一个位置也没问题。
飞哥 2006-10-17
  • 打赏
  • 举报
回复
TRUNCATE(2) Linux Programmer's Manual TRUNCATE(2)

NAME
truncate, ftruncate - truncate a file to a specified length

SYNOPSIS
#include <unistd.h>

int truncate(const char *path, off_t length);
int ftruncate(int fd, off_t length);

DESCRIPTION
The truncate and ftruncate functions cause the regular file named by
path or referenced by fd to be truncated to a size of precisely length
bytes.

If the file previously was larger than this size, the extra data is
lost. If the file previously was shorter, it is extended, and the
extended part reads as zero bytes.

The file pointer is not changed.

With ftruncate, the file must be open for writing; with truncate, the
file must be writable.

RETURN VALUE
On success, zero is returned. On error, -1 is returned, and errno is
set appropriately.

ERRORS
For truncate:

EACCES Search permission is denied for a component of the path prefix,
or the named file is not writable by the user.

EFAULT Path points outside the process's allocated address space.

EFBIG The argument length is larger than the maximum file size. (XSI)

EINTR A signal was caught during execution.

EINVAL The argument length is negative or larger than the maximum file
size.

EIO An I/O error occurred updating the inode.

EISDIR The named file is a directory.

ELOOP Too many symbolic links were encountered in translating the
pathname.

ENAMETOOLONG
A component of a pathname exceeded 255 characters, or an entire
path name exceeded 1023 characters.

ENOENT The named file does not exist.

ENOTDIR
A component of the path prefix is not a directory.

EROFS The named file resides on a read-only file system.

ETXTBSY
The file is a pure procedure (shared text) file that is being
executed.

For ftruncate the same errors apply, but instead of things that can be
wrong with path, we now have things that can be wrong with fd:

EBADF The fd is not a valid descriptor.

EBADF or EINVAL
The fd is not open for writing.

EINVAL The fd does not reference a regular file.
内容概要:本文基于Matlab/Simulink平台,对电励磁同步电机在异步牵入、稳态运行及能耗制动三个阶段的全周期动态特性进行建模仿真与系统研究。研究构建了完整的电机数学模型与仿真系统,重点分析了电机从异步启动到同步运行的过渡过程、稳态运行时的电磁与机械性能,以及执行能耗制动时的减速特性与能量耗散机理。通过仿真,揭示了励磁电流、负载转矩与转速在不同工况下的动态响应规律与耦合关系,为电机的控制策略设计与性能优化提供了理论依据和数据支持。; 适合人群:具备电机学、电力电子与电力拖动基础知识的电气工程及相关专业的研究生、科研人员与工程技术人员。; 使用场景及目标:①研究电励磁同步电机的启动特性,解决异步牵入过程不稳定或失败的问题;②分析电机在不同负载下的稳态运行性能,优化运行效率;③设计和验证能耗制动策略,精确控制制动过程的减速时间和能量消耗。; 阅读建议:在学习过程中,应结合电机的基本原理,深入理解仿真模型中各模块(如电机本体、励磁控制、负载模型)的搭建逻辑,并通过调整仿真参数(如励磁电压、负载大小)来观察和分析系统动态响应,以加深对电机全周期运行特性的理解。

70,040

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧