errstr 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. .TH ERRSTR 2
  2. .SH NAME
  3. errstr, rerrstr, werrstr \- description of last system call error
  4. .SH SYNOPSIS
  5. .B #include <u.h>
  6. .br
  7. .B #include <libc.h>
  8. .PP
  9. .B
  10. int errstr(char *err, uint nerr)
  11. .PP
  12. .B
  13. void rerrstr(char *err, uint nerr)
  14. .PP
  15. .B
  16. void werrstr(char *fmt, ...)
  17. .SH DESCRIPTION
  18. When a system call fails it returns \-1 and
  19. records a string describing the error in a per-process buffer.
  20. .I Errstr
  21. swaps the contents of that buffer with the contents of the array
  22. .IR err .
  23. .I Errstr
  24. will write at most
  25. .I nerr
  26. bytes into
  27. .IR err ;
  28. if the per-process error string does not fit,
  29. it is silently truncated at a UTF character boundary.
  30. The returned string is NUL-terminated.
  31. Usually
  32. .I errstr
  33. will be called with an empty string,
  34. but the exchange property provides a mechanism for
  35. libraries to set the return value for the next call to
  36. .IR errstr .
  37. .PP
  38. If no system call has generated an error since the last call to
  39. .I errstr
  40. with an empty string,
  41. the result is an empty string.
  42. .PP
  43. The verb
  44. .B r
  45. in
  46. .IR print (2)
  47. calls
  48. .I errstr
  49. and outputs the error string.
  50. .PP
  51. .I Rerrstr
  52. reads the error string but does not modify the per-process buffer, so
  53. a subsequent
  54. .I errstr
  55. will recover the same string.
  56. .PP
  57. .I Werrstr
  58. takes a
  59. .I print
  60. style format as its argument and uses it to format
  61. a string to pass to
  62. .IR errstr .
  63. The string returned from
  64. .I errstr
  65. is discarded.
  66. .SH SOURCE
  67. .B /sys/src/libc/9syscall
  68. .br
  69. .B /sys/src/libc/9sys/werrstr.c
  70. .SH DIAGNOSTICS
  71. .I Errstr
  72. always returns 0.
  73. .SH SEE ALSO
  74. .IR intro (2),
  75. .IR perror (2)