File: getdlgitemtext_alloc.c

package info (click to toggle)
putty 0.83-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,216 kB
  • sloc: ansic: 148,476; python: 8,466; perl: 1,830; makefile: 128; sh: 117
file content (35 lines) | stat: -rw-r--r-- 745 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
 * Handy wrappers around GetDlgItemText (A and W) which don't make you
 * invent an arbitrary length limit on the output string. Returned
 * string is dynamically allocated; caller must free.
 */

#include <wchar.h>

#include "putty.h"

char *GetDlgItemText_alloc(HWND hwnd, int id)
{
    char *ret = NULL;
    size_t size = 0;

    do {
        sgrowarray_nm(ret, size, size);
        GetDlgItemText(hwnd, id, ret, size);
    } while (!memchr(ret, '\0', size-1));

    return ret;
}

wchar_t *GetDlgItemTextW_alloc(HWND hwnd, int id)
{
    wchar_t *ret = NULL;
    size_t size = 0;

    do {
        sgrowarray_nm(ret, size, size);
        GetDlgItemTextW(hwnd, id, ret, size);
    } while (!wmemchr(ret, L'\0', size-1));

    return ret;
}