CStr.def 961 B

1234567891011121314151617181920212223242526272829
  1. DEFINITION MODULE CStr;
  2. (* Explicit C string types and conversions.
  3. CString is a pointer to a NUL-terminated C byte string. It is an
  4. ADDRESS alias, so it can be stored, compared with NIL, returned from
  5. a FOR "C" procedure, and passed to another C function without any
  6. hidden descriptor conversion.
  7. CBuffer is the same representation, used for a writable C buffer.
  8. A V3 ARRAY OF CHAR can still be passed directly to a C function;
  9. use Copy for the reverse direction (C string -> V3 string). *)
  10. FROM SYSTEM IMPORT ADDRESS;
  11. TYPE
  12. CString = ADDRESS;
  13. CBuffer = ADDRESS;
  14. PROCEDURE Length (s : CString) : CARDINAL;
  15. (* strlen-like length; NIL has length 0. *)
  16. PROCEDURE Copy (s : CString; VAR dst : ARRAY OF CHAR) : CARDINAL;
  17. (* Copy s into dst, truncating to dst's capacity and NUL-terminating.
  18. NIL clears dst. Returns the number of bytes copied. *)
  19. PROCEDURE IsNil (s : CString) : BOOLEAN;
  20. (* TRUE for a NIL C string. *)
  21. END CStr.