pread在不应该返回时返回0?

时间:2012-07-17 19:13:19

标签: c file-transfer chunking

我正在写一个文件传输程序。但是出于某种原因pread正在返回0,尽管不在文件的末尾。任何人都可以看看我的代码,看看问题?它与fread完美配合。

        int file;
        unsigned int size = selfp->intdata;
        file=open(str, O_RDONLY); 
        char buf[1024];

        printf("filename = %s \n", str);//prints file name requested
        printf("buffer = %s \n", buf);//prints nothing currently
        printf("offset = %d \n",atoi(chunkIndex)*CHUNK);//prints 0 for first chunk
        printf("CHUNK = %d \n", CHUNK);//prints 1024
        int myoffset = atoi(chunkIndex)*CHUNK; 
        int dataSize=pread(file, buf, sizeof buf, myoffset);
        printf("%d\n", dataSize);//returns 0

        close(file);

谢谢!

0 个答案:

没有答案