mirror of
https://git.zap.org.au/git/trader.git
synced 2025-02-02 15:08:13 -05:00
Add the function chbufdup() to duplicate a chtype array
This commit is contained in:
parent
7d9bf097b9
commit
06b66716cf
26
src/intf.c
26
src/intf.c
@ -1235,6 +1235,32 @@ int vprepstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm,
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************/
|
||||
// chbufdup: Duplicate a chtype buffer
|
||||
|
||||
chtype *chbufdup (const chtype *restrict chbuf, int chbufsize)
|
||||
{
|
||||
const chtype *p;
|
||||
int len;
|
||||
chtype *ret;
|
||||
|
||||
|
||||
// Determine chbuf length, including ending NUL
|
||||
for (len = 1, p = chbuf; *p != '\0' && len <= chbufsize; p++, len++)
|
||||
;
|
||||
|
||||
ret = malloc(len * sizeof(chtype));
|
||||
if (ret == NULL) {
|
||||
err_exit_nomem();
|
||||
}
|
||||
|
||||
memcpy(ret, chbuf, len * sizeof(chtype));
|
||||
ret[len - 1] = '\0'; // Terminating NUL, just in case not present
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************/
|
||||
// pr_left: Print strings in chbuf left-aligned
|
||||
|
||||
|
14
src/intf.h
14
src/intf.h
@ -385,6 +385,20 @@ extern int vprepstr (chtype *restrict chbuf, int chbufsize, chtype attr_norm,
|
||||
const char *restrict format, va_list args);
|
||||
|
||||
|
||||
/*
|
||||
Function: chbufdup - Duplicate a chtype buffer
|
||||
Parameters: chbuf - Buffer to duplicate
|
||||
chbufsize - Number of chtype elements in chbuf
|
||||
Returns: chtype * - Pointer to new duplicated buffer
|
||||
|
||||
This function returns a new buffer of type chtype * that contains a
|
||||
copy of the string in chbuf. No errors are returned: if sufficient
|
||||
memory is not available, the program terminates with an "Out of memory"
|
||||
message.
|
||||
*/
|
||||
extern chtype *chbufdup (const chtype *restrict chbuf, int chbufsize);
|
||||
|
||||
|
||||
/*
|
||||
Function: pr_left - Print strings in chbuf left-aligned
|
||||
Parameters: win - Window to use (should be curwin)
|
||||
|
Loading…
Reference in New Issue
Block a user