mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2025-12-24 19:40:10 +01:00
nir/spirv: improve lseek() error handling
Signed-off-by: Eric Engestrom <eric@engestrom.ch> Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
This commit is contained in:
parent
23519a9de2
commit
65c8cbe89d
1 changed files with 10 additions and 2 deletions
|
|
@ -39,6 +39,8 @@
|
|||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define WORD_SIZE 4
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int fd = open(argv[1], O_RDONLY);
|
||||
|
|
@ -49,9 +51,15 @@ int main(int argc, char **argv)
|
|||
}
|
||||
|
||||
off_t len = lseek(fd, 0, SEEK_END);
|
||||
if (len % WORD_SIZE != 0)
|
||||
{
|
||||
fprintf(stderr, "File length isn't a multiple of the word size\n");
|
||||
fprintf(stderr, "Are you sure this is a valid SPIR-V shader?\n");
|
||||
close(fd);
|
||||
return 1;
|
||||
}
|
||||
|
||||
assert(len % 4 == 0);
|
||||
size_t word_count = len / 4;
|
||||
size_t word_count = len / WORD_SIZE;
|
||||
|
||||
const void *map = mmap(NULL, len, PROT_READ, MAP_PRIVATE, fd, 0);
|
||||
assert(map != NULL);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue