diff --git a/src/ioc/db/dbExtractArray.c b/src/ioc/db/dbExtractArray.c index fde0f6ca0..95eca4bfa 100644 --- a/src/ioc/db/dbExtractArray.c +++ b/src/ioc/db/dbExtractArray.c @@ -24,12 +24,13 @@ #define epicsExportSharedSymbols #include "dbExtractArray.h" -void dbExtractArray(const dbAddr *paddr, - void *pto, long nRequest, long no_elements, long offset, long increment) +void dbExtractArrayFromRec(const dbAddr *paddr, void *pto, + long nRequest, long no_elements, long offset, long increment) { char *pdst = (char *) pto; char *psrc = (char *) paddr->pfield; long nUpperPart; + int i; short srcSize = paddr->field_size; short dstSize = srcSize; char isString = (paddr->field_type == DBF_STRING); @@ -42,6 +43,9 @@ void dbExtractArray(const dbAddr *paddr, memcpy(pdst, &psrc[offset * srcSize], dstSize * nUpperPart); if (nRequest > nUpperPart) memcpy(&pdst[dstSize * nUpperPart], psrc, dstSize * (nRequest - nUpperPart)); + if (isString) + for (i = 1; i <= nRequest; i++) + pdst[dstSize*i] = '\0'; } else { for (; nRequest > 0; nRequest--, pdst += srcSize, offset += increment) { offset %= no_elements; @@ -50,3 +54,31 @@ void dbExtractArray(const dbAddr *paddr, } } } + +void dbExtractArrayFromBuf(const void *pfrom, void *pto, + short field_size, short field_type, + long nRequest, long no_elements, long offset, long increment) +{ + char *pdst = (char *) pto; + char *psrc = (char *) pfrom; + int i; + short srcSize = field_size; + short dstSize = srcSize; + char isString = (field_type == DBF_STRING); + + if (nRequest > no_elements) nRequest = no_elements; + if (offset > no_elements - 1) offset = no_elements - 1; + if (isString && dstSize >= MAX_STRING_SIZE) dstSize = MAX_STRING_SIZE - 1; + + if (increment == 1) { + memcpy(pdst, &psrc[offset * srcSize], dstSize * nRequest); + if (isString) + for (i = 1; i <= nRequest; i++) + pdst[dstSize*i] = '\0'; + } else { + for (; nRequest > 0; nRequest--, pdst += srcSize, offset += increment) { + memcpy(pdst, &psrc[offset*srcSize], dstSize); + if (isString) pdst[dstSize] = '\0'; + } + } +} diff --git a/src/ioc/db/dbExtractArray.h b/src/ioc/db/dbExtractArray.h index 56f484212..7ed35847f 100644 --- a/src/ioc/db/dbExtractArray.h +++ b/src/ioc/db/dbExtractArray.h @@ -14,14 +14,18 @@ #define INC_dbExtractArray_H #include "dbFldTypes.h" +#include "dbAddr.h" #include "shareLib.h" #ifdef __cplusplus extern "C" { #endif -epicsShareExtern void dbExtractArray(const DBADDR *paddr, void *pbuffer, - long nRequest, long no_elements, long offset, long increment); +epicsShareFunc void dbExtractArrayFromRec(const DBADDR *paddr, void *pto, + long nRequest, long no_elements, long offset, long increment); +epicsShareFunc void dbExtractArrayFromBuf(const void *pfrom, void *pto, + short field_size, short field_type, + long nRequest, long no_elements, long offset, long increment); #ifdef __cplusplus }