2
0

bss_null.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License 2.0 (the "License"). You may not use
  5. * this file except in compliance with the License. You can obtain a copy
  6. * in the file LICENSE in the source distribution or at
  7. * https://www.openssl.org/source/license.html
  8. */
  9. #include <stdio.h>
  10. #include <errno.h>
  11. #include "bio_local.h"
  12. #include "internal/cryptlib.h"
  13. static int null_write(BIO *h, const char *buf, int num);
  14. static int null_read(BIO *h, char *buf, int size);
  15. static int null_puts(BIO *h, const char *str);
  16. static int null_gets(BIO *h, char *str, int size);
  17. static long null_ctrl(BIO *h, int cmd, long arg1, void *arg2);
  18. static const BIO_METHOD null_method = {
  19. BIO_TYPE_NULL,
  20. "NULL",
  21. bwrite_conv,
  22. null_write,
  23. bread_conv,
  24. null_read,
  25. null_puts,
  26. null_gets,
  27. null_ctrl,
  28. NULL,
  29. NULL,
  30. NULL, /* null_callback_ctrl */
  31. };
  32. const BIO_METHOD *BIO_s_null(void)
  33. {
  34. return &null_method;
  35. }
  36. static int null_read(BIO *b, char *out, int outl)
  37. {
  38. return 0;
  39. }
  40. static int null_write(BIO *b, const char *in, int inl)
  41. {
  42. return inl;
  43. }
  44. static long null_ctrl(BIO *b, int cmd, long num, void *ptr)
  45. {
  46. long ret = 1;
  47. switch (cmd) {
  48. case BIO_CTRL_RESET:
  49. case BIO_CTRL_EOF:
  50. case BIO_CTRL_SET:
  51. case BIO_CTRL_SET_CLOSE:
  52. case BIO_CTRL_FLUSH:
  53. case BIO_CTRL_DUP:
  54. ret = 1;
  55. break;
  56. case BIO_CTRL_GET_CLOSE:
  57. case BIO_CTRL_INFO:
  58. case BIO_CTRL_GET:
  59. case BIO_CTRL_PENDING:
  60. case BIO_CTRL_WPENDING:
  61. default:
  62. ret = 0;
  63. break;
  64. }
  65. return ret;
  66. }
  67. static int null_gets(BIO *bp, char *buf, int size)
  68. {
  69. return 0;
  70. }
  71. static int null_puts(BIO *bp, const char *str)
  72. {
  73. if (str == NULL)
  74. return 0;
  75. return strlen(str);
  76. }