Parcourir la source

Add wcswidth and test

Jeremy Soller il y a 2 ans
Parent
commit
393489b38b
100 fichiers modifiés avec 12 ajouts et 10 suppressions
  1. 11 3
      src/header/wchar/mod.rs
  2. 1 0
      tests/Makefile
  3. 0 1
      tests/expected/bins_dynamic/args.stdout
  4. 0 0
      tests/expected/bins_dynamic/errno.stderr
  5. 0 6
      tests/expected/bins_dynamic/errno.stdout
  6. 0 0
      tests/expected/bins_static/alloca.stderr
  7. 0 0
      tests/expected/bins_static/alloca.stdout
  8. 0 0
      tests/expected/bins_static/arpainet.stderr
  9. 0 0
      tests/expected/bins_static/arpainet.stdout
  10. 0 0
      tests/expected/bins_static/assert.stderr
  11. 0 0
      tests/expected/bins_static/assert.stdout
  12. 0 0
      tests/expected/bins_static/constructor.stderr
  13. 0 0
      tests/expected/bins_static/constructor.stdout
  14. 0 0
      tests/expected/bins_static/ctype.stderr
  15. 0 0
      tests/expected/bins_static/ctype.stdout
  16. 0 0
      tests/expected/bins_static/destructor.stderr
  17. 0 0
      tests/expected/bins_static/destructor.stdout
  18. 0 0
      tests/expected/bins_static/dirent/scandir.stderr
  19. 0 0
      tests/expected/bins_static/dirent/scandir.stdout
  20. 0 0
      tests/expected/bins_static/error.stderr
  21. 0 0
      tests/expected/bins_static/error.stdout
  22. 0 0
      tests/expected/bins_static/fcntl/create.stderr
  23. 0 0
      tests/expected/bins_static/fcntl/create.stdout
  24. 0 0
      tests/expected/bins_static/fcntl/fcntl.stderr
  25. 0 0
      tests/expected/bins_static/fcntl/fcntl.stdout
  26. 0 0
      tests/expected/bins_static/fnmatch.stderr
  27. 0 0
      tests/expected/bins_static/fnmatch.stdout
  28. 0 0
      tests/expected/bins_static/futimens.stderr
  29. 0 0
      tests/expected/bins_static/futimens.stdout
  30. 0 0
      tests/expected/bins_static/libgen.stderr
  31. 0 0
      tests/expected/bins_static/libgen.stdout
  32. 0 0
      tests/expected/bins_static/locale.stderr
  33. 0 0
      tests/expected/bins_static/locale.stdout
  34. 0 0
      tests/expected/bins_static/math.stderr
  35. 0 0
      tests/expected/bins_static/math.stdout
  36. 0 0
      tests/expected/bins_static/netdb/getaddrinfo.stderr
  37. 0 0
      tests/expected/bins_static/netdb/getaddrinfo.stdout
  38. 0 0
      tests/expected/bins_static/ptrace.stderr
  39. 0 0
      tests/expected/bins_static/ptrace.stdout
  40. 0 0
      tests/expected/bins_static/regex.stderr
  41. 0 0
      tests/expected/bins_static/regex.stdout
  42. 0 0
      tests/expected/bins_static/select.stderr
  43. 0 0
      tests/expected/bins_static/select.stdout
  44. 0 0
      tests/expected/bins_static/setjmp.stderr
  45. 0 0
      tests/expected/bins_static/setjmp.stdout
  46. 0 0
      tests/expected/bins_static/sigaction.stderr
  47. 0 0
      tests/expected/bins_static/sigaction.stdout
  48. 0 0
      tests/expected/bins_static/signal.stderr
  49. 0 0
      tests/expected/bins_static/signal.stdout
  50. 0 0
      tests/expected/bins_static/stdio/all.stderr
  51. 0 0
      tests/expected/bins_static/stdio/all.stdout
  52. 0 0
      tests/expected/bins_static/stdio/buffer.stderr
  53. 0 0
      tests/expected/bins_static/stdio/buffer.stdout
  54. 0 0
      tests/expected/bins_static/stdio/fgets.stderr
  55. 0 0
      tests/expected/bins_static/stdio/fgets.stdout
  56. 0 0
      tests/expected/bins_static/stdio/fputs.stderr
  57. 0 0
      tests/expected/bins_static/stdio/fputs.stdout
  58. 0 0
      tests/expected/bins_static/stdio/fread.stderr
  59. 0 0
      tests/expected/bins_static/stdio/fread.stdout
  60. 0 0
      tests/expected/bins_static/stdio/freopen.stderr
  61. 0 0
      tests/expected/bins_static/stdio/freopen.stdout
  62. 0 0
      tests/expected/bins_static/stdio/fscanf.stderr
  63. 0 0
      tests/expected/bins_static/stdio/fscanf.stdout
  64. 0 0
      tests/expected/bins_static/stdio/fscanf_offby1.stderr
  65. 0 0
      tests/expected/bins_static/stdio/fscanf_offby1.stdout
  66. 0 0
      tests/expected/bins_static/stdio/fseek.stderr
  67. 0 0
      tests/expected/bins_static/stdio/fseek.stdout
  68. 0 0
      tests/expected/bins_static/stdio/fwrite.stderr
  69. 0 0
      tests/expected/bins_static/stdio/fwrite.stdout
  70. 0 0
      tests/expected/bins_static/stdio/getc_unget.stderr
  71. 0 0
      tests/expected/bins_static/stdio/getc_unget.stdout
  72. 0 0
      tests/expected/bins_static/stdio/mutex.stderr
  73. 0 0
      tests/expected/bins_static/stdio/mutex.stdout
  74. 0 0
      tests/expected/bins_static/stdio/popen.stderr
  75. 0 0
      tests/expected/bins_static/stdio/popen.stdout
  76. 0 0
      tests/expected/bins_static/stdio/printf.stderr
  77. 0 0
      tests/expected/bins_static/stdio/printf.stdout
  78. 0 0
      tests/expected/bins_static/stdio/printf_neg_pad.stderr
  79. 0 0
      tests/expected/bins_static/stdio/printf_neg_pad.stdout
  80. 0 0
      tests/expected/bins_static/stdio/printf_space_pad.stderr
  81. 0 0
      tests/expected/bins_static/stdio/printf_space_pad.stdout
  82. 0 0
      tests/expected/bins_static/stdio/rename.stderr
  83. 0 0
      tests/expected/bins_static/stdio/rename.stdout
  84. 0 0
      tests/expected/bins_static/stdio/scanf.stderr
  85. 0 0
      tests/expected/bins_static/stdio/scanf.stdout
  86. 0 0
      tests/expected/bins_static/stdio/setvbuf.stderr
  87. 0 0
      tests/expected/bins_static/stdio/setvbuf.stdout
  88. 0 0
      tests/expected/bins_static/stdio/sprintf.stderr
  89. 0 0
      tests/expected/bins_static/stdio/sprintf.stdout
  90. 0 0
      tests/expected/bins_static/stdio/ungetc_ftell.stderr
  91. 0 0
      tests/expected/bins_static/stdio/ungetc_ftell.stdout
  92. 0 0
      tests/expected/bins_static/stdio/ungetc_multiple.stderr
  93. 0 0
      tests/expected/bins_static/stdio/ungetc_multiple.stdout
  94. 0 0
      tests/expected/bins_static/stdlib/a64l.stderr
  95. 0 0
      tests/expected/bins_static/stdlib/a64l.stdout
  96. 0 0
      tests/expected/bins_static/stdlib/alloc.stderr
  97. 0 0
      tests/expected/bins_static/stdlib/alloc.stdout
  98. 0 0
      tests/expected/bins_static/stdlib/atof.stderr
  99. 0 0
      tests/expected/bins_static/stdlib/atof.stdout
  100. 0 0
      tests/expected/bins_static/stdlib/atoi.stderr

+ 11 - 3
src/header/wchar/mod.rs

@@ -637,9 +637,17 @@ pub extern "C" fn wcswcs(ws1: *const wchar_t, ws2: *const wchar_t) -> *mut wchar
     unimplemented!();
 }
 
-// #[no_mangle]
-pub extern "C" fn wcswidth(pwcs: *const wchar_t, n: size_t) -> c_int {
-    unimplemented!();
+#[no_mangle]
+pub unsafe extern "C" fn wcswidth(pwcs: *const wchar_t, n: size_t) -> c_int {
+    let mut total_width = 0;
+    for i in 0..n {
+        let wc_width = wcwidth(*pwcs.add(i));
+        if wc_width < 0 {
+            return -1;
+        }
+        total_width += wc_width;
+    }
+    total_width
 }
 
 // #[no_mangle]

+ 1 - 0
tests/Makefile

@@ -115,6 +115,7 @@ EXPECT_NAMES=\
 	wchar/wcstol \
 	wchar/wcscasecmp \
 	wchar/wcsncasecmp \
+	wchar/wcswidth \
 	wctype/towlower \
 	wctype/towupper
 	# TODO: Fix these

+ 0 - 1
tests/expected/bins_dynamic/args.stdout

@@ -1 +0,0 @@
-bins_dynamic/args test args 

+ 0 - 0
tests/expected/bins_dynamic/errno.stderr


+ 0 - 6
tests/expected/bins_dynamic/errno.stdout

@@ -1,6 +0,0 @@
-bins_dynamic/errno
-bins_dynamic/errno
-errno
-yes, you can change this
-yes, you can change this
-yes, you can change this

+ 0 - 0
tests/expected/alloca.stderr → tests/expected/bins_static/alloca.stderr


+ 0 - 0
tests/expected/alloca.stdout → tests/expected/bins_static/alloca.stdout


+ 0 - 0
tests/expected/arpainet.stderr → tests/expected/bins_static/arpainet.stderr


+ 0 - 0
tests/expected/arpainet.stdout → tests/expected/bins_static/arpainet.stdout


+ 0 - 0
tests/expected/assert.stderr → tests/expected/bins_static/assert.stderr


+ 0 - 0
tests/expected/assert.stdout → tests/expected/bins_static/assert.stdout


+ 0 - 0
tests/expected/constructor.stderr → tests/expected/bins_static/constructor.stderr


+ 0 - 0
tests/expected/constructor.stdout → tests/expected/bins_static/constructor.stdout


+ 0 - 0
tests/expected/ctype.stderr → tests/expected/bins_static/ctype.stderr


+ 0 - 0
tests/expected/ctype.stdout → tests/expected/bins_static/ctype.stdout


+ 0 - 0
tests/expected/destructor.stderr → tests/expected/bins_static/destructor.stderr


+ 0 - 0
tests/expected/destructor.stdout → tests/expected/bins_static/destructor.stdout


+ 0 - 0
tests/expected/dirent/scandir.stderr → tests/expected/bins_static/dirent/scandir.stderr


+ 0 - 0
tests/expected/dirent/scandir.stdout → tests/expected/bins_static/dirent/scandir.stdout


+ 0 - 0
tests/expected/error.stderr → tests/expected/bins_static/error.stderr


+ 0 - 0
tests/expected/error.stdout → tests/expected/bins_static/error.stdout


+ 0 - 0
tests/expected/fcntl/create.stderr → tests/expected/bins_static/fcntl/create.stderr


+ 0 - 0
tests/expected/fcntl/create.stdout → tests/expected/bins_static/fcntl/create.stdout


+ 0 - 0
tests/expected/fcntl/fcntl.stderr → tests/expected/bins_static/fcntl/fcntl.stderr


+ 0 - 0
tests/expected/fcntl/fcntl.stdout → tests/expected/bins_static/fcntl/fcntl.stdout


+ 0 - 0
tests/expected/fnmatch.stderr → tests/expected/bins_static/fnmatch.stderr


+ 0 - 0
tests/expected/fnmatch.stdout → tests/expected/bins_static/fnmatch.stdout


+ 0 - 0
tests/expected/futimens.stderr → tests/expected/bins_static/futimens.stderr


+ 0 - 0
tests/expected/futimens.stdout → tests/expected/bins_static/futimens.stdout


+ 0 - 0
tests/expected/libgen.stderr → tests/expected/bins_static/libgen.stderr


+ 0 - 0
tests/expected/libgen.stdout → tests/expected/bins_static/libgen.stdout


+ 0 - 0
tests/expected/locale.stderr → tests/expected/bins_static/locale.stderr


+ 0 - 0
tests/expected/locale.stdout → tests/expected/bins_static/locale.stdout


+ 0 - 0
tests/expected/math.stderr → tests/expected/bins_static/math.stderr


+ 0 - 0
tests/expected/math.stdout → tests/expected/bins_static/math.stdout


+ 0 - 0
tests/expected/netdb/getaddrinfo.stderr → tests/expected/bins_static/netdb/getaddrinfo.stderr


+ 0 - 0
tests/expected/netdb/getaddrinfo.stdout → tests/expected/bins_static/netdb/getaddrinfo.stdout


+ 0 - 0
tests/expected/ptrace.stderr → tests/expected/bins_static/ptrace.stderr


+ 0 - 0
tests/expected/ptrace.stdout → tests/expected/bins_static/ptrace.stdout


+ 0 - 0
tests/expected/regex.stderr → tests/expected/bins_static/regex.stderr


+ 0 - 0
tests/expected/regex.stdout → tests/expected/bins_static/regex.stdout


+ 0 - 0
tests/expected/select.stderr → tests/expected/bins_static/select.stderr


+ 0 - 0
tests/expected/select.stdout → tests/expected/bins_static/select.stdout


+ 0 - 0
tests/expected/setjmp.stderr → tests/expected/bins_static/setjmp.stderr


+ 0 - 0
tests/expected/setjmp.stdout → tests/expected/bins_static/setjmp.stdout


+ 0 - 0
tests/expected/sigaction.stderr → tests/expected/bins_static/sigaction.stderr


+ 0 - 0
tests/expected/sigaction.stdout → tests/expected/bins_static/sigaction.stdout


+ 0 - 0
tests/expected/signal.stderr → tests/expected/bins_static/signal.stderr


+ 0 - 0
tests/expected/signal.stdout → tests/expected/bins_static/signal.stdout


+ 0 - 0
tests/expected/stdio/all.stderr → tests/expected/bins_static/stdio/all.stderr


+ 0 - 0
tests/expected/stdio/all.stdout → tests/expected/bins_static/stdio/all.stdout


+ 0 - 0
tests/expected/stdio/buffer.stderr → tests/expected/bins_static/stdio/buffer.stderr


+ 0 - 0
tests/expected/stdio/buffer.stdout → tests/expected/bins_static/stdio/buffer.stdout


+ 0 - 0
tests/expected/stdio/fgets.stderr → tests/expected/bins_static/stdio/fgets.stderr


+ 0 - 0
tests/expected/stdio/fgets.stdout → tests/expected/bins_static/stdio/fgets.stdout


+ 0 - 0
tests/expected/stdio/fputs.stderr → tests/expected/bins_static/stdio/fputs.stderr


+ 0 - 0
tests/expected/stdio/fputs.stdout → tests/expected/bins_static/stdio/fputs.stdout


+ 0 - 0
tests/expected/stdio/fread.stderr → tests/expected/bins_static/stdio/fread.stderr


+ 0 - 0
tests/expected/stdio/fread.stdout → tests/expected/bins_static/stdio/fread.stdout


+ 0 - 0
tests/expected/stdio/freopen.stderr → tests/expected/bins_static/stdio/freopen.stderr


+ 0 - 0
tests/expected/stdio/freopen.stdout → tests/expected/bins_static/stdio/freopen.stdout


+ 0 - 0
tests/expected/stdio/fscanf.stderr → tests/expected/bins_static/stdio/fscanf.stderr


+ 0 - 0
tests/expected/stdio/fscanf.stdout → tests/expected/bins_static/stdio/fscanf.stdout


+ 0 - 0
tests/expected/stdio/fscanf_offby1.stderr → tests/expected/bins_static/stdio/fscanf_offby1.stderr


+ 0 - 0
tests/expected/stdio/fscanf_offby1.stdout → tests/expected/bins_static/stdio/fscanf_offby1.stdout


+ 0 - 0
tests/expected/stdio/fseek.stderr → tests/expected/bins_static/stdio/fseek.stderr


+ 0 - 0
tests/expected/stdio/fseek.stdout → tests/expected/bins_static/stdio/fseek.stdout


+ 0 - 0
tests/expected/stdio/fwrite.stderr → tests/expected/bins_static/stdio/fwrite.stderr


+ 0 - 0
tests/expected/stdio/fwrite.stdout → tests/expected/bins_static/stdio/fwrite.stdout


+ 0 - 0
tests/expected/stdio/getc_unget.stderr → tests/expected/bins_static/stdio/getc_unget.stderr


+ 0 - 0
tests/expected/stdio/getc_unget.stdout → tests/expected/bins_static/stdio/getc_unget.stdout


+ 0 - 0
tests/expected/stdio/mutex.stderr → tests/expected/bins_static/stdio/mutex.stderr


+ 0 - 0
tests/expected/stdio/mutex.stdout → tests/expected/bins_static/stdio/mutex.stdout


+ 0 - 0
tests/expected/stdio/popen.stderr → tests/expected/bins_static/stdio/popen.stderr


+ 0 - 0
tests/expected/stdio/popen.stdout → tests/expected/bins_static/stdio/popen.stdout


+ 0 - 0
tests/expected/stdio/printf.stderr → tests/expected/bins_static/stdio/printf.stderr


+ 0 - 0
tests/expected/stdio/printf.stdout → tests/expected/bins_static/stdio/printf.stdout


+ 0 - 0
tests/expected/stdio/printf_neg_pad.stderr → tests/expected/bins_static/stdio/printf_neg_pad.stderr


+ 0 - 0
tests/expected/stdio/printf_neg_pad.stdout → tests/expected/bins_static/stdio/printf_neg_pad.stdout


+ 0 - 0
tests/expected/stdio/printf_space_pad.stderr → tests/expected/bins_static/stdio/printf_space_pad.stderr


+ 0 - 0
tests/expected/stdio/printf_space_pad.stdout → tests/expected/bins_static/stdio/printf_space_pad.stdout


+ 0 - 0
tests/expected/stdio/rename.stderr → tests/expected/bins_static/stdio/rename.stderr


+ 0 - 0
tests/expected/stdio/rename.stdout → tests/expected/bins_static/stdio/rename.stdout


+ 0 - 0
tests/expected/stdio/scanf.stderr → tests/expected/bins_static/stdio/scanf.stderr


+ 0 - 0
tests/expected/stdio/scanf.stdout → tests/expected/bins_static/stdio/scanf.stdout


+ 0 - 0
tests/expected/stdio/setvbuf.stderr → tests/expected/bins_static/stdio/setvbuf.stderr


+ 0 - 0
tests/expected/stdio/setvbuf.stdout → tests/expected/bins_static/stdio/setvbuf.stdout


+ 0 - 0
tests/expected/stdio/sprintf.stderr → tests/expected/bins_static/stdio/sprintf.stderr


+ 0 - 0
tests/expected/stdio/sprintf.stdout → tests/expected/bins_static/stdio/sprintf.stdout


+ 0 - 0
tests/expected/stdio/ungetc_ftell.stderr → tests/expected/bins_static/stdio/ungetc_ftell.stderr


+ 0 - 0
tests/expected/stdio/ungetc_ftell.stdout → tests/expected/bins_static/stdio/ungetc_ftell.stdout


+ 0 - 0
tests/expected/stdio/ungetc_multiple.stderr → tests/expected/bins_static/stdio/ungetc_multiple.stderr


+ 0 - 0
tests/expected/stdio/ungetc_multiple.stdout → tests/expected/bins_static/stdio/ungetc_multiple.stdout


+ 0 - 0
tests/expected/stdlib/a64l.stderr → tests/expected/bins_static/stdlib/a64l.stderr


+ 0 - 0
tests/expected/stdlib/a64l.stdout → tests/expected/bins_static/stdlib/a64l.stdout


+ 0 - 0
tests/expected/stdlib/alloc.stderr → tests/expected/bins_static/stdlib/alloc.stderr


+ 0 - 0
tests/expected/stdlib/alloc.stdout → tests/expected/bins_static/stdlib/alloc.stdout


+ 0 - 0
tests/expected/stdlib/atof.stderr → tests/expected/bins_static/stdlib/atof.stderr


+ 0 - 0
tests/expected/stdlib/atof.stdout → tests/expected/bins_static/stdlib/atof.stdout


+ 0 - 0
tests/expected/stdlib/atoi.stderr → tests/expected/bins_static/stdlib/atoi.stderr


Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff