source: trunk/libs/newlib/src/libgloss/msp430/write.c @ 532

Last change on this file since 532 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 1.5 KB
Line 
1/* Copyright (c) 2013 Red Hat, Inc. All rights reserved.
2
3   This copyrighted material is made available to anyone wishing to use, modify,
4   copy, or redistribute it subject to the terms and conditions of the BSD
5   License.   This program is distributed in the hope that it will be useful,
6   but WITHOUT ANY WARRANTY expressed or implied, including the implied warranties
7   of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  A copy of this license
8   is available at http://www.opensource.org/licenses. Any Red Hat trademarks that
9   are incorporated in the source code or documentation are not subject to the BSD
10   License and may only be used or replicated with the express permission of
11   Red Hat, Inc.
12*/
13
14#include <string.h>
15
16#include "cio.h"
17
18static int
19write_chunk (int fd, char *buf, int len)
20{
21  __CIOBUF__.length[0] = len;
22  __CIOBUF__.length[1] = len >> 8;
23  __CIOBUF__.parms[0] = CIO_WRITE;
24  __CIOBUF__.parms[1] = fd;
25  __CIOBUF__.parms[2] = fd >> 8;
26  __CIOBUF__.parms[3] = len;
27  __CIOBUF__.parms[4] = len >> 8;
28  memcpy (__CIOBUF__.buf, buf, len);
29
30  _libgloss_cio_hook ();
31
32  return __CIOBUF__.parms[0] + __CIOBUF__.parms[1] * 256;
33}
34
35#include <stdio.h>
36
37int
38write (int fd, char *buf, int len)
39{
40  int rv = 0;
41  int c;
42#if 0
43  if (fd == 2)
44    fprintf (stderr, "%.*s", buf, len);
45  else if (fd == 1)
46    printf ("%.*s", buf, len);
47#endif
48  while (len > 0)
49    {
50      int l = (len > CIO_BUF_SIZE) ? CIO_BUF_SIZE : len;
51      c = write_chunk (fd, buf, l);
52      if (c < 0)
53        return c;
54      rv += l;
55      len -= l;
56      buf += l;
57    }
58  return rv;
59}
Note: See TracBrowser for help on using the repository browser.