source: rtems/cpukit/libcsupport/src/newlibc_reent.c @ aeba445

4.115
Last change on this file since aeba445 was aeba445, checked in by Sebastian Huber <sebastian.huber@…>, on 04/24/13 at 07:38:00

libcsupport: Remove superfluous assignments

Remove superfluous declaractions, defines, comments and includes.

  • Property mode set to 100644
File size: 1.8 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief Newlib Support
5 *  @ingroup libcsupport
6 */
7
8/*
9 *  COPYRIGHT (c) 1994 by Division Incorporated
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.rtems.com/license/LICENSE.
14 *
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#define __RTEMS_VIOLATE_KERNEL_VISIBILITY__
22#include <rtems.h>
23
24#if defined(RTEMS_NEWLIB)
25
26#include <sys/reent.h>
27#include <stdlib.h>
28#include <stdio.h>
29
30#include <rtems/libcsupport.h>
31
32int _fwalk(struct _reent *ptr, int (*function) (FILE *) );
33
34bool newlib_create_hook(
35  rtems_tcb *current_task __attribute__((unused)),
36  rtems_tcb *creating_task
37)
38{
39  struct _reent *ptr;
40  bool ok;
41
42  if (_Thread_libc_reent == 0)
43  {
44    _REENT = _GLOBAL_REENT;
45
46    _Thread_Set_libc_reent (&_REENT);
47  }
48
49  /* It is OK to allocate from the workspace because these
50   * hooks run with thread dispatching disabled.
51   */
52  ptr = (struct _reent *) _Workspace_Allocate(sizeof(*ptr));
53  creating_task->libc_reent = ptr;
54  ok = ptr != NULL;
55
56  if (ok) {
57    _REENT_INIT_PTR((ptr)); /* GCC extension: structure constants */
58  }
59
60  return ok;
61}
62
63static int newlib_free_buffers(
64  FILE *fp
65)
66{
67  switch ( fileno(fp) ) {
68    case 0:
69    case 1:
70    case 2:
71      if (fp->_flags & __SMBF) {
72        free( fp->_bf._base );
73        fp->_flags &= ~__SMBF;
74        fp->_bf._base = fp->_p = (unsigned char *) NULL;
75      }
76      break;
77    default:
78     fclose(fp);
79  }
80  return 0;
81}
82
83void newlib_delete_hook(
84  rtems_tcb *current_task,
85  rtems_tcb *deleted_task
86)
87{
88  struct _reent *ptr;
89
90  ptr = deleted_task->libc_reent;
91  deleted_task->libc_reent = NULL;
92
93  /*
94   *  Just in case there are some buffers lying around.
95   */
96  _fwalk(ptr, newlib_free_buffers);
97
98  _Workspace_Free(ptr);
99}
100
101#endif
Note: See TracBrowser for help on using the repository browser.