| 1 | // RUN: %clangxx -O0 %s -o %t && %run %t | FileCheck %s |
| 2 | // REQUIRES: sunrpc, !android |
| 3 | #include <cassert> |
| 4 | #include <rpc/xdr.h> |
| 5 | |
| 6 | int print_msg(char *handle, char *buf, int len) { |
| 7 | if (len > 0) { |
| 8 | for (size_t i = 0; i < len; i++) { |
| 9 | printf("%02x " , (uint8_t)buf[i]); |
| 10 | } |
| 11 | printf("\n" ); |
| 12 | } |
| 13 | return len; |
| 14 | } |
| 15 | |
| 16 | int main() { |
| 17 | XDR xdrs; |
| 18 | xdrs.x_op = XDR_ENCODE; |
| 19 | |
| 20 | xdrrec_create(&xdrs, 0, 0, nullptr, nullptr, print_msg); |
| 21 | unsigned foo = 42; |
| 22 | assert(xdr_u_int(&xdrs, &foo)); |
| 23 | assert(xdrrec_endofrecord(&xdrs, /*sendnow*/ true)); |
| 24 | xdr_destroy(&xdrs); |
| 25 | } |
| 26 | |
| 27 | // CHECK: 00 00 00 2a |
| 28 | |