bss_null.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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_lcl.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. /* TODO: Convert to new style write function */
  22. bwrite_conv,
  23. null_write,
  24. /* TODO: Convert to new style read function */
  25. bread_conv,
  26. null_read,
  27. null_puts,
  28. null_gets,
  29. null_ctrl,
  30. NULL,
  31. NULL,
  32. NULL, /* null_callback_ctrl */
  33. };
  34. const BIO_METHOD *BIO_s_null(void)
  35. {
  36. return &null_method;
  37. }
  38. static int null_read(BIO *b, char *out, int outl)
  39. {
  40. return 0;
  41. }
  42. static int null_write(BIO *b, const char *in, int inl)
  43. {
  44. return inl;
  45. }
  46. static long null_ctrl(BIO *b, int cmd, long num, void *ptr)
  47. {
  48. long ret = 1;
  49. switch (cmd) {
  50. case BIO_CTRL_RESET:
  51. case BIO_CTRL_EOF:
  52. case BIO_CTRL_SET:
  53. case BIO_CTRL_SET_CLOSE:
  54. case BIO_CTRL_FLUSH:
  55. case BIO_CTRL_DUP:
  56. ret = 1;
  57. break;
  58. case BIO_CTRL_GET_CLOSE:
  59. case BIO_CTRL_INFO:
  60. case BIO_CTRL_GET:
  61. case BIO_CTRL_PENDING:
  62. case BIO_CTRL_WPENDING:
  63. default:
  64. ret = 0;
  65. break;
  66. }
  67. return ret;
  68. }
  69. static int null_gets(BIO *bp, char *buf, int size)
  70. {
  71. return 0;
  72. }
  73. static int null_puts(BIO *bp, const char *str)
  74. {
  75. if (str == NULL)
  76. return 0;
  77. return strlen(str);
  78. }