Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of GPS by
getline.cpp
00001 #include "mbed.h" 00002 // receive a line from a stream, allowing backspace editing, 00003 // and checking for buffer overflow. Terminates on either a \n or \r. 00004 size_t getline(Stream &s, char *buf, size_t bufsize) 00005 { 00006 char c; 00007 size_t receivedChars = 0; 00008 for(;;) 00009 { 00010 c = s.getc(); 00011 if (c == '\r' || c == '\n') 00012 break; 00013 s.putc(c); 00014 if (c == '\b') 00015 { 00016 if (receivedChars > 0) 00017 { 00018 buf--; 00019 receivedChars--; 00020 } 00021 } 00022 else if (receivedChars < bufsize - 1) 00023 { 00024 *buf++ = c; 00025 receivedChars++; 00026 } 00027 } 00028 *buf++ = 0; 00029 s.putc('\n'); 00030 s.putc('\r'); 00031 return receivedChars; 00032 }
Generated on Fri Jul 15 2022 06:22:47 by
1.7.2
