Use fstat instead of stat and simplify the code
git-svn-id: svn://svn.cc65.org/cc65/trunk@750 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -89,53 +89,7 @@ static Collection AFiles = STATIC_COLLECTION_INITIALIZER;
|
|||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* Helper functions */
|
/* struct IFile */
|
||||||
/*****************************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static long GetFileSize (FILE* F)
|
|
||||||
/* Calculate the size of the file F, return -1 on error. */
|
|
||||||
{
|
|
||||||
long Size;
|
|
||||||
long CurPos = ftell (F);
|
|
||||||
if (CurPos < 0) {
|
|
||||||
/* Error */
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (fseek (F, 0, SEEK_END) != 0) {
|
|
||||||
/* Error */
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
Size = ftell (F);
|
|
||||||
if (Size < 0) {
|
|
||||||
/* Error */
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (fseek (F, CurPos, SEEK_SET) != 0) {
|
|
||||||
/* Error */
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return Size;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static long GetFileTime (const char* Name)
|
|
||||||
/* Get the time of last modification for the given file. Return -1 on errors. */
|
|
||||||
{
|
|
||||||
struct stat Buf;
|
|
||||||
if (stat (Name, &Buf) != 0) {
|
|
||||||
/* Error */
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return (long) Buf.st_mtime;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************/
|
|
||||||
/* struct IFile */
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
@@ -188,21 +142,14 @@ static AFile* NewAFile (IFile* IF, FILE* F)
|
|||||||
*/
|
*/
|
||||||
if (IF->Usage++ == 0) {
|
if (IF->Usage++ == 0) {
|
||||||
|
|
||||||
long Val;
|
/* Get file size and modification time */
|
||||||
|
struct stat Buf;
|
||||||
/* Get the file size */
|
if (fstat (fileno (F), &Buf) != 0) {
|
||||||
Val = GetFileSize (AF->F);
|
/* Error */
|
||||||
if (Val < 0) {
|
|
||||||
Fatal ("Cannot seek on `%s': %s", IF->Name, strerror (errno));
|
|
||||||
}
|
|
||||||
IF->Size = Val;
|
|
||||||
|
|
||||||
/* Get the file modification time */
|
|
||||||
Val = GetFileTime (IF->Name);
|
|
||||||
if (Val < 0) {
|
|
||||||
Fatal ("Cannot stat `%s': %s", IF->Name, strerror (errno));
|
Fatal ("Cannot stat `%s': %s", IF->Name, strerror (errno));
|
||||||
}
|
}
|
||||||
IF->MTime = Val;
|
IF->Size = (unsigned long) Buf.st_size;
|
||||||
|
IF->MTime = (unsigned long) Buf.st_mtime;
|
||||||
|
|
||||||
/* Set the debug data */
|
/* Set the debug data */
|
||||||
g_fileinfo (IF->Name, IF->Size, IF->MTime);
|
g_fileinfo (IF->Name, IF->Size, IF->MTime);
|
||||||
|
|||||||
Reference in New Issue
Block a user