defs.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * defs.h: initial definitions for PuTTY.
  3. *
  4. * The rule about this header file is that it can't depend on any
  5. * other header file in this code base. This is where we define
  6. * things, as much as we can, that other headers will want to refer
  7. * to, such as opaque structure types and their associated typedefs,
  8. * or macros that are used by other headers.
  9. */
  10. #ifndef PUTTY_DEFS_H
  11. #define PUTTY_DEFS_H
  12. #include <stddef.h>
  13. #ifndef FALSE
  14. #define FALSE 0
  15. #endif
  16. #ifndef TRUE
  17. #define TRUE 1
  18. #endif
  19. typedef struct conf_tag Conf;
  20. typedef struct terminal_tag Terminal;
  21. typedef struct Filename Filename;
  22. typedef struct FontSpec FontSpec;
  23. typedef struct bufchain_tag bufchain;
  24. typedef struct strbuf strbuf;
  25. struct RSAKey;
  26. #include <stdint.h>
  27. typedef uint32_t uint32;
  28. typedef struct BinarySink BinarySink;
  29. typedef struct BinarySource BinarySource;
  30. typedef struct SockAddr_tag *SockAddr;
  31. typedef struct Socket_vtable Socket_vtable;
  32. typedef struct Plug_vtable Plug_vtable;
  33. typedef struct Backend Backend;
  34. typedef struct Backend_vtable Backend_vtable;
  35. typedef struct Ldisc_tag Ldisc;
  36. typedef struct LogContext_tag LogContext;
  37. typedef struct Frontend Frontend;
  38. typedef struct ssh_tag *Ssh;
  39. typedef struct Channel Channel;
  40. typedef struct ssh_sharing_state ssh_sharing_state;
  41. typedef struct ssh_sharing_connstate ssh_sharing_connstate;
  42. typedef struct share_channel share_channel;
  43. typedef struct dlgparam dlgparam;
  44. /* Note indirection: for historical reasons (it used to be closer to
  45. * the OS socket type), the type that most code uses for a socket is
  46. * 'Socket', not 'Socket *'. So an implementation of Socket or Plug
  47. * has a 'const Socket *' field for the vtable pointer, and the
  48. * 'Socket' type returned to client code is a pointer to _that_ in
  49. * turn. */
  50. typedef const Socket_vtable **Socket;
  51. typedef const Plug_vtable **Plug;
  52. /*
  53. * A small structure wrapping up a (pointer, length) pair so that it
  54. * can be conveniently passed to or from a function.
  55. */
  56. typedef struct ptrlen {
  57. const void *ptr;
  58. size_t len;
  59. } ptrlen;
  60. typedef struct logblank_t logblank_t;
  61. /* Do a compile-time type-check of 'to_check' (without evaluating it),
  62. * as a side effect of returning the value 'to_return'. Note that
  63. * although this macro double-*expands* to_return, it always
  64. * *evaluates* exactly one copy of it, so it's side-effect safe. */
  65. #define TYPECHECK(to_check, to_return) \
  66. (sizeof(to_check) ? (to_return) : (to_return))
  67. /* Return a pointer to the object of structure type 'type' whose field
  68. * with name 'field' is pointed at by 'object'. */
  69. #define FROMFIELD(object, type, field) \
  70. TYPECHECK(object == &((type *)0)->field, \
  71. ((type *)(((char *)(object)) - offsetof(type, field))))
  72. #endif /* PUTTY_DEFS_H */