Changeset 472c09d in mainline for uspace/lib/libc/generic/async.c
- Timestamp:
- 2010-02-03T15:18:40Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b4cbef1
- Parents:
- 28be7fa
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libc/generic/async.c
r28be7fa r472c09d 1345 1345 } 1346 1346 1347 /** Wrapper for receiving b lobsvia the async_data_write_*1347 /** Wrapper for receiving binary data via the async_data_write_* 1348 1348 * 1349 1349 * This wrapper only makes it more comfortable to use async_data_write_* 1350 1350 * functions to receive blobs. 1351 1351 * 1352 * @param blob Pointer to data pointer (which should be later disposed 1353 * by free()). If the operation fails, the pointer is not 1354 * touched. 1355 * @param max_size Maximum size (in bytes) of the blob to receive. 0 means 1356 * no limit. 1357 * @param received If not NULL, the size of the received data is stored here. 1352 * @param data Pointer to data pointer (which should be later disposed 1353 * by free()). If the operation fails, the pointer is not 1354 * touched. 1355 * @param max_size Maximum size (in bytes) of the data to receive. 0 means 1356 * no limit. 1357 * @param granulariy If non-zero, then the size of the received data has to 1358 * be divisible by this value. 1359 * @param received If not NULL, the size of the received data is stored here. 1358 1360 * 1359 1361 * @return Zero on success or a value from @ref errno.h on failure. 1360 1362 * 1361 1363 */ 1362 int async_data_blob_receive(char **blob, const size_t max_size, size_t *received) 1364 int async_data_receive(void **data, const size_t max_size, 1365 const size_t granularity, size_t *received) 1363 1366 { 1364 1367 ipc_callid_t callid; … … 1374 1377 } 1375 1378 1376 char *data = (char *) malloc(size); 1377 if (data == NULL) { 1379 if ((granularity > 0) && ((size % granularity) != 0)) { 1380 ipc_answer_0(callid, EINVAL); 1381 return EINVAL; 1382 } 1383 1384 void *_data = malloc(size); 1385 if (_data == NULL) { 1378 1386 ipc_answer_0(callid, ENOMEM); 1379 1387 return ENOMEM; 1380 1388 } 1381 1389 1382 int rc = async_data_write_finalize(callid, data, size);1390 int rc = async_data_write_finalize(callid, _data, size); 1383 1391 if (rc != EOK) { 1384 free( data);1392 free(_data); 1385 1393 return rc; 1386 1394 } 1387 1395 1388 * blob =data;1396 *data = _data; 1389 1397 if (received != NULL) 1390 1398 *received = size; … … 1403 1411 * @param max_size Maximum size (in bytes) of the string to receive. 0 means 1404 1412 * no limit. 1413 * @param received If not NULL, the size of the received data is stored here. 1405 1414 * 1406 1415 * @return Zero on success or a value from @ref errno.h on failure. 1407 1416 * 1408 1417 */ 1409 int async_ data_string_receive(char **str, const size_t max_size)1418 int async_string_receive(char **str, const size_t max_size, size_t *received) 1410 1419 { 1411 1420 ipc_callid_t callid; … … 1435 1444 data[size] = 0; 1436 1445 *str = data; 1446 if (received != NULL) 1447 *received = size; 1448 1437 1449 return EOK; 1438 1450 }
Note:
See TracChangeset
for help on using the changeset viewer.