defs.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 backend_tag Backend;
  21. typedef struct terminal_tag Terminal;
  22. typedef struct Filename Filename;
  23. typedef struct FontSpec FontSpec;
  24. typedef struct bufchain_tag bufchain;
  25. typedef struct strbuf strbuf;
  26. struct RSAKey;
  27. #include <stdint.h>
  28. typedef uint32_t uint32;
  29. typedef struct BinarySink BinarySink;
  30. typedef struct BinarySource BinarySource;
  31. typedef struct SockAddr_tag *SockAddr;
  32. typedef struct Socket_vtable Socket_vtable;
  33. typedef struct Plug_vtable Plug_vtable;
  34. /* Note indirection: for historical reasons (it used to be closer to
  35. * the OS socket type), the type that most code uses for a socket is
  36. * 'Socket', not 'Socket *'. So an implementation of Socket or Plug
  37. * has a 'const Socket *' field for the vtable pointer, and the
  38. * 'Socket' type returned to client code is a pointer to _that_ in
  39. * turn. */
  40. typedef const Socket_vtable **Socket;
  41. typedef const Plug_vtable **Plug;
  42. /*
  43. * A small structure wrapping up a (pointer, length) pair so that it
  44. * can be conveniently passed to or from a function.
  45. */
  46. typedef struct ptrlen {
  47. const void *ptr;
  48. size_t len;
  49. } ptrlen;
  50. typedef struct logblank_t logblank_t;
  51. /* Do a compile-time type-check of 'to_check' (without evaluating it),
  52. * as a side effect of returning the value 'to_return'. Note that
  53. * although this macro double-*expands* to_return, it always
  54. * *evaluates* exactly one copy of it, so it's side-effect safe. */
  55. #define TYPECHECK(to_check, to_return) \
  56. (sizeof(to_check) ? (to_return) : (to_return))
  57. /* Return a pointer to the object of structure type 'type' whose field
  58. * with name 'field' is pointed at by 'object'. */
  59. #define FROMFIELD(object, type, field) \
  60. TYPECHECK(object == &((type *)0)->field, \
  61. ((type *)(((char *)(object)) - offsetof(type, field))))
  62. #endif /* PUTTY_DEFS_H */