Quantcast
Channel: How do you get file size by fd? - Stack Overflow
Browsing all 4 articles
Browse latest View live

Answer by Be Kind To New Users for How do you get file size by fd?

I like to write my code samples as functions so they are ready to cut and paste into the code:int fileSize(int fd) { struct stat s; if (fstat(fd, &s) == -1) { int saveErrno = errno; fprintf(stderr,...

View Article



Answer by Hasturkun for How do you get file size by fd?

You can use lseek with SEEK_END as the origin, as it returns the new offset in the file, eg.off_t fsize;fsize = lseek(fd, 0, SEEK_END);

View Article

Answer by Seth Robertson for How do you get file size by fd?

fstat will work. But I'm not exactly sure how you plan the get the file size via fseek unless you also use ftell (eg. fseek to the end, then ftell where you are). fstat is better, even for FILE, since...

View Article

How do you get file size by fd?

I know I can get file size of FILE * by fseek, but what I have is just a INT fd.How can I get file size in this case?

View Article
Browsing all 4 articles
Browse latest View live


Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>