version 1.25, 2016/09/17 15:06:41 |
version 1.26, 2017/10/29 17:10:55 |
|
|
} |
} |
|
|
/* |
/* |
* Try to determine the size of a file by seeking to the end. |
|
*/ |
|
static off_t |
|
seek_filesize(int f) |
|
{ |
|
off_t spos; |
|
|
|
spos = lseek(f, (off_t)0, SEEK_END); |
|
if (spos == (off_t)-1) |
|
return (-1); |
|
return (spos); |
|
} |
|
|
|
/* |
|
* Read a string from a file. |
* Read a string from a file. |
* Return a pointer to the string in memory. |
* Return a pointer to the string in memory. |
*/ |
*/ |
|
|
|
|
/* |
/* |
* Return the size of a file, as cheaply as possible. |
* Return the size of a file, as cheaply as possible. |
* In Unix, we can stat the file. |
|
*/ |
*/ |
off_t |
off_t |
filesize(int f) |
filesize(int f) |
|
|
|
|
if (fstat(f, &statbuf) >= 0) |
if (fstat(f, &statbuf) >= 0) |
return (statbuf.st_size); |
return (statbuf.st_size); |
return (seek_filesize(f)); |
return (-1); |
} |
} |
|
|
/* |
/* |