libpts: Use chunk_map() instead of non-portable mmap()
This commit is contained in:
parent
7ae878c357
commit
853498155e
|
@ -24,7 +24,6 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/mman.h>
|
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
|
@ -178,40 +177,19 @@ static bool collect_tags(private_swid_inventory_t *this, char *pathname,
|
||||||
if (this->full_tags)
|
if (this->full_tags)
|
||||||
{
|
{
|
||||||
swid_tag_t *tag;
|
swid_tag_t *tag;
|
||||||
chunk_t xml_tag;
|
chunk_t *xml_tag;
|
||||||
struct stat sb;
|
|
||||||
void *addr;
|
|
||||||
int fd;
|
|
||||||
|
|
||||||
fd = open(abs_name, O_RDONLY);
|
xml_tag = chunk_map(abs_name, FALSE);
|
||||||
if (fd == -1)
|
if (!xml_tag)
|
||||||
{
|
{
|
||||||
DBG1(DBG_IMC, " opening '%s' failed: %s", abs_name,
|
DBG1(DBG_IMC, " opening '%s' failed: %s", abs_name,
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fstat(fd, &sb) == -1)
|
tag = swid_tag_create(*xml_tag, unique_seq_id);
|
||||||
{
|
|
||||||
DBG1(DBG_IMC, " getting file size of '%s' failed: %s", abs_name,
|
|
||||||
strerror(errno));
|
|
||||||
close(fd);
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
|
|
||||||
addr = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
|
|
||||||
if (addr == MAP_FAILED)
|
|
||||||
{
|
|
||||||
DBG1(DBG_IMC, " mapping '%s' failed: %s", abs_name,
|
|
||||||
strerror(errno));
|
|
||||||
close(fd);
|
|
||||||
goto end;
|
|
||||||
}
|
|
||||||
xml_tag = chunk_create(addr, sb.st_size);
|
|
||||||
tag = swid_tag_create(xml_tag, unique_seq_id);
|
|
||||||
this->list->insert_last(this->list, tag);
|
this->list->insert_last(this->list, tag);
|
||||||
munmap(addr, sb.st_size);
|
chunk_unmap(xml_tag);
|
||||||
close(fd);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -290,5 +268,3 @@ swid_inventory_t *swid_inventory_create(bool full_tags)
|
||||||
|
|
||||||
return &this->public;
|
return &this->public;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue