Skip to content

Commit

Permalink
libfreerdp-utils: replace ARRAY_SIZE custom macro with ARRAYSIZE() wi…
Browse files Browse the repository at this point in the history
…ndows macro
  • Loading branch information
awakecoding committed Nov 22, 2012
1 parent 2a16183 commit b3d8f79
Show file tree
Hide file tree
Showing 23 changed files with 45 additions and 39 deletions.
6 changes: 3 additions & 3 deletions client/Windows/wfreerdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,11 @@ BOOL wf_post_connect(freerdp* instance)
}

if (settings->WindowTitle != NULL)
_snwprintf(win_title, ARRAY_SIZE(win_title), L"%S", settings->WindowTitle);
_snwprintf(win_title, ARRAYSIZE(win_title), L"%S", settings->WindowTitle);
else if (settings->ServerPort == 3389)
_snwprintf(win_title, ARRAY_SIZE(win_title), L"FreeRDP: %S", settings->ServerHostname);
_snwprintf(win_title, ARRAYSIZE(win_title), L"FreeRDP: %S", settings->ServerHostname);
else
_snwprintf(win_title, ARRAY_SIZE(win_title), L"FreeRDP: %S:%d", settings->ServerHostname, settings->ServerPort);
_snwprintf(win_title, ARRAYSIZE(win_title), L"FreeRDP: %S:%d", settings->ServerHostname, settings->ServerPort);

if (wfi->hwnd == 0)
{
Expand Down
2 changes: 1 addition & 1 deletion client/X11/xf_cliprdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ static void xf_cliprdr_append_target(clipboardContext* cb, Atom target)
{
int i;

if (cb->num_targets >= ARRAY_SIZE(cb->targets))
if (cb->num_targets >= ARRAYSIZE(cb->targets))
return;

for (i = 0; i < cb->num_targets; i++)
Expand Down
2 changes: 1 addition & 1 deletion client/X11/xf_keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void xf_kbd_release_all_keypress(xfInfo* xfi)
int keycode;
RDP_SCANCODE rdp_scancode;

for (keycode = 0; keycode < ARRAY_SIZE(xfi->pressed_keys); keycode++)
for (keycode = 0; keycode < ARRAYSIZE(xfi->pressed_keys); keycode++)
{
if (xfi->pressed_keys[keycode] != NoSymbol)
{
Expand Down
2 changes: 1 addition & 1 deletion client/X11/xf_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ xfWindow* xf_CreateDesktopWindow(xfInfo* xfi, char* name, int width, int height,
input_mask |= EnterWindowMask | LeaveWindowMask;

XChangeProperty(xfi->display, window->handle, xfi->_NET_WM_ICON, XA_CARDINAL, 32,
PropModeReplace, (BYTE*) xf_icon_prop, ARRAY_SIZE(xf_icon_prop));
PropModeReplace, (BYTE*) xf_icon_prop, ARRAYSIZE(xf_icon_prop));

if (xfi->parent_window)
XReparentWindow(xfi->display, window->handle, xfi->parent_window, 0, 0);
Expand Down
10 changes: 5 additions & 5 deletions cunit/test_rail.c
Original file line number Diff line number Diff line change
Expand Up @@ -380,13 +380,13 @@ static BYTE server_app_get_resp_app_id[] =


#define EMULATE_SERVER_SEND_CHANNEL_DATA(inst, byte_array) \
emulate_server_send_channel_data(inst, byte_array, ARRAY_SIZE(byte_array))
emulate_server_send_channel_data(inst, byte_array, ARRAYSIZE(byte_array))

#define STREAM_EQUAL_TO_DUMP(stream, dump) \
(stream_equal_dump((stream)->data, (stream)->size, dump, ARRAY_SIZE(dump)))
(stream_equal_dump((stream)->data, (stream)->size, dump, ARRAYSIZE(dump)))

#define UNICODE_STRING_EQUAL_TO_DUMP(ustring, dump) \
(stream_equal_dump((ustring)->string, (ustring)->length, dump, ARRAY_SIZE(dump)))
(stream_equal_dump((ustring)->string, (ustring)->length, dump, ARRAYSIZE(dump)))

typedef struct
{
Expand Down Expand Up @@ -521,7 +521,7 @@ static void emulate_server_send_channel_data(
static void save_dump(void* data, size_t size)
{
thread_param * p = global_thread_params;
if (p->in_streams_number < ARRAY_SIZE(p->in_streams))
if (p->in_streams_number < ARRAYSIZE(p->in_streams))
{
STREAM* s = &p->in_streams[p->in_streams_number];
s->data = malloc(size);
Expand Down Expand Up @@ -631,7 +631,7 @@ static void process_events_and_channel_data_from_plugin(thread_param* param)
counter);

// add to global event list
if (param->in_events_number < ARRAY_SIZE(param->in_events))
if (param->in_events_number < ARRAYSIZE(param->in_events))
{
save_event(event, &param->in_events[param->in_events_number]);
param->in_events_number++;
Expand Down
2 changes: 1 addition & 1 deletion cunit/test_rfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ void test_rlgr(void)
{
int n;

n = rfx_rlgr_decode(RLGR3, y_data, sizeof(y_data), buffer, ARRAY_SIZE(buffer));
n = rfx_rlgr_decode(RLGR3, y_data, sizeof(y_data), buffer, ARRAYSIZE(buffer));

//printf("RLGR decode %d bytes to %d values.", sizeof(y_data), n);
//dump_buffer(buffer, n);
Expand Down
2 changes: 1 addition & 1 deletion include/freerdp/utils/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@

#include <freerdp/api.h>

#define ARRAY_SIZE(_x) (sizeof(_x)/sizeof(*(_x)))
#include <winpr/crt.h>

#endif /* __MEMORY_UTILS_H */
2 changes: 1 addition & 1 deletion libfreerdp/core/fastpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ static BOOL fastpath_recv_update(rdpFastPath* fastpath, BYTE updateCode, UINT32

#ifdef WITH_DEBUG_RDP
DEBUG_RDP("recv Fast-Path %s Update (0x%X), length:%d",
updateCode < ARRAY_SIZE(FASTPATH_UPDATETYPE_STRINGS) ? FASTPATH_UPDATETYPE_STRINGS[updateCode] : "???", updateCode, size);
updateCode < ARRAYSIZE(FASTPATH_UPDATETYPE_STRINGS) ? FASTPATH_UPDATETYPE_STRINGS[updateCode] : "???", updateCode, size);
#endif

switch (updateCode)
Expand Down
6 changes: 3 additions & 3 deletions libfreerdp/core/orders.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static const char* const SECONDARY_DRAWING_ORDER_STRINGS[] =
"Cache Bitmap V3"
};

#define SECONDARY_DRAWING_ORDER_COUNT (ARRAY_SIZE(SECONDARY_DRAWING_ORDER_STRINGS))
#define SECONDARY_DRAWING_ORDER_COUNT (ARRAYSIZE(SECONDARY_DRAWING_ORDER_STRINGS))

static const char* const ALTSEC_DRAWING_ORDER_STRINGS[] =
{
Expand All @@ -92,7 +92,7 @@ static const char* const ALTSEC_DRAWING_ORDER_STRINGS[] =
"Frame Marker"
};

#define ALTSEC_DRAWING_ORDER_COUNT (ARRAY_SIZE(ALTSEC_DRAWING_ORDER_STRINGS))
#define ALTSEC_DRAWING_ORDER_COUNT (ARRAYSIZE(ALTSEC_DRAWING_ORDER_STRINGS))

#endif /* WITH_DEBUG_ORDERS */

Expand Down Expand Up @@ -125,7 +125,7 @@ static const BYTE PRIMARY_DRAWING_ORDER_FIELD_BYTES[] =
GLYPH_INDEX_ORDER_FIELD_BYTES
};

#define PRIMARY_DRAWING_ORDER_COUNT (ARRAY_SIZE(PRIMARY_DRAWING_ORDER_FIELD_BYTES))
#define PRIMARY_DRAWING_ORDER_COUNT (ARRAYSIZE(PRIMARY_DRAWING_ORDER_FIELD_BYTES))

static const BYTE CBR2_BPP[] =
{
Expand Down
2 changes: 1 addition & 1 deletion libfreerdp/core/rdp.c
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ BOOL rdp_recv_data_pdu(rdpRdp* rdp, STREAM* s)
#ifdef WITH_DEBUG_RDP
/* if (type != DATA_PDU_TYPE_UPDATE) */
DEBUG_RDP("recv %s Data PDU (0x%02X), length:%d",
type < ARRAY_SIZE(DATA_PDU_TYPE_STRINGS) ? DATA_PDU_TYPE_STRINGS[type] : "???", type, length);
type < ARRAYSIZE(DATA_PDU_TYPE_STRINGS) ? DATA_PDU_TYPE_STRINGS[type] : "???", type, length);
#endif

switch (type)
Expand Down
2 changes: 1 addition & 1 deletion libfreerdp/locale/keyboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ UINT32 freerdp_keyboard_init(UINT32 keyboardLayoutId)
keyboardLayoutId = freerdp_detect_keyboard(keyboardLayoutId);

memset(RDP_SCANCODE_TO_X11_KEYCODE, 0, sizeof(RDP_SCANCODE_TO_X11_KEYCODE));
for (keycode=0; keycode < ARRAY_SIZE(RDP_SCANCODE_TO_X11_KEYCODE); keycode++)
for (keycode=0; keycode < ARRAYSIZE(RDP_SCANCODE_TO_X11_KEYCODE); keycode++)
RDP_SCANCODE_TO_X11_KEYCODE
[RDP_SCANCODE_CODE(X11_KEYCODE_TO_RDP_SCANCODE[keycode])]
[RDP_SCANCODE_EXTENDED(X11_KEYCODE_TO_RDP_SCANCODE[keycode]) ? 1 : 0] = keycode;
Expand Down
12 changes: 6 additions & 6 deletions libfreerdp/locale/keyboard_layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ RDP_KEYBOARD_LAYOUT* freerdp_keyboard_get_layouts(UINT32 types)

if ((types & RDP_KEYBOARD_LAYOUT_TYPE_STANDARD) != 0)
{
length = ARRAY_SIZE(RDP_KEYBOARD_LAYOUT_TABLE);
length = ARRAYSIZE(RDP_KEYBOARD_LAYOUT_TABLE);
layouts = (RDP_KEYBOARD_LAYOUT*) realloc(layouts, (num + length + 1) * sizeof(RDP_KEYBOARD_LAYOUT));

for (i = 0; i < length; i++, num++)
Expand All @@ -499,7 +499,7 @@ RDP_KEYBOARD_LAYOUT* freerdp_keyboard_get_layouts(UINT32 types)
}
if ((types & RDP_KEYBOARD_LAYOUT_TYPE_VARIANT) != 0)
{
length = ARRAY_SIZE(RDP_KEYBOARD_LAYOUT_VARIANT_TABLE);
length = ARRAYSIZE(RDP_KEYBOARD_LAYOUT_VARIANT_TABLE);
layouts = (RDP_KEYBOARD_LAYOUT*) realloc(layouts, (num + length + 1) * sizeof(RDP_KEYBOARD_LAYOUT));

for (i = 0; i < length; i++, num++)
Expand All @@ -510,7 +510,7 @@ RDP_KEYBOARD_LAYOUT* freerdp_keyboard_get_layouts(UINT32 types)
}
if ((types & RDP_KEYBOARD_LAYOUT_TYPE_IME) != 0)
{
length = ARRAY_SIZE(RDP_KEYBOARD_IME_TABLE);
length = ARRAYSIZE(RDP_KEYBOARD_IME_TABLE);
layouts = (RDP_KEYBOARD_LAYOUT*) realloc(layouts, (num + length + 1) * sizeof(RDP_KEYBOARD_LAYOUT));

for (i = 0; i < length; i++, num++)
Expand All @@ -529,19 +529,19 @@ const char* freerdp_keyboard_get_layout_name_from_id(UINT32 keyboardLayoutID)
{
int i;

for (i = 0; i < ARRAY_SIZE(RDP_KEYBOARD_LAYOUT_TABLE); i++)
for (i = 0; i < ARRAYSIZE(RDP_KEYBOARD_LAYOUT_TABLE); i++)
{
if (RDP_KEYBOARD_LAYOUT_TABLE[i].code == keyboardLayoutID)
return RDP_KEYBOARD_LAYOUT_TABLE[i].name;
}

for (i = 0; i < ARRAY_SIZE(RDP_KEYBOARD_LAYOUT_VARIANT_TABLE); i++)
for (i = 0; i < ARRAYSIZE(RDP_KEYBOARD_LAYOUT_VARIANT_TABLE); i++)
{
if (RDP_KEYBOARD_LAYOUT_VARIANT_TABLE[i].code == keyboardLayoutID)
return RDP_KEYBOARD_LAYOUT_VARIANT_TABLE[i].name;
}

for (i = 0; i < ARRAY_SIZE(RDP_KEYBOARD_IME_TABLE); i++)
for (i = 0; i < ARRAYSIZE(RDP_KEYBOARD_IME_TABLE); i++)
{
if (RDP_KEYBOARD_IME_TABLE[i].code == keyboardLayoutID)
return RDP_KEYBOARD_IME_TABLE[i].name;
Expand Down
2 changes: 1 addition & 1 deletion libfreerdp/locale/keyboard_sun.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ UINT32 freerdp_detect_keyboard_type_and_layout_solaris(char* keyboard_type, int
}
pclose(kbd);

for (i = 0; i < ARRAY_SIZE(SOLARIS_KEYBOARD_TABLE); i++)
for (i = 0; i < ARRAYSIZE(SOLARIS_KEYBOARD_TABLE); i++)
{
if (SOLARIS_KEYBOARD_TABLE[i].type == type)
{
Expand Down
2 changes: 1 addition & 1 deletion libfreerdp/locale/keyboard_xkbfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ int freerdp_keyboard_load_map_from_xkbfile(void* display, RDP_SCANCODE x11_keyco
if (strlen(xkb_keyname) < 1)
continue;

for (j = 0; j < ARRAY_SIZE(XKB_KEY_NAME_SCANCODE_TABLE); j++)
for (j = 0; j < ARRAYSIZE(XKB_KEY_NAME_SCANCODE_TABLE); j++)
{

if (!strcmp(xkb_keyname, XKB_KEY_NAME_SCANCODE_TABLE[j].xkb_keyname))
Expand Down
6 changes: 3 additions & 3 deletions libfreerdp/locale/locale.c
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ SYSTEM_LOCALE* freerdp_detect_system_locale()

freerdp_get_system_language_and_country_codes(language, country);

for (i = 0; i < ARRAY_SIZE(SYSTEM_LOCALE_TABLE); i++)
for (i = 0; i < ARRAYSIZE(SYSTEM_LOCALE_TABLE); i++)
{
if ((strcmp(language, SYSTEM_LOCALE_TABLE[i].language) == 0) && (strcmp(country, SYSTEM_LOCALE_TABLE[i].country) == 0))
{
Expand Down Expand Up @@ -707,7 +707,7 @@ const char* freerdp_get_system_locale_name_from_id(UINT32 localeId)
{
int index;

for (index = 0; index < ARRAY_SIZE(LOCALE_NAME_TABLE); index++)
for (index = 0; index < ARRAYSIZE(LOCALE_NAME_TABLE); index++)
{
if (localeId == LOCALE_NAME_TABLE[index].localeId)
return LOCALE_NAME_TABLE[index].name;
Expand Down Expand Up @@ -735,7 +735,7 @@ UINT32 freerdp_detect_keyboard_layout_from_system_locale()

DEBUG_KBD("Found locale : %s_%s", locale->language, locale->country);

for (i = 0; i < ARRAY_SIZE(LOCALE_KEYBOARD_LAYOUTS_TABLE); i++)
for (i = 0; i < ARRAYSIZE(LOCALE_KEYBOARD_LAYOUTS_TABLE); i++)
{
if (LOCALE_KEYBOARD_LAYOUTS_TABLE[i].locale == locale->code)
{
Expand Down
4 changes: 2 additions & 2 deletions libfreerdp/locale/timezone.c
Original file line number Diff line number Diff line change
Expand Up @@ -1609,9 +1609,9 @@ TIME_ZONE_ENTRY* freerdp_detect_windows_time_zone(UINT32 bias)
if (tzid == NULL)
return NULL;

for (i = 0; i < ARRAY_SIZE(TimeZoneTable); i++)
for (i = 0; i < ARRAYSIZE(TimeZoneTable); i++)
{
for (j = 0; j < ARRAY_SIZE(WindowsTimeZoneIdTable); j++)
for (j = 0; j < ARRAYSIZE(WindowsTimeZoneIdTable); j++)
{
if (strcmp(TimeZoneTable[i].Id, WindowsTimeZoneIdTable[j].windows) != 0)
continue;
Expand Down
2 changes: 1 addition & 1 deletion libfreerdp/locale/virtual_key_codes.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ const char* freerdp_keyboard_get_virtual_key_code_name(UINT32 vkcode)
UINT32 freerdp_keyboard_get_virtual_key_code_from_name(const char* vkcode_name)
{
int i = 0;
for (i = 0; i < ARRAY_SIZE(VIRTUAL_KEY_CODE_TABLE); i++)
for (i = 0; i < ARRAYSIZE(VIRTUAL_KEY_CODE_TABLE); i++)
{
if (VIRTUAL_KEY_CODE_TABLE[i].name)
{
Expand Down
2 changes: 1 addition & 1 deletion libfreerdp/locale/xkb_layout_ids.c
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ UINT32 find_keyboard_layout_in_xorg_rules(char* layout, char* variant)

DEBUG_KBD("xkbLayout: %s\txkbVariant: %s", layout, variant);

for (i = 0; i < ARRAY_SIZE(xkbLayouts); i++)
for (i = 0; i < ARRAYSIZE(xkbLayouts); i++)
{
if (strcmp(xkbLayouts[i].layout, layout) == 0)
{
Expand Down
4 changes: 2 additions & 2 deletions libfreerdp/rail/window.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void print_window_styles(UINT32 style)
int i;

printf("Window Styles:\n{\n");
for (i = 0; i < ARRAY_SIZE(WINDOW_STYLES); i++)
for (i = 0; i < ARRAYSIZE(WINDOW_STYLES); i++)
{
if (style & WINDOW_STYLES[i].style)
{
Expand All @@ -123,7 +123,7 @@ void print_extended_window_styles(UINT32 style)
int i;

printf("Extended Window Styles:\n{\n");
for (i = 0; i < ARRAY_SIZE(EXTENDED_WINDOW_STYLES); i++)
for (i = 0; i < ARRAYSIZE(EXTENDED_WINDOW_STYLES); i++)
{
if (style & EXTENDED_WINDOW_STYLES[i].style)
{
Expand Down
2 changes: 1 addition & 1 deletion libfreerdp/utils/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ int freerdp_parse_args(rdpSettings* settings, int argc, char** argv,
printf("missing extension name\n");
return FREERDP_ARGS_PARSE_FAILURE;
}
if (num_extensions >= ARRAY_SIZE(settings->extensions))
if (num_extensions >= ARRAYSIZE(settings->extensions))
{
printf("maximum extensions reached\n");
return FREERDP_ARGS_PARSE_FAILURE;
Expand Down
2 changes: 1 addition & 1 deletion libfreerdp/utils/rail.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void* rail_clone_order(UINT32 event_type, void* order)
size_t order_size = 0;
void* new_order = NULL;

for (i = 0; i < ARRAY_SIZE(ordersize_table); i++)
for (i = 0; i < ARRAYSIZE(ordersize_table); i++)
{
if (event_type == ordersize_table[i].type)
{
Expand Down
2 changes: 1 addition & 1 deletion libfreerdp/utils/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ int freerdp_handle_signals(void)
fatal_sigaction.sa_flags = 0;

for (signal_index = 0;
signal_index < ARRAY_SIZE(fatal_signals);
signal_index < ARRAYSIZE(fatal_signals);
signal_index++)
if (sigaction(fatal_signals[signal_index],
NULL, &orig_sigaction) == 0)
Expand Down
6 changes: 6 additions & 0 deletions winpr/include/winpr/crt.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
typedef int errno_t;
#endif

#define RTL_NUMBER_OF_V1(A) (sizeof(A) / sizeof((A)[0]))
#define RTL_NUMBER_OF_V2(A) RTL_NUMBER_OF_V1(A)

#define ARRAYSIZE(A) RTL_NUMBER_OF_V2(A)
#define _ARRAYSIZE(A) RTL_NUMBER_OF_V1(A)

WINPR_API void* _aligned_malloc(size_t size, size_t alignment);
WINPR_API void* _aligned_realloc(void* memblock, size_t size, size_t alignment);
WINPR_API void* _aligned_recalloc(void* memblock, size_t num, size_t size, size_t alignment);
Expand Down

0 comments on commit b3d8f79

Please sign in to comment.