Skip to content

Commit

Permalink
introduce C test for vsnprintf
Browse files Browse the repository at this point in the history
  • Loading branch information
Alain-Bearez committed Dec 22, 2017
1 parent 202c76d commit 1ba3433
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,19 @@ void test_varargs_invocation() {
ASSERT(varargs_i(1, 91, 92, 93) == 92);
ASSERT(varargs_i(2, 91, 92, 93) == 93);

}
}

char * invoke_vsnprintf(char *fmt, ...) {
char *x = malloc(100);
va_list args;
va_start(args, fmt);
vsnprintf(x, 100, fmt, args);
va_end(args);
return x;
}

void test_vsnprintf() {

ASSERT(strcmp(invoke_vsnprintf("Hello %s, you have %d messages", "Bob", 99), "Hello Bob, you have 99 messages") == 0);

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.renjin.gcc.runtime;

import org.renjin.gcc.annotations.Struct;
import org.renjin.gcc.annotations.VarArgs;

import java.io.FileNotFoundException;
import java.io.IOException;
Expand Down Expand Up @@ -318,9 +317,8 @@ public static int sprintf(BytePtr string, BytePtr format, Object... arguments) {
return snprintf(string, Integer.MAX_VALUE, format, arguments);
}

public static int vsnprintf(BytePtr string, int limit, BytePtr format, @VarArgs OpaquePtr<?> arguments) {
Object[] args = (Object[]) arguments.getArray();
return snprintf(string, Integer.MAX_VALUE, format, args);
public static int vsnprintf(BytePtr string, int limit, BytePtr format, Object... arguments) {
return snprintf(string, limit, format, arguments);
}

public static int snprintf(BytePtr string, int limit, BytePtr format, Object... arguments) {
Expand Down

0 comments on commit 1ba3433

Please sign in to comment.