2025-02-21 14:10:26 +00:00
|
|
|
#include "tcc/io.h"
|
2025-02-14 16:47:45 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <tcc/state.h>
|
|
|
|
#include <tcc/memory.h>
|
2025-02-11 12:07:04 +00:00
|
|
|
#include <tcc/object.h>
|
|
|
|
#include <tcc/object/archive.h>
|
|
|
|
#include <tcc/object/coff.h>
|
|
|
|
|
|
|
|
int
|
2025-02-21 14:10:26 +00:00
|
|
|
tcc_object_type(int fd, COFFFileHeader *h)
|
2025-02-11 12:07:04 +00:00
|
|
|
{
|
2025-02-21 14:10:26 +00:00
|
|
|
ssize_t size;
|
2025-02-11 12:07:04 +00:00
|
|
|
|
2025-02-21 14:10:26 +00:00
|
|
|
size = full_read(fd, h, sizeof(COFFFileHeader));
|
|
|
|
if (size == sizeof(COFFFileHeader)
|
|
|
|
&& h->magic == COFF_MAGIC
|
|
|
|
&& (h->flags & COFF_F_EXEC) == 0)
|
|
|
|
{
|
|
|
|
return (TCC_BINTYPE_COFF);
|
|
|
|
}
|
|
|
|
else if (size >= 8
|
|
|
|
&& memcmp(h, ARCHIVE_MAGIC, ARCHIVE_MAGSZ) == 0)
|
|
|
|
{
|
|
|
|
return (TCC_BINTYPE_ARCHIVE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (TCC_BINTYPE_NONE);
|
2025-02-14 16:47:45 +00:00
|
|
|
}
|