diff options
author | Torbjörn Svensson | 2020-10-31 19:54:44 +0000 |
---|---|---|
committer | Jonah Graham | 2020-11-01 00:13:42 +0000 |
commit | 6431307e7085a5154561c6b1a85f970d62f3cac2 (patch) | |
tree | 856b03db830a41d8a2dc34f15011ad868e571b7f /native | |
parent | 7f10dce12f33db3c5576b303612b7a1eecffdafa (diff) | |
download | org.eclipse.cdt-6431307e7085a5154561c6b1a85f970d62f3cac2.tar.gz org.eclipse.cdt-6431307e7085a5154561c6b1a85f970d62f3cac2.tar.xz org.eclipse.cdt-6431307e7085a5154561c6b1a85f970d62f3cac2.zip |
Bug 568079: Reformat source code using clang-format
This will enforce formatting when building the native code
Change-Id: I6c047f4c0672609df322b7ba716fc786f0e3aab4
Signed-off-by: Torbjörn Svensson <azoff@svenskalinuxforeningen.se>
Diffstat (limited to 'native')
5 files changed, 432 insertions, 638 deletions
diff --git a/native/org.eclipse.cdt.native.serial/.settings/org.eclipse.cdt.core.prefs b/native/org.eclipse.cdt.native.serial/.settings/org.eclipse.cdt.core.prefs deleted file mode 100644 index 85b6db296e7..00000000000 --- a/native/org.eclipse.cdt.native.serial/.settings/org.eclipse.cdt.core.prefs +++ /dev/null @@ -1,189 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.cdt.core.formatter.alignment_for_arguments_in_method_invocation=16 -org.eclipse.cdt.core.formatter.alignment_for_assignment=16 -org.eclipse.cdt.core.formatter.alignment_for_base_clause_in_type_declaration=80 -org.eclipse.cdt.core.formatter.alignment_for_binary_expression=16 -org.eclipse.cdt.core.formatter.alignment_for_compact_if=16 -org.eclipse.cdt.core.formatter.alignment_for_conditional_expression=34 -org.eclipse.cdt.core.formatter.alignment_for_conditional_expression_chain=18 -org.eclipse.cdt.core.formatter.alignment_for_constructor_initializer_list=0 -org.eclipse.cdt.core.formatter.alignment_for_declarator_list=16 -org.eclipse.cdt.core.formatter.alignment_for_enumerator_list=48 -org.eclipse.cdt.core.formatter.alignment_for_expression_list=0 -org.eclipse.cdt.core.formatter.alignment_for_expressions_in_array_initializer=16 -org.eclipse.cdt.core.formatter.alignment_for_lambda_expression=20 -org.eclipse.cdt.core.formatter.alignment_for_member_access=0 -org.eclipse.cdt.core.formatter.alignment_for_overloaded_left_shift_chain=16 -org.eclipse.cdt.core.formatter.alignment_for_parameters_in_method_declaration=16 -org.eclipse.cdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 -org.eclipse.cdt.core.formatter.brace_position_for_array_initializer=end_of_line -org.eclipse.cdt.core.formatter.brace_position_for_block=end_of_line -org.eclipse.cdt.core.formatter.brace_position_for_block_in_case=end_of_line -org.eclipse.cdt.core.formatter.brace_position_for_linkage_declaration=end_of_line -org.eclipse.cdt.core.formatter.brace_position_for_method_declaration=end_of_line -org.eclipse.cdt.core.formatter.brace_position_for_namespace_declaration=end_of_line -org.eclipse.cdt.core.formatter.brace_position_for_switch=end_of_line -org.eclipse.cdt.core.formatter.brace_position_for_type_declaration=end_of_line -org.eclipse.cdt.core.formatter.comment.line_up_line_comment_in_blocks_on_first_column=false -org.eclipse.cdt.core.formatter.comment.min_distance_between_code_and_line_comment=1 -org.eclipse.cdt.core.formatter.comment.never_indent_line_comments_on_first_column=true -org.eclipse.cdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments=true -org.eclipse.cdt.core.formatter.comment_formatter_off_tag=@formatter\:off -org.eclipse.cdt.core.formatter.comment_formatter_on_tag=@formatter\:on -org.eclipse.cdt.core.formatter.compact_else_if=true -org.eclipse.cdt.core.formatter.continuation_indentation=2 -org.eclipse.cdt.core.formatter.continuation_indentation_for_array_initializer=2 -org.eclipse.cdt.core.formatter.format_block_comment=true -org.eclipse.cdt.core.formatter.format_guardian_clause_on_one_line=false -org.eclipse.cdt.core.formatter.format_header_comment=true -org.eclipse.cdt.core.formatter.format_line_comment=true -org.eclipse.cdt.core.formatter.indent_access_specifier_compare_to_type_header=false -org.eclipse.cdt.core.formatter.indent_access_specifier_extra_spaces=0 -org.eclipse.cdt.core.formatter.indent_body_declarations_compare_to_access_specifier=true -org.eclipse.cdt.core.formatter.indent_body_declarations_compare_to_linkage=false -org.eclipse.cdt.core.formatter.indent_body_declarations_compare_to_namespace_header=false -org.eclipse.cdt.core.formatter.indent_breaks_compare_to_cases=true -org.eclipse.cdt.core.formatter.indent_declaration_compare_to_template_header=false -org.eclipse.cdt.core.formatter.indent_empty_lines=false -org.eclipse.cdt.core.formatter.indent_label_compare_to_statements=true -org.eclipse.cdt.core.formatter.indent_statements_compare_to_block=true -org.eclipse.cdt.core.formatter.indent_statements_compare_to_body=true -org.eclipse.cdt.core.formatter.indent_switchstatements_compare_to_cases=true -org.eclipse.cdt.core.formatter.indent_switchstatements_compare_to_switch=false -org.eclipse.cdt.core.formatter.indentation.size=4 -org.eclipse.cdt.core.formatter.insert_new_line_after_colon_in_constructor_initializer_list=insert -org.eclipse.cdt.core.formatter.insert_new_line_after_label=do not insert -org.eclipse.cdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert -org.eclipse.cdt.core.formatter.insert_new_line_after_template_declaration=do not insert -org.eclipse.cdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert -org.eclipse.cdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert -org.eclipse.cdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert -org.eclipse.cdt.core.formatter.insert_new_line_before_colon_in_constructor_initializer_list=do not insert -org.eclipse.cdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert -org.eclipse.cdt.core.formatter.insert_new_line_before_identifier_in_function_declaration=do not insert -org.eclipse.cdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert -org.eclipse.cdt.core.formatter.insert_new_line_in_empty_block=insert -org.eclipse.cdt.core.formatter.insert_space_after_assignment_operator=insert -org.eclipse.cdt.core.formatter.insert_space_after_binary_operator=insert -org.eclipse.cdt.core.formatter.insert_space_after_closing_angle_bracket_in_template_arguments=insert -org.eclipse.cdt.core.formatter.insert_space_after_closing_angle_bracket_in_template_parameters=insert -org.eclipse.cdt.core.formatter.insert_space_after_closing_brace_in_block=insert -org.eclipse.cdt.core.formatter.insert_space_after_closing_paren_in_cast=insert -org.eclipse.cdt.core.formatter.insert_space_after_colon_in_base_clause=insert -org.eclipse.cdt.core.formatter.insert_space_after_colon_in_case=insert -org.eclipse.cdt.core.formatter.insert_space_after_colon_in_conditional=insert -org.eclipse.cdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert -org.eclipse.cdt.core.formatter.insert_space_after_comma_in_array_initializer=insert -org.eclipse.cdt.core.formatter.insert_space_after_comma_in_base_types=insert -org.eclipse.cdt.core.formatter.insert_space_after_comma_in_declarator_list=insert -org.eclipse.cdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert -org.eclipse.cdt.core.formatter.insert_space_after_comma_in_expression_list=insert -org.eclipse.cdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert -org.eclipse.cdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert -org.eclipse.cdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert -org.eclipse.cdt.core.formatter.insert_space_after_comma_in_structured_binding_name_list=insert -org.eclipse.cdt.core.formatter.insert_space_after_comma_in_template_arguments=insert -org.eclipse.cdt.core.formatter.insert_space_after_comma_in_template_parameters=insert -org.eclipse.cdt.core.formatter.insert_space_after_lambda_return=insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_angle_bracket_in_template_arguments=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_angle_bracket_in_template_parameters=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_bracket=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_exception_specification=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_opening_structured_binding_name_list=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_pointer_in_declarator_list=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_pointer_in_method_declaration=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_postfix_operator=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_prefix_operator=do not insert -org.eclipse.cdt.core.formatter.insert_space_after_question_in_conditional=insert -org.eclipse.cdt.core.formatter.insert_space_after_semicolon_in_for=insert -org.eclipse.cdt.core.formatter.insert_space_after_unary_operator=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_assignment_operator=insert -org.eclipse.cdt.core.formatter.insert_space_before_binary_operator=insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_angle_bracket_in_template_arguments=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_angle_bracket_in_template_parameters=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_bracket=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_exception_specification=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_closing_structured_binding_name_list=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_colon_in_base_clause=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_colon_in_case=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_colon_in_conditional=insert -org.eclipse.cdt.core.formatter.insert_space_before_colon_in_default=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_comma_in_base_types=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_comma_in_declarator_list=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_comma_in_expression_list=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_comma_in_structured_binding_name_list=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_comma_in_template_arguments=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_comma_in_template_parameters=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_lambda_return=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_angle_bracket_in_template_arguments=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_angle_bracket_in_template_parameters=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_block=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_linkage_declaration=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_namespace_declaration=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_switch=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_bracket=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_catch=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_exception_specification=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_for=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_if=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_switch=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_paren_in_while=insert -org.eclipse.cdt.core.formatter.insert_space_before_opening_structured_binding_name_list=insert -org.eclipse.cdt.core.formatter.insert_space_before_pointer_in_declarator_list=insert -org.eclipse.cdt.core.formatter.insert_space_before_pointer_in_method_declaration=insert -org.eclipse.cdt.core.formatter.insert_space_before_postfix_operator=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_prefix_operator=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_question_in_conditional=insert -org.eclipse.cdt.core.formatter.insert_space_before_ref_qualifier_in_structured_binding=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_semicolon=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_semicolon_in_for=do not insert -org.eclipse.cdt.core.formatter.insert_space_before_unary_operator=do not insert -org.eclipse.cdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert -org.eclipse.cdt.core.formatter.insert_space_between_empty_brackets=do not insert -org.eclipse.cdt.core.formatter.insert_space_between_empty_parens_in_exception_specification=do not insert -org.eclipse.cdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert -org.eclipse.cdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert -org.eclipse.cdt.core.formatter.join_wrapped_lines=true -org.eclipse.cdt.core.formatter.keep_else_statement_on_same_line=false -org.eclipse.cdt.core.formatter.keep_empty_array_initializer_on_one_line=false -org.eclipse.cdt.core.formatter.keep_imple_if_on_one_line=false -org.eclipse.cdt.core.formatter.keep_then_statement_on_same_line=false -org.eclipse.cdt.core.formatter.lineSplit=120 -org.eclipse.cdt.core.formatter.number_of_empty_lines_to_preserve=1 -org.eclipse.cdt.core.formatter.put_empty_statement_on_new_line=true -org.eclipse.cdt.core.formatter.tabulation.char=tab -org.eclipse.cdt.core.formatter.tabulation.size=4 -org.eclipse.cdt.core.formatter.use_comment_formatter_tag=true -org.eclipse.cdt.core.formatter.use_tabs_only_for_leading_indentations=false diff --git a/native/org.eclipse.cdt.native.serial/.settings/org.eclipse.cdt.ui.prefs b/native/org.eclipse.cdt.native.serial/.settings/org.eclipse.cdt.ui.prefs deleted file mode 100644 index 4f7bce2bbb8..00000000000 --- a/native/org.eclipse.cdt.native.serial/.settings/org.eclipse.cdt.ui.prefs +++ /dev/null @@ -1,3 +0,0 @@ -eclipse.preferences.version=1 -formatter_profile=_Unmanaged profile 'CDT' -formatter_settings_version=1 diff --git a/native/org.eclipse.cdt.native.serial/native_src/include/org_eclipse_cdt_serial_SerialPort.h b/native/org.eclipse.cdt.native.serial/native_src/include/org_eclipse_cdt_serial_SerialPort.h index 2ada4771739..d5da82fce57 100644 --- a/native/org.eclipse.cdt.native.serial/native_src/include/org_eclipse_cdt_serial_SerialPort.h +++ b/native/org.eclipse.cdt.native.serial/native_src/include/org_eclipse_cdt_serial_SerialPort.h @@ -12,56 +12,50 @@ extern "C" { * Method: open0 * Signature: (Ljava/lang/String;IIII)J */ -JNIEXPORT jlong JNICALL Java_org_eclipse_cdt_serial_SerialPort_open0 - (JNIEnv *, jobject, jstring, jint, jint, jint, jint); +JNIEXPORT jlong JNICALL Java_org_eclipse_cdt_serial_SerialPort_open0(JNIEnv *, jobject, jstring, jint, jint, jint, + jint); /* * Class: org_eclipse_cdt_serial_SerialPort * Method: close0 * Signature: (J)V */ -JNIEXPORT void JNICALL Java_org_eclipse_cdt_serial_SerialPort_close0 - (JNIEnv *, jobject, jlong); +JNIEXPORT void JNICALL Java_org_eclipse_cdt_serial_SerialPort_close0(JNIEnv *, jobject, jlong); /* * Class: org_eclipse_cdt_serial_SerialPort * Method: read1 * Signature: (J[BII)I */ -JNIEXPORT jint JNICALL Java_org_eclipse_cdt_serial_SerialPort_read1 - (JNIEnv *, jobject, jlong, jbyteArray, jint, jint); +JNIEXPORT jint JNICALL Java_org_eclipse_cdt_serial_SerialPort_read1(JNIEnv *, jobject, jlong, jbyteArray, jint, jint); /* * Class: org_eclipse_cdt_serial_SerialPort * Method: available0 * Signature: (J)I */ -JNIEXPORT jint JNICALL Java_org_eclipse_cdt_serial_SerialPort_available0 - (JNIEnv *, jobject, jlong); +JNIEXPORT jint JNICALL Java_org_eclipse_cdt_serial_SerialPort_available0(JNIEnv *, jobject, jlong); /* * Class: org_eclipse_cdt_serial_SerialPort * Method: write0 * Signature: (JI)V */ -JNIEXPORT void JNICALL Java_org_eclipse_cdt_serial_SerialPort_write0 - (JNIEnv *, jobject, jlong, jint); +JNIEXPORT void JNICALL Java_org_eclipse_cdt_serial_SerialPort_write0(JNIEnv *, jobject, jlong, jint); /* * Class: org_eclipse_cdt_serial_SerialPort * Method: write1 * Signature: (J[BII)V */ -JNIEXPORT void JNICALL Java_org_eclipse_cdt_serial_SerialPort_write1 - (JNIEnv *, jobject, jlong, jbyteArray, jint, jint); +JNIEXPORT void JNICALL Java_org_eclipse_cdt_serial_SerialPort_write1(JNIEnv *, jobject, jlong, jbyteArray, jint, jint); /* * Class: org_eclipse_cdt_serial_SerialPort * Method: getPortName * Signature: (I)Ljava/lang/String; */ -JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_serial_SerialPort_getPortName - (JNIEnv *, jclass, jint); +JNIEXPORT jstring JNICALL Java_org_eclipse_cdt_serial_SerialPort_getPortName(JNIEnv *, jclass, jint); #ifdef __cplusplus } diff --git a/native/org.eclipse.cdt.native.serial/native_src/serial.c b/native/org.eclipse.cdt.native.serial/native_src/serial.c index 5cc51a384f3..53951cda19f 100644 --- a/native/org.eclipse.cdt.native.serial/native_src/serial.c +++ b/native/org.eclipse.cdt.native.serial/native_src/serial.c @@ -38,7 +38,7 @@ #include <jni.h> #include <org_eclipse_cdt_serial_SerialPort.h> -#define FUNC(x) Java_org_eclipse_cdt_serial_SerialPort_ ## x +#define FUNC(x) Java_org_eclipse_cdt_serial_SerialPort_##x /** * Use this method to throw an exception when open fails after the OS open @@ -51,515 +51,507 @@ static void closeAndthrowIOException(int fd, JNIEnv *env, const char *msg) { #else static void closeAndthrowIOException(HANDLE handle, JNIEnv *env, const char *msg) { #endif - char buff[256]; + char buff[256]; #ifndef __MINGW32__ - sprintf(buff, "%s: %s", msg, strerror(errno)); - close(fd); + sprintf(buff, "%s: %s", msg, strerror(errno)); + close(fd); #else - sprintf_s(buff, sizeof(buff), "%s (%d)", msg, GetLastError()); - CloseHandle(handle); + sprintf_s(buff, sizeof(buff), "%s (%d)", msg, GetLastError()); + CloseHandle(handle); #endif - jclass cls = (*env)->FindClass(env, "java/io/IOException"); - (*env)->ThrowNew(env, cls, buff); + jclass cls = (*env)->FindClass(env, "java/io/IOException"); + (*env)->ThrowNew(env, cls, buff); } #endif static void throwIOException(JNIEnv *env, const char *msg) { - char buff[256]; + char buff[256]; #ifndef __MINGW32__ - sprintf(buff, "%s: %s", msg, strerror(errno)); + sprintf(buff, "%s: %s", msg, strerror(errno)); #else - sprintf_s(buff, sizeof(buff), "%s (%d)", msg, GetLastError()); + sprintf_s(buff, sizeof(buff), "%s (%d)", msg, GetLastError()); #endif - jclass cls = (*env)->FindClass(env, "java/io/IOException"); - (*env)->ThrowNew(env, cls, buff); + jclass cls = (*env)->FindClass(env, "java/io/IOException"); + (*env)->ThrowNew(env, cls, buff); } JNIEXPORT jlong JNICALL FUNC(open0)(JNIEnv *env, jobject jobj, jstring portName, jint baudRate, jint byteSize, - jint parity, jint stopBits) { + jint parity, jint stopBits) { #ifndef __MINGW32__ - const char *cportName = (*env)->GetStringUTFChars(env, portName, NULL); - int fd = open(cportName, O_RDWR | O_NOCTTY | O_NDELAY); - if (fd < 0) { - char msg[256]; - sprintf(msg, "Error opening %s", cportName); - (*env)->ReleaseStringUTFChars(env, portName, cportName); - throwIOException(env, msg); - return fd; - } - (*env)->ReleaseStringUTFChars(env, portName, cportName); - - // Turn off all flags - fcntl(fd, F_SETFL, 0); - - struct termios options; - tcgetattr(fd, &options); - options.c_cflag |= (CLOCAL | CREAD); + const char *cportName = (*env)->GetStringUTFChars(env, portName, NULL); + int fd = open(cportName, O_RDWR | O_NOCTTY | O_NDELAY); + if (fd < 0) { + char msg[256]; + sprintf(msg, "Error opening %s", cportName); + (*env)->ReleaseStringUTFChars(env, portName, cportName); + throwIOException(env, msg); + return fd; + } + (*env)->ReleaseStringUTFChars(env, portName, cportName); + + // Turn off all flags + fcntl(fd, F_SETFL, 0); + + struct termios options; + tcgetattr(fd, &options); + options.c_cflag |= (CLOCAL | CREAD); #ifndef __APPLE__ - speed_t baud; - switch (baudRate) { - case 110: - baud = B110; - break; - case 300: - baud = B300; - break; - case 600: - baud = B600; - break; - case 1200: - baud = B1200; - break; - case 2400: - baud = B2400; - break; - case 4800: - baud = B4800; - break; - case 9600: - baud = B9600; - break; - case 19200: - baud = B19200; - break; - case 38400: - baud = B38400; - break; - case 57600: - baud = B57600; - break; - case 115200: - baud = B115200; - break; - case 230400: - baud = B230400; - break; - case 460800: - baud = B460800; - break; - case 500000: - baud = B500000; - break; - case 576000: - baud = B576000; - break; - case 921600: - baud = B921600; - break; - case 1000000: - baud = B1000000; - break; - case 1152000: - baud = B1152000; - break; - case 1500000: - baud = B1500000; - break; - case 2000000: - baud = B2000000; - break; - case 2500000: - baud = B2500000; - break; - case 3000000: - baud = B3000000; - break; - case 3500000: - baud = B3500000; - break; - case 4000000: - baud = B4000000; - break; - default: - baud = B0; - break; - } - - if (baud == B0) { - // Use custom linux baud rates if possible: https://bugs.eclipse.org/bugs/show_bug.cgi?id=543122#c8 - struct serial_struct serial_options; - options.c_cflag |= B38400; - - if (ioctl(fd, TIOCGSERIAL, &serial_options) != 0) { - closeAndthrowIOException(fd, env, "Failed to use custom baud rate. Error using TIOCGSERIAL"); - return -1; - } - serial_options.custom_divisor = serial_options.baud_base / baudRate; - if (serial_options.custom_divisor == 0) { - serial_options.custom_divisor = 1; - } - - serial_options.flags &= ~ASYNC_SPD_MASK; - serial_options.flags |= ASYNC_SPD_CUST; - - if (ioctl(fd, TIOCSSERIAL, &serial_options) != 0) { - closeAndthrowIOException(fd, env, "Failed to use custom baud rate. Error using TIOCSSERIAL"); - return -1; - } - } else { - // Set baud rate - cfsetispeed(&options, baud); - cfsetospeed(&options, baud); - } + speed_t baud; + switch (baudRate) { + case 110: + baud = B110; + break; + case 300: + baud = B300; + break; + case 600: + baud = B600; + break; + case 1200: + baud = B1200; + break; + case 2400: + baud = B2400; + break; + case 4800: + baud = B4800; + break; + case 9600: + baud = B9600; + break; + case 19200: + baud = B19200; + break; + case 38400: + baud = B38400; + break; + case 57600: + baud = B57600; + break; + case 115200: + baud = B115200; + break; + case 230400: + baud = B230400; + break; + case 460800: + baud = B460800; + break; + case 500000: + baud = B500000; + break; + case 576000: + baud = B576000; + break; + case 921600: + baud = B921600; + break; + case 1000000: + baud = B1000000; + break; + case 1152000: + baud = B1152000; + break; + case 1500000: + baud = B1500000; + break; + case 2000000: + baud = B2000000; + break; + case 2500000: + baud = B2500000; + break; + case 3000000: + baud = B3000000; + break; + case 3500000: + baud = B3500000; + break; + case 4000000: + baud = B4000000; + break; + default: + baud = B0; + break; + } + + if (baud == B0) { + // Use custom linux baud rates if possible: https://bugs.eclipse.org/bugs/show_bug.cgi?id=543122#c8 + struct serial_struct serial_options; + options.c_cflag |= B38400; + + if (ioctl(fd, TIOCGSERIAL, &serial_options) != 0) { + closeAndthrowIOException(fd, env, "Failed to use custom baud rate. Error using TIOCGSERIAL"); + return -1; + } + serial_options.custom_divisor = serial_options.baud_base / baudRate; + if (serial_options.custom_divisor == 0) { + serial_options.custom_divisor = 1; + } + + serial_options.flags &= ~ASYNC_SPD_MASK; + serial_options.flags |= ASYNC_SPD_CUST; + + if (ioctl(fd, TIOCSSERIAL, &serial_options) != 0) { + closeAndthrowIOException(fd, env, "Failed to use custom baud rate. Error using TIOCSSERIAL"); + return -1; + } + } else { + // Set baud rate + cfsetispeed(&options, baud); + cfsetospeed(&options, baud); + } #else - // On OSX speed_t is simply the baud rate: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/cfsetispeed.3.html - cfsetispeed(&options, baudRate); - cfsetospeed(&options, baudRate); + // On OSX speed_t is simply the baud rate: + // https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/cfsetispeed.3.html + cfsetispeed(&options, baudRate); + cfsetospeed(&options, baudRate); #endif - // set data size - options.c_cflag &= ~CSIZE; - switch (byteSize) { - case 5: - options.c_cflag |= CS5; - break; - case 6: - options.c_cflag |= CS6; - break; - case 7: - options.c_cflag |= CS7; - break; - case 8: - options.c_cflag |= CS8; - break; - - } - - // set parity - switch (parity) { - case 0: // None - options.c_cflag &= ~PARENB; - break; - case 1: // Even - options.c_cflag |= PARENB; - options.c_cflag &= ~PARODD; - break; - case 2: // Odd - options.c_cflag |= (PARENB | PARODD); - break; - } - - switch (stopBits) { - case 0: // 1 - options.c_cflag &= ~CSTOPB; - break; - case 1: // 2 - options.c_cflag |= CSTOPB; - break; - } - - // raw input - options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); - - // ignore parity - options.c_iflag |= IGNPAR; - - // turn off those bits in the input flag that fiddle with CR and NL - options.c_iflag &= ~(ICRNL | INLCR | IGNCR); - - options.c_cc[VMIN] = 0; // min chars to read - options.c_cc[VTIME] = 2; // 10ths second timeout - - tcflush(fd, TCIFLUSH); - tcsetattr(fd, TCSANOW, &options); - - return fd; + // set data size + options.c_cflag &= ~CSIZE; + switch (byteSize) { + case 5: + options.c_cflag |= CS5; + break; + case 6: + options.c_cflag |= CS6; + break; + case 7: + options.c_cflag |= CS7; + break; + case 8: + options.c_cflag |= CS8; + break; + } + + // set parity + switch (parity) { + case 0: // None + options.c_cflag &= ~PARENB; + break; + case 1: // Even + options.c_cflag |= PARENB; + options.c_cflag &= ~PARODD; + break; + case 2: // Odd + options.c_cflag |= (PARENB | PARODD); + break; + } + + switch (stopBits) { + case 0: // 1 + options.c_cflag &= ~CSTOPB; + break; + case 1: // 2 + options.c_cflag |= CSTOPB; + break; + } + + // raw input + options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); + + // ignore parity + options.c_iflag |= IGNPAR; + + // turn off those bits in the input flag that fiddle with CR and NL + options.c_iflag &= ~(ICRNL | INLCR | IGNCR); + + options.c_cc[VMIN] = 0; // min chars to read + options.c_cc[VTIME] = 2; // 10ths second timeout + + tcflush(fd, TCIFLUSH); + tcsetattr(fd, TCSANOW, &options); + + return fd; #else // __MINGW32__ - const wchar_t * cportName = (const wchar_t *)(*env)->GetStringChars(env, portName, NULL); - HANDLE handle = CreateFile(cportName, - GENERIC_READ | GENERIC_WRITE, - 0, - NULL, - OPEN_EXISTING, - FILE_FLAG_OVERLAPPED, - NULL); - (*env)->ReleaseStringChars(env, portName, cportName); - - if (handle == INVALID_HANDLE_VALUE) { - char msg[256]; - const char * name = (*env)->GetStringUTFChars(env, portName, NULL); - sprintf_s(msg, sizeof(msg), "Error opening %s", name); - (*env)->ReleaseStringUTFChars(env, portName, name); - throwIOException(env, msg); - return -1; - } - - DCB dcb = { 0 }; - - if (!GetCommState(handle, &dcb)) { - closeAndthrowIOException(handle, env, "Error getting DCB"); - return -1; - } - - dcb.BaudRate = baudRate; - dcb.ByteSize = (BYTE)byteSize; - - switch (parity) { - case 0: // None - dcb.fParity = FALSE; - dcb.Parity = NOPARITY; - break; - case 1: // Even - dcb.fParity = TRUE; - dcb.Parity = EVENPARITY; - break; - case 2: // Odd - dcb.fParity = TRUE; - dcb.Parity = ODDPARITY; - break; - } - - switch (stopBits) { - case 0: - dcb.StopBits = ONESTOPBIT; - break; - case 1: - dcb.StopBits = TWOSTOPBITS; - break; - } - - if (!SetCommState(handle, &dcb)) { - closeAndthrowIOException(handle, env, "Error setting DCB"); - return -1; - } - - COMMTIMEOUTS timeouts = { 0 }; - timeouts.ReadIntervalTimeout = MAXDWORD; - timeouts.ReadTotalTimeoutMultiplier = MAXDWORD; - timeouts.ReadTotalTimeoutConstant = 200; - if (!SetCommTimeouts(handle, &timeouts)) { - closeAndthrowIOException(handle, env, "Error setting timeouts"); - return -1; - } + const wchar_t *cportName = (const wchar_t *)(*env)->GetStringChars(env, portName, NULL); + HANDLE handle = + CreateFile(cportName, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); + (*env)->ReleaseStringChars(env, portName, cportName); + + if (handle == INVALID_HANDLE_VALUE) { + char msg[256]; + const char *name = (*env)->GetStringUTFChars(env, portName, NULL); + sprintf_s(msg, sizeof(msg), "Error opening %s", name); + (*env)->ReleaseStringUTFChars(env, portName, name); + throwIOException(env, msg); + return -1; + } + + DCB dcb = {0}; + + if (!GetCommState(handle, &dcb)) { + closeAndthrowIOException(handle, env, "Error getting DCB"); + return -1; + } + + dcb.BaudRate = baudRate; + dcb.ByteSize = (BYTE)byteSize; + + switch (parity) { + case 0: // None + dcb.fParity = FALSE; + dcb.Parity = NOPARITY; + break; + case 1: // Even + dcb.fParity = TRUE; + dcb.Parity = EVENPARITY; + break; + case 2: // Odd + dcb.fParity = TRUE; + dcb.Parity = ODDPARITY; + break; + } + + switch (stopBits) { + case 0: + dcb.StopBits = ONESTOPBIT; + break; + case 1: + dcb.StopBits = TWOSTOPBITS; + break; + } + + if (!SetCommState(handle, &dcb)) { + closeAndthrowIOException(handle, env, "Error setting DCB"); + return -1; + } + + COMMTIMEOUTS timeouts = {0}; + timeouts.ReadIntervalTimeout = MAXDWORD; + timeouts.ReadTotalTimeoutMultiplier = MAXDWORD; + timeouts.ReadTotalTimeoutConstant = 200; + if (!SetCommTimeouts(handle, &timeouts)) { + closeAndthrowIOException(handle, env, "Error setting timeouts"); + return -1; + } #ifdef _WIN64 - return (jlong)handle; + return (jlong)handle; #else - return (jlong)(unsigned)handle; + return (jlong)(unsigned)handle; #endif #endif // __MINGW32__ } -JNIEXPORT void JNICALL FUNC(close0) -(JNIEnv *env, jobject jobj, jlong handle) { +JNIEXPORT void JNICALL FUNC(close0)(JNIEnv *env, jobject jobj, jlong handle) { #ifndef __MINGW32__ - close(handle); + close(handle); #else #ifdef _WIN64 - CloseHandle((HANDLE)handle); + CloseHandle((HANDLE)handle); #else - CloseHandle((HANDLE)(unsigned)handle); + CloseHandle((HANDLE)(unsigned)handle); #endif #endif } JNIEXPORT jint JNICALL FUNC(available0)(JNIEnv *env, jobject jobj, jlong jhandle) { #ifndef __MINGW32__ - int result = 0; - if (ioctl(jhandle, FIONREAD, &result) < 0) { - throwIOException(env, "Error calling ioctl"); - return 0; - } - return result; + int result = 0; + if (ioctl(jhandle, FIONREAD, &result) < 0) { + throwIOException(env, "Error calling ioctl"); + return 0; + } + return result; #else - COMSTAT stat; - DWORD errCode; + COMSTAT stat; + DWORD errCode; #ifdef _WIN64 - HANDLE handle = (HANDLE)jhandle; + HANDLE handle = (HANDLE)jhandle; #else - HANDLE handle = (HANDLE)(unsigned)jhandle; + HANDLE handle = (HANDLE)(unsigned)jhandle; #endif - if (ClearCommError(handle, &errCode, &stat) == 0) { - throwIOException(env, "Error calling ClearCommError"); - return -1; - } - return (int)stat.cbInQue; + if (ClearCommError(handle, &errCode, &stat) == 0) { + throwIOException(env, "Error calling ClearCommError"); + return -1; + } + return (int)stat.cbInQue; #endif } JNIEXPORT jint JNICALL FUNC(read1)(JNIEnv *env, jobject jobj, jlong jhandle, jbyteArray bytes, jint offset, jint size) { #ifndef __MINGW32__ - jbyte buff[256]; - int n = size < sizeof(buff) ? size : sizeof(buff); - n = read(jhandle, buff, n); - if (n > 0) { - (*env)->SetByteArrayRegion(env, bytes, offset, n, buff); - } - return n; + jbyte buff[256]; + int n = size < sizeof(buff) ? size : sizeof(buff); + n = read(jhandle, buff, n); + if (n > 0) { + (*env)->SetByteArrayRegion(env, bytes, offset, n, buff); + } + return n; #else - OVERLAPPED olp = { 0 }; + OVERLAPPED olp = {0}; - olp.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); - if (olp.hEvent == NULL) { - throwIOException(env, "Error creating event"); - return -1; - } + olp.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + if (olp.hEvent == NULL) { + throwIOException(env, "Error creating event"); + return -1; + } - char buff[256]; - DWORD nread = sizeof(buff) < size ? sizeof(buff) : size; + char buff[256]; + DWORD nread = sizeof(buff) < size ? sizeof(buff) : size; #ifdef _WIN64 - HANDLE handle = (HANDLE)jhandle; + HANDLE handle = (HANDLE)jhandle; #else - HANDLE handle = (HANDLE)(unsigned)jhandle; + HANDLE handle = (HANDLE)(unsigned)jhandle; #endif - if (!ReadFile(handle, buff, sizeof(buff), &nread, &olp)) { - if (GetLastError() != ERROR_IO_PENDING) { - throwIOException(env, "Error reading from port"); - CloseHandle(olp.hEvent); - return -1; - } else { - switch (WaitForSingleObject(olp.hEvent, INFINITE)) { - case WAIT_OBJECT_0: - if (!GetOverlappedResult(handle, &olp, &nread, FALSE)) { - if (GetLastError() != ERROR_OPERATION_ABORTED) { - throwIOException(env, "Error waiting for read"); - } - CloseHandle(olp.hEvent); - return -1; - } - break; - } - } - } - - if (nread > 0) { - (*env)->SetByteArrayRegion(env, bytes, offset, nread, (jbyte *)buff); - } - CloseHandle(olp.hEvent); - return nread; + if (!ReadFile(handle, buff, sizeof(buff), &nread, &olp)) { + if (GetLastError() != ERROR_IO_PENDING) { + throwIOException(env, "Error reading from port"); + CloseHandle(olp.hEvent); + return -1; + } else { + switch (WaitForSingleObject(olp.hEvent, INFINITE)) { + case WAIT_OBJECT_0: + if (!GetOverlappedResult(handle, &olp, &nread, FALSE)) { + if (GetLastError() != ERROR_OPERATION_ABORTED) { + throwIOException(env, "Error waiting for read"); + } + CloseHandle(olp.hEvent); + return -1; + } + break; + } + } + } + + if (nread > 0) { + (*env)->SetByteArrayRegion(env, bytes, offset, nread, (jbyte *)buff); + } + CloseHandle(olp.hEvent); + return nread; #endif } -JNIEXPORT void JNICALL FUNC(write0) -(JNIEnv *env, jobject jobj, jlong jhandle, jint b) { +JNIEXPORT void JNICALL FUNC(write0)(JNIEnv *env, jobject jobj, jlong jhandle, jint b) { #ifndef __MINGW32__ - char buff = b; - write(jhandle, &buff, 1); + char buff = b; + write(jhandle, &buff, 1); #else - OVERLAPPED olp = { 0 }; + OVERLAPPED olp = {0}; - olp.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); - if (olp.hEvent == NULL) { - throwIOException(env, "Error creating event"); - return; - } + olp.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + if (olp.hEvent == NULL) { + throwIOException(env, "Error creating event"); + return; + } - char buff = (char)b; - DWORD nwritten; + char buff = (char)b; + DWORD nwritten; #ifdef _WIN64 - HANDLE handle = (HANDLE)jhandle; + HANDLE handle = (HANDLE)jhandle; #else - HANDLE handle = (HANDLE)(unsigned)jhandle; + HANDLE handle = (HANDLE)(unsigned)jhandle; #endif - if (!WriteFile(handle, &buff, sizeof(buff), &nwritten, &olp)) { - if (GetLastError() != ERROR_IO_PENDING) { - throwIOException(env, "Error writing to port"); - } - else { - switch (WaitForSingleObject(olp.hEvent, INFINITE)) { - case WAIT_OBJECT_0: - if (!GetOverlappedResult(handle, &olp, &nwritten, FALSE)) { - throwIOException(env, "Error waiting for write"); - } - } - } - } - - CloseHandle(olp.hEvent); + if (!WriteFile(handle, &buff, sizeof(buff), &nwritten, &olp)) { + if (GetLastError() != ERROR_IO_PENDING) { + throwIOException(env, "Error writing to port"); + } else { + switch (WaitForSingleObject(olp.hEvent, INFINITE)) { + case WAIT_OBJECT_0: + if (!GetOverlappedResult(handle, &olp, &nwritten, FALSE)) { + throwIOException(env, "Error waiting for write"); + } + } + } + } + + CloseHandle(olp.hEvent); #endif } -JNIEXPORT void JNICALL FUNC(write1)(JNIEnv *env, jobject jobj, jlong jhandle, jbyteArray bytes, jint offset, jint size) { +JNIEXPORT void JNICALL FUNC(write1)(JNIEnv *env, jobject jobj, jlong jhandle, jbyteArray bytes, jint offset, + jint size) { #ifndef __MINGW32__ - while (size > 0) { - jbyte buff[256]; - int n = size < sizeof(buff) ? size : sizeof(buff); - (*env)->GetByteArrayRegion(env, bytes, offset, n, buff); - n = write(jhandle, buff, n); - if (n < 0) { - return; - } - size -= n; - offset += n; - } + while (size > 0) { + jbyte buff[256]; + int n = size < sizeof(buff) ? size : sizeof(buff); + (*env)->GetByteArrayRegion(env, bytes, offset, n, buff); + n = write(jhandle, buff, n); + if (n < 0) { + return; + } + size -= n; + offset += n; + } #else - OVERLAPPED olp = { 0 }; - - olp.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); - if (olp.hEvent == NULL) { - throwIOException(env, "Error creating event"); - return; - } - - while (size > 0) { - char buff[256]; - DWORD nwritten = sizeof(buff) < size ? sizeof(buff) : size; - (*env)->GetByteArrayRegion(env, bytes, offset, nwritten, (jbyte *)buff); + OVERLAPPED olp = {0}; + + olp.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + if (olp.hEvent == NULL) { + throwIOException(env, "Error creating event"); + return; + } + + while (size > 0) { + char buff[256]; + DWORD nwritten = sizeof(buff) < size ? sizeof(buff) : size; + (*env)->GetByteArrayRegion(env, bytes, offset, nwritten, (jbyte *)buff); #ifdef _WIN64 - HANDLE handle = (HANDLE)jhandle; + HANDLE handle = (HANDLE)jhandle; #else - HANDLE handle = (HANDLE)(unsigned)jhandle; + HANDLE handle = (HANDLE)(unsigned)jhandle; #endif - if (!WriteFile(handle, buff, nwritten, &nwritten, &olp)) { - if (GetLastError() != ERROR_IO_PENDING) { - throwIOException(env, "Error writing to port"); - return; - } else { - switch (WaitForSingleObject(olp.hEvent, INFINITE)) { - case WAIT_OBJECT_0: - if (!GetOverlappedResult(handle, &olp, &nwritten, FALSE)) { - throwIOException(env, "Error waiting for write"); - return; - } - } - } - } - size -= nwritten; - offset += nwritten; - } - - CloseHandle(olp.hEvent); + if (!WriteFile(handle, buff, nwritten, &nwritten, &olp)) { + if (GetLastError() != ERROR_IO_PENDING) { + throwIOException(env, "Error writing to port"); + return; + } else { + switch (WaitForSingleObject(olp.hEvent, INFINITE)) { + case WAIT_OBJECT_0: + if (!GetOverlappedResult(handle, &olp, &nwritten, FALSE)) { + throwIOException(env, "Error waiting for write"); + return; + } + } + } + } + size -= nwritten; + offset += nwritten; + } + + CloseHandle(olp.hEvent); #endif } #ifdef __MINGW32__ -JNIEXPORT jstring FUNC(getPortName)(JNIEnv *env, jclass cls, jint i) -{ - HKEY key; - - if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"HARDWARE\\DEVICEMAP\\SERIALCOMM", 0, KEY_READ, &key) != ERROR_SUCCESS) { - // There are none - return NULL; - } - - wchar_t name[256]; - DWORD len = sizeof(name); - LONG rc = RegEnumValue(key, (DWORD)i, name, &len, NULL, NULL, NULL, NULL); - if (rc != ERROR_SUCCESS) { - if (rc != ERROR_NO_MORE_ITEMS) { - throwIOException(env, "Can not enum value"); - } - RegCloseKey(key); - return NULL; - } - - wchar_t value[256]; - DWORD type; - len = sizeof(value); - if (RegQueryValueEx(key, name, NULL, &type, (BYTE *)value, &len) != ERROR_SUCCESS) { - throwIOException(env, "Can not query value"); - RegCloseKey(key); - return NULL; - } - - jstring result = (*env)->NewString(env, (jchar *)value, (jsize) wcslen(value)); - RegCloseKey(key); - return result; +JNIEXPORT jstring FUNC(getPortName)(JNIEnv *env, jclass cls, jint i) { + HKEY key; + + if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"HARDWARE\\DEVICEMAP\\SERIALCOMM", 0, KEY_READ, &key) != ERROR_SUCCESS) { + // There are none + return NULL; + } + + wchar_t name[256]; + DWORD len = sizeof(name); + LONG rc = RegEnumValue(key, (DWORD)i, name, &len, NULL, NULL, NULL, NULL); + if (rc != ERROR_SUCCESS) { + if (rc != ERROR_NO_MORE_ITEMS) { + throwIOException(env, "Can not enum value"); + } + RegCloseKey(key); + return NULL; + } + + wchar_t value[256]; + DWORD type; + len = sizeof(value); + if (RegQueryValueEx(key, name, NULL, &type, (BYTE *)value, &len) != ERROR_SUCCESS) { + throwIOException(env, "Can not query value"); + RegCloseKey(key); + return NULL; + } + + jstring result = (*env)->NewString(env, (jchar *)value, (jsize)wcslen(value)); + RegCloseKey(key); + return result; } #endif diff --git a/native/org.eclipse.cdt.native.serial/os/win32/x86_64/serial.dll b/native/org.eclipse.cdt.native.serial/os/win32/x86_64/serial.dll Binary files differindex a14bc966cee..5a68572e0c9 100755 --- a/native/org.eclipse.cdt.native.serial/os/win32/x86_64/serial.dll +++ b/native/org.eclipse.cdt.native.serial/os/win32/x86_64/serial.dll |