--- libaitrpc/src/blob.c 2012/05/14 08:39:05 1.7 +++ libaitrpc/src/blob.c 2012/05/16 08:10:39 1.7.2.1 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: blob.c,v 1.7 2012/05/14 08:39:05 misho Exp $ +* $Id: blob.c,v 1.7.2.1 2012/05/16 08:10:39 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -47,7 +47,7 @@ SUCH DAMAGE. /* - * rpc_srv_blobCreate() - Create map blob to memory region and return object + * rpc_srv_blobCreate() - Create and map blob to memory region and return object * * @srv = RPC Server instance * @len = BLOB length object @@ -81,13 +81,12 @@ again: LOGERR; return NULL; } - if (lseek(f, len - 1, SEEK_SET) == -1) { + if (ftruncate(f, len) == -1) { LOGERR; close(f); unlink(szFName); return NULL; - } else - write(f, "", 1); + } blob = malloc(sizeof(rpc_blob_t)); if (!blob) { @@ -166,9 +165,7 @@ rpc_srv_blobMap(rpc_srv_t * __restrict srv, rpc_blob_t inline void rpc_srv_blobUnmap(rpc_blob_t * __restrict blob) { - if (!blob || !blob->blob_data) - rpc_SetErr(EINVAL, "Invalid arguments"); - else { + if (blob && blob->blob_data) munmap(blob->blob_data, blob->blob_len); blob->blob_data = NULL; } @@ -189,9 +186,7 @@ rpc_srv_blobFree(rpc_srv_t * __restrict srv, rpc_blob_ if (!blob) { rpc_SetErr(EINVAL, "Invalid argument BLOB"); return -1; - } - - if (blob->blob_data) + } else rpc_srv_blobUnmap(blob); memset(szFName, 0, sizeof szFName); @@ -204,7 +199,7 @@ rpc_srv_blobFree(rpc_srv_t * __restrict srv, rpc_blob_ return 0; } -// ------------------------------------------------------------ +/* ------------------------------------------------------------ */ /* * rpc_srv_sendBLOB() - Send mapped BLOB to client