This commit is contained in:
Emil 2023-10-07 18:14:49 +00:00
parent 0d7605a43f
commit 981a1931d4
No known key found for this signature in database
GPG Key ID: 5432DB986FDBCF8A

57
baked.c
View File

@ -57,48 +57,51 @@ find_region(const char * fn)
fd = open(fn, O_RDONLY);
if ( fd != -1
&& !fstat(fd,&s)
&& s.st_mode & S_IFREG
&& s.st_size)
if (fd != -1)
{
char * start, * stop, * addr;
addr = mmap(NULL, s.st_size, PROT_READ, MAP_SHARED, fd, 0);
if (addr != MAP_FAILED)
if (!fstat(fd,&s)
&& s.st_mode & S_IFREG
&& s.st_size)
{
for (start = addr; *start; ++start)
char * start, * stop, * addr;
addr = mmap(NULL, s.st_size, PROT_READ, MAP_SHARED, fd, 0);
if (addr != MAP_FAILED)
{
if (s.st_size - (start - addr) > SLEN)
for (start = addr; *start; ++start)
{
if (!strncmp(start,START,SLEN))
if (s.st_size - (start - addr) > SLEN)
{
start += strlen(START);
for (stop = start; *stop; ++stop)
if (!strncmp(start,START,SLEN))
{
if (s.st_size - (stop - addr) > SLEN)
start += strlen(START);
for (stop = start; *stop; ++stop)
{
if (!strncmp(stop,STOP,SLEN))
if (s.st_size - (stop - addr) > SLEN)
{
size_t len = (stop - addr) - (start - addr);
buf = malloc(len + 1);
assert(buf);
if (!buf)
{ goto stop; }
strncpy(buf, start, len);
buf[len] = '\0';
goto stop;
if (!strncmp(stop,STOP,SLEN))
{
size_t len = (stop - addr) - (start - addr);
buf = malloc(len + 1);
assert(buf);
if (!buf)
{ goto stop; }
strncpy(buf, start, len);
buf[len] = '\0';
goto stop;
}
}
else goto stop;
}
else goto stop;
goto stop;
}
goto stop;
}
else goto stop;
}
else goto stop;
stop:
munmap(addr, s.st_size);
}
stop:
munmap(addr, s.st_size);
}
close(fd);
}
return buf;
}