1
0

readnum 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. .TH READNUM 9
  2. .SH NAME
  3. readnum, readstr \- return values from read from device
  4. .SH SYNOPSIS
  5. .ta \w'\fLchar* 'u
  6. .B
  7. int readstr(ulong off, char *buf, ulong n, char *str)
  8. .PP
  9. .B
  10. int readnum(ulong off, char *buf, ulong n, ulong val, int size)
  11. .SH DESCRIPTION
  12. .I Readstr
  13. and
  14. .I readnum
  15. simplify the return of strings and numbers from device
  16. .I read
  17. routines,
  18. because they deal with any buffering and boundary cases.
  19. Several parameters to the read call are often handed on directly
  20. to these functions:
  21. the file offset, as
  22. .IR off ;
  23. the address of the user's buffer, as
  24. .IR buf ;
  25. and the number of bytes requested, as
  26. .IR n .
  27. Both functions return the number of bytes they have stored in
  28. .IR buf ,
  29. and which can often be returned directly from the device read routine.
  30. .PP
  31. .I Readstr
  32. satisfies a read by copying data into
  33. .I buf
  34. from the NUL-terminated string in
  35. .IR str .
  36. The data transferred is selected and limited by
  37. .IR off ,
  38. .I n
  39. and the length of
  40. .IR str .
  41. .PP
  42. .I Readnum
  43. converts the unsigned integer
  44. .I val
  45. to a decimal representation in
  46. .IR buf .
  47. The value is right-justified in a field of
  48. .IR size "-1"
  49. places and is followed by a blank.
  50. .I Size
  51. can be the global constant
  52. .L NUMSIZE
  53. for 32-bit integers;
  54. the largest
  55. .I size
  56. allowed is 64 bytes.
  57. .SH SOURCE
  58. .B /sys/src/9/port/devcons.c