reent_init.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include <string.h>
  15. #include <sys/reent.h>
  16. #include "esp_attr.h"
  17. /* This function is not part on newlib API, it is defined in libc/stdio/local.h
  18. * There is no nice way to get __cleanup member populated while avoiding __sinit,
  19. * so extern declaration is used here.
  20. */
  21. extern void _cleanup_r(struct _reent* r);
  22. /**
  23. * This is the replacement for newlib's _REENT_INIT_PTR and __sinit.
  24. * The problem with __sinit is that it allocates three FILE structures
  25. * (stdin, stdout, stderr). Having individual standard streams for each task
  26. * is a bit too much on a small embedded system. So we point streams
  27. * to the streams of the global struct _reent, which are initialized in
  28. * startup code.
  29. */
  30. void IRAM_ATTR esp_reent_init(struct _reent* r)
  31. {
  32. memset(r, 0, sizeof(*r));
  33. r->_stdout = _GLOBAL_REENT->_stdout;
  34. r->_stderr = _GLOBAL_REENT->_stderr;
  35. r->_stdin = _GLOBAL_REENT->_stdin;
  36. r->__cleanup = &_cleanup_r;
  37. r->__sdidinit = 1;
  38. r->__sglue._next = NULL;
  39. r->__sglue._niobs = 0;
  40. r->__sglue._iobs = NULL;
  41. r->_current_locale = "C";
  42. }