]>
git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/libraries/mbed/common/Stream.cpp
1 /* mbed Microcontroller Library
2 * Copyright (c) 2006-2013 ARM Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
22 Stream::Stream(const char *name
) : FileLike(name
), _file(NULL
) {
24 char buf
[12]; /* :0x12345678 + null byte */
25 std::sprintf(buf
, ":%p", this);
26 _file
= std::fopen(buf
, "w+");
27 mbed_set_unbuffered_stream(_file
);
34 int Stream::putc(int c
) {
36 return std::fputc(c
, _file
);
38 int Stream::puts(const char *s
) {
40 return std::fputs(s
, _file
);
44 return mbed_getc(_file
);
46 char* Stream::gets(char *s
, int size
) {
48 return mbed_gets(s
,size
,_file
);
55 ssize_t
Stream::write(const void* buffer
, size_t length
) {
56 const char* ptr
= (const char*)buffer
;
57 const char* end
= ptr
+ length
;
59 if (_putc(*ptr
++) == EOF
) {
63 return ptr
- (const char*)buffer
;
66 ssize_t
Stream::read(void* buffer
, size_t length
) {
67 char* ptr
= (char*)buffer
;
68 char* end
= ptr
+ length
;
74 return ptr
- (const char*)buffer
;
77 off_t
Stream::lseek(off_t offset
, int whence
) {
81 int Stream::isatty() {
89 off_t
Stream::flen() {
93 int Stream::printf(const char* format
, ...) {
95 va_start(arg
, format
);
97 int r
= vfprintf(_file
, format
, arg
);
102 int Stream::scanf(const char* format
, ...) {
104 va_start(arg
, format
);
106 int r
= vfscanf(_file
, format
, arg
);