ChinaUnix.net
相关文章推荐:

ftruncate和lseek设置空洞的区别

小弟在linux下写的一段代码,运行结果有些不明白: 当使用lseek时,从文件中读的数据是0,但是文件的内容却是6235; 使用fseek时,从文件中读的的数据是正常的6235. 使用这两个函数读的内容为什么不一样?谢谢。

by disheng727 - C/C++ - 2008-09-12 16:36:23 阅读(7616) 回复(8)

相关讨论

有没有可以读取2g以上文件的方法? 谢谢了

by song6295 - C/C++ - 2006-08-30 11:47:27 阅读(2246) 回复(6)

最近在看APUE,lseek不太明白,请大牛讲讲,谢谢

by 看不见的地平线 - C/C++ - 2008-04-01 09:19:26 阅读(1386) 回复(2)

为什么我的lseek老是出错?请高手指点,谢谢! 错误提示:Invalid argument 代码如下: #include #include #define PATHSIZE 1024 #define BUFFSIZE 1024 int main() { int ret; int filedes; ssize_t size; off_t off; char pathname[PATHSIZE]; char buf[BUFFSIZE]; strcpy(pathname, "test.txt"); filedes = open(pathname, O_RDONLY); if(filedes == -1) { printf("open fail!\n"); ...

by wuzhiguo - C/C++ - 2008-07-23 20:31:11 阅读(1703) 回复(5)

offset=0x7fffffff+1; lseek(fd,offset,0); error: Invalid argument. how to fix it?

by hjy7094 - C/C++ - 2003-03-25 17:22:58 阅读(980) 回复(3)

how to set _FILE_OFFSET_BITS=64? need make kernel again?

by hjy7094 - 内核/嵌入技术 - 2003-03-25 08:08:44 阅读(644) 回复(0)

#include #include #include int main(void) { int fd; char buf[20]; int size; off_t location; char * filename = "tt.dat"; if( (fd = open(filename,O_RDWR | O_CREAT | O_TRUNC)) == -1){ perror("open"); return 1; } size = write(fd,"Hello C Programming!\n",20); if(size...

by FinalBSD - C/C++ - 2008-07-27 00:32:21 阅读(3873) 回复(12)

int fd; offset_t offset; fd=open("/dev/dsk/c0t1d0s7",O_RDONLY); offset=0x7fffffff+(offset_t)1; lseek64(fd,offset,0); error messages: lseek error, invalid argument. errno:22 if change /dev/dsk/c0t1d0s7 with a large file name(>;2g), it works. how to fix it?

by SaltOnOurSkin - C/C++ - 2003-03-26 12:54:50 阅读(827) 回复(1)

每个打开文件都有一个与其相关联的“当前文件位移量”。它是一个非负整数,用以度量从文件开始处计算的字节数。通常,读、写操作都从当前文件位移量处开始,并使位移量增加所读或写的字节数。按系统默认,当打开一个文件时,除非指定O_APPEND选择项,否则该位移量被设置为0。 可以调用l s e e k显式地定位一个打开文件。 #include #include off_t lseek(int filedes, off_t offset, int whence) ; ...

by cdblsc - AIX文档中心 - 2007-04-23 13:35:22 阅读(1205) 回复(0)

我写了一个双机传输程序。里面有段代码是这样的 Server: ........ off_t curoff, *datbufp; char datbuf[BUFSIZE * 4 + sizeof(off_t)]; char *iovbufp; ......... iovbufp = &datbuf[sizeof(off_t)]; curoff = lseek(fd, 0L, SEEK_CUR); readn = read(fd, iovbufp, jobsize.ps_end - curoff); *(off_t *)datbuf = curoff; if((writen = send(sockfd, datbuf, rea...

by It'sGifted - C/C++ - 2008-04-06 11:01:14 阅读(1465) 回复(1)

#define _LARGEFILE_SOURCE #define _LARGEFILE64_SOURCE #define _FILE_OFFSET_BITS 64 #include #include #include #include #include int main() { printf("sizeof(off_t) = %d\n", sizeof(off_t)); int fd = 0; #if 0 fd = open("test", O_WRONLY | O_CREAT | O_LARGEFILE, 0600); #else fd = open("/dev/hda1", O_RDONLY, 0600); #endif ...

by lixuewei97 - C/C++ - 2008-12-24 16:27:04 阅读(1298) 回复(1)