(root)/
util-linux-2.39/
tests/
helpers/
test_mbsencode.c
       1  /*
       2   * SPDX-License-Identifier: GPL-2.0-or-later
       3   *
       4   * Copyright (C) 2018 Vaclav Dolezal <vdolezal@redhat.com>
       5   *
       6   * This file is part of util-linux.
       7   */
       8  #include <stdio.h>
       9  #include <stdlib.h>
      10  #include <string.h>
      11  #include <locale.h>
      12  
      13  #include "mbsalign.h"
      14  
      15  int main(int argc, char **argv)
      16  {
      17  	int i = 1;
      18  	char *(*encode_fn)(const char *, size_t *) = mbs_safe_encode;
      19  
      20  	setlocale(LC_ALL, "");
      21  
      22  	if (i < argc) {
      23  		if (!strcmp(argv[i], "--safe")) {
      24  			i++;
      25  			encode_fn = mbs_safe_encode;
      26  		} else if (!strcmp(argv[i], "--invalid")) {
      27  			i++;
      28  			encode_fn = mbs_invalid_encode;
      29  		} else if (!strcmp(argv[i], "--")) {
      30  			i++;
      31  		}
      32  	}
      33  
      34  	for (; i < argc; i++) {
      35  		size_t width;
      36  		char *res;
      37  		res = encode_fn(argv[i], &width);
      38  		printf("%zi %s\n", width, res);
      39  		free(res);
      40  	}
      41  
      42  	return 0;
      43  }