Skip to content

Commit

Permalink
[libcrystax] Add swab implementation (issue #1252)
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Moskalchuk <dm@crystax.net>
  • Loading branch information
dmsck committed Feb 4, 2016
1 parent 309e50e commit f86dbdb
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions sources/crystax/bin/gen-bsd-sources
Expand Up @@ -993,6 +993,7 @@ g.add "lib/libc/string/strspn.c", warnings: "sign-compare"
g.add "lib/libc/string/strstr.c"
g.add "lib/libc/string/strtok.c"
g.add "lib/libc/string/strxfrm.c", fixup: "collate_fixwarnings"
g.add "lib/libc/string/swab.c"
g.add "lib/libc/string/wcpcpy.c"
g.add "lib/libc/string/wcpncpy.c"
g.add "lib/libc/string/wcscasecmp.c"
Expand Down
8 changes: 8 additions & 0 deletions tests/device/crystax-issue1252-swab/jni/Android.mk
@@ -0,0 +1,8 @@
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE := test
LOCAL_SRC_FILES := main.c
LOCAL_CFLAGS := -Wall -Wextra -Werror
LOCAL_CFLAGS += -UNDEBUG
include $(BUILD_EXECUTABLE)
1 change: 1 addition & 0 deletions tests/device/crystax-issue1252-swab/jni/Application.mk
@@ -0,0 +1 @@
APP_ABI := all
36 changes: 36 additions & 0 deletions tests/device/crystax-issue1252-swab/jni/main.c
@@ -0,0 +1,36 @@
#include <assert.h>
#include <unistd.h>
#include <stdint.h>

int main()
{
uint8_t src[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
uint8_t dst[sizeof(src)/sizeof(src[0])];

swab(NULL, NULL, -1);

memset(dst, 0, sizeof(dst));
swab(src, dst, -1);
assert(dst[0] == 0);

memset(dst, 0, sizeof(dst));
swab(src, dst, 0);
assert(dst[0] == 0);

memset(dst, 0, sizeof(dst));
swab(src, dst, 2);
assert(dst[0] == 0x02);
assert(dst[1] == 0x01);
assert(dst[2] == 0);

memset(dst, 0, sizeof(dst));
swab(src, dst, 5);
assert(dst[0] == 0x02);
assert(dst[1] == 0x01);
assert(dst[2] == 0x04);
assert(dst[3] == 0x03);
assert(dst[4] == 0);
assert(dst[5] == 0);

return 0;
}

0 comments on commit f86dbdb

Please sign in to comment.