/*
* lmo - Lua Machine Objects - Base functions
*
- * Copyright (C) 2009 Jo-Philipp Wich <xm@subsignal.org>
+ * Copyright (C) 2009-2010 Jo-Philipp Wich <xm@subsignal.org>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
goto cleanup;
}
- if( lseek(in, (off_t)(-sizeof(uint32_t)), SEEK_END) == -1 )
+ if( lseek(in, -sizeof(uint32_t), SEEK_END) == -1 )
{
error("Can not seek to eof", 1);
goto cleanup;
ar->fd = in;
ar->length = idx_offset;
+ fcntl(ar->fd, F_SETFD, fcntl(ar->fd, F_GETFD) | FD_CLOEXEC);
+
for( i = idx_offset;
i < (s.st_size - sizeof(uint32_t));
i += (4 * sizeof(uint32_t))
{
uint32_t look_key = sfh_hash(key, strlen(key));
int copy_len = -1;
+ lmo_entry_t *entry;
+
+ if( !ar )
+ return copy_len;
- lmo_entry_t *entry = ar->index;
+ entry = ar->index;
while( entry != NULL )
{
if( entry->key_id == look_key )
{
- copy_len = (len > entry->length) ? entry->length : len;
+ copy_len = ((len - 1) > entry->length) ? entry->length : (len - 1);
memcpy(dest, &ar->mmap[entry->offset], copy_len);
+ dest[copy_len] = '\0';
break;
}
return copy_len;
}
-