Carl-Daniel Hailfinger | e51ea10 | 2009-11-23 19:20:11 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
| 4 | * Copyright (C) 2009 Urja Rannikko <urjaman@gmail.com> |
Carl-Daniel Hailfinger | efa151e | 2010-01-06 16:09:10 +0000 | [diff] [blame] | 5 | * Copyright (C) 2009,2010 Carl-Daniel Hailfinger |
Carl-Daniel Hailfinger | e51ea10 | 2009-11-23 19:20:11 +0000 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
| 21 | |
| 22 | #include <stdio.h> |
| 23 | #include <stdlib.h> |
| 24 | #include <unistd.h> |
Carl-Daniel Hailfinger | e51ea10 | 2009-11-23 19:20:11 +0000 | [diff] [blame] | 25 | #include <string.h> |
| 26 | #include <ctype.h> |
| 27 | #include <fcntl.h> |
Carl-Daniel Hailfinger | e51ea10 | 2009-11-23 19:20:11 +0000 | [diff] [blame] | 28 | #include <sys/stat.h> |
| 29 | #include <errno.h> |
| 30 | #include <inttypes.h> |
Patrick Georgi | e48654c | 2010-01-06 22:14:39 +0000 | [diff] [blame] | 31 | #ifdef _WIN32 |
| 32 | #include <conio.h> |
| 33 | #else |
Carl-Daniel Hailfinger | e51ea10 | 2009-11-23 19:20:11 +0000 | [diff] [blame] | 34 | #include <termios.h> |
Virgil-Adrian Teaca | da7c545 | 2012-04-30 23:11:06 +0000 | [diff] [blame] | 35 | #include <unistd.h> |
| 36 | #include <sys/types.h> |
| 37 | #include <sys/ioctl.h> |
Patrick Georgi | e48654c | 2010-01-06 22:14:39 +0000 | [diff] [blame] | 38 | #endif |
Carl-Daniel Hailfinger | 5b997c3 | 2010-07-27 22:41:39 +0000 | [diff] [blame] | 39 | #include "flash.h" |
| 40 | #include "programmer.h" |
Carl-Daniel Hailfinger | e51ea10 | 2009-11-23 19:20:11 +0000 | [diff] [blame] | 41 | |
Patrick Georgi | e48654c | 2010-01-06 22:14:39 +0000 | [diff] [blame] | 42 | fdtype sp_fd; |
Carl-Daniel Hailfinger | e51ea10 | 2009-11-23 19:20:11 +0000 | [diff] [blame] | 43 | |
| 44 | void __attribute__((noreturn)) sp_die(char *msg) |
| 45 | { |
| 46 | perror(msg); |
| 47 | exit(1); |
| 48 | } |
| 49 | |
Patrick Georgi | e48654c | 2010-01-06 22:14:39 +0000 | [diff] [blame] | 50 | #ifndef _WIN32 |
Carl-Daniel Hailfinger | e51ea10 | 2009-11-23 19:20:11 +0000 | [diff] [blame] | 51 | struct baudentry { |
| 52 | int flag; |
| 53 | unsigned int baud; |
| 54 | }; |
| 55 | |
| 56 | /* I'd like if the C preprocessor could have directives in macros */ |
| 57 | #define BAUDENTRY(baud) { B##baud, baud }, |
| 58 | static const struct baudentry sp_baudtable[] = { |
| 59 | BAUDENTRY(9600) |
| 60 | BAUDENTRY(19200) |
| 61 | BAUDENTRY(38400) |
| 62 | BAUDENTRY(57600) |
| 63 | BAUDENTRY(115200) |
| 64 | #ifdef B230400 |
| 65 | BAUDENTRY(230400) |
| 66 | #endif |
| 67 | #ifdef B460800 |
| 68 | BAUDENTRY(460800) |
| 69 | #endif |
| 70 | #ifdef B500000 |
| 71 | BAUDENTRY(500000) |
| 72 | #endif |
| 73 | #ifdef B576000 |
| 74 | BAUDENTRY(576000) |
| 75 | #endif |
| 76 | #ifdef B921600 |
| 77 | BAUDENTRY(921600) |
| 78 | #endif |
| 79 | #ifdef B1000000 |
| 80 | BAUDENTRY(1000000) |
| 81 | #endif |
| 82 | #ifdef B1152000 |
| 83 | BAUDENTRY(1152000) |
| 84 | #endif |
| 85 | #ifdef B1500000 |
| 86 | BAUDENTRY(1500000) |
| 87 | #endif |
| 88 | #ifdef B2000000 |
| 89 | BAUDENTRY(2000000) |
| 90 | #endif |
| 91 | #ifdef B2500000 |
| 92 | BAUDENTRY(2500000) |
| 93 | #endif |
| 94 | #ifdef B3000000 |
| 95 | BAUDENTRY(3000000) |
| 96 | #endif |
| 97 | #ifdef B3500000 |
| 98 | BAUDENTRY(3500000) |
| 99 | #endif |
| 100 | #ifdef B4000000 |
| 101 | BAUDENTRY(4000000) |
| 102 | #endif |
| 103 | {0, 0} /* Terminator */ |
| 104 | }; |
Patrick Georgi | e48654c | 2010-01-06 22:14:39 +0000 | [diff] [blame] | 105 | #endif |
Carl-Daniel Hailfinger | e51ea10 | 2009-11-23 19:20:11 +0000 | [diff] [blame] | 106 | |
Stefan Tauner | bf88be9 | 2013-04-01 00:45:08 +0000 | [diff] [blame^] | 107 | /* Uses msg_perr to print the last system error. |
| 108 | * Prints "Error: " followed first by \c msg and then by the description of the last error retrieved via |
| 109 | * strerror() or FormatMessage() and ending with a linebreak. */ |
| 110 | static void msg_perr_strerror(const char *msg) |
| 111 | { |
| 112 | msg_perr("Error: %s", msg); |
| 113 | #ifdef _WIN32 |
| 114 | char *lpMsgBuf; |
| 115 | DWORD nErr = GetLastError(); |
| 116 | FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, nErr, |
| 117 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL); |
| 118 | msg_perr(lpMsgBuf); |
| 119 | /* At least some formatted messages contain a line break at the end. Make sure to always print one */ |
| 120 | if (lpMsgBuf[strlen(lpMsgBuf)-1] != '\n') |
| 121 | msg_perr("\n"); |
| 122 | LocalFree(lpMsgBuf); |
| 123 | #else |
| 124 | msg_perr("%s\n", strerror(errno)); |
| 125 | #endif |
| 126 | } |
| 127 | |
Patrick Georgi | e48654c | 2010-01-06 22:14:39 +0000 | [diff] [blame] | 128 | fdtype sp_openserport(char *dev, unsigned int baud) |
Carl-Daniel Hailfinger | e51ea10 | 2009-11-23 19:20:11 +0000 | [diff] [blame] | 129 | { |
Patrick Georgi | e48654c | 2010-01-06 22:14:39 +0000 | [diff] [blame] | 130 | #ifdef _WIN32 |
| 131 | HANDLE fd; |
Uwe Hermann | 4395970 | 2010-03-13 17:28:29 +0000 | [diff] [blame] | 132 | char *dev2 = dev; |
Stefan Tauner | bf88be9 | 2013-04-01 00:45:08 +0000 | [diff] [blame^] | 133 | if ((strlen(dev) > 3) && |
| 134 | (tolower((unsigned char)dev[0]) == 'c') && |
Carl-Daniel Hailfinger | 9e3a6c4 | 2010-10-08 12:40:09 +0000 | [diff] [blame] | 135 | (tolower((unsigned char)dev[1]) == 'o') && |
| 136 | (tolower((unsigned char)dev[2]) == 'm')) { |
Uwe Hermann | 4395970 | 2010-03-13 17:28:29 +0000 | [diff] [blame] | 137 | dev2 = malloc(strlen(dev) + 5); |
Niklas Söderlund | 2a95e87 | 2012-07-30 19:42:33 +0000 | [diff] [blame] | 138 | if (!dev2) { |
Stefan Tauner | bf88be9 | 2013-04-01 00:45:08 +0000 | [diff] [blame^] | 139 | msg_perr_strerror("Out of memory: "); |
Stefan Tauner | bb4fed7 | 2012-09-01 21:47:19 +0000 | [diff] [blame] | 140 | return SER_INV_FD; |
Niklas Söderlund | 2a95e87 | 2012-07-30 19:42:33 +0000 | [diff] [blame] | 141 | } |
Patrick Georgi | 06602c2 | 2010-01-26 20:58:40 +0000 | [diff] [blame] | 142 | strcpy(dev2, "\\\\.\\"); |
Uwe Hermann | 4395970 | 2010-03-13 17:28:29 +0000 | [diff] [blame] | 143 | strcpy(dev2 + 4, dev); |
Patrick Georgi | 06602c2 | 2010-01-26 20:58:40 +0000 | [diff] [blame] | 144 | } |
Uwe Hermann | 4395970 | 2010-03-13 17:28:29 +0000 | [diff] [blame] | 145 | fd = CreateFile(dev2, GENERIC_READ | GENERIC_WRITE, 0, NULL, |
| 146 | OPEN_EXISTING, 0, NULL); |
Patrick Georgi | 06602c2 | 2010-01-26 20:58:40 +0000 | [diff] [blame] | 147 | if (dev2 != dev) |
| 148 | free(dev2); |
Patrick Georgi | e48654c | 2010-01-06 22:14:39 +0000 | [diff] [blame] | 149 | if (fd == INVALID_HANDLE_VALUE) { |
Stefan Tauner | bf88be9 | 2013-04-01 00:45:08 +0000 | [diff] [blame^] | 150 | msg_perr_strerror("Cannot open serial port: "); |
Stefan Tauner | bb4fed7 | 2012-09-01 21:47:19 +0000 | [diff] [blame] | 151 | return SER_INV_FD; |
Patrick Georgi | e48654c | 2010-01-06 22:14:39 +0000 | [diff] [blame] | 152 | } |
| 153 | DCB dcb; |
| 154 | if (!GetCommState(fd, &dcb)) { |
Stefan Tauner | bf88be9 | 2013-04-01 00:45:08 +0000 | [diff] [blame^] | 155 | msg_perr_strerror("Could not fetch serial port configuration: "); |
Stefan Tauner | bb4fed7 | 2012-09-01 21:47:19 +0000 | [diff] [blame] | 156 | return SER_INV_FD; |
Patrick Georgi | e48654c | 2010-01-06 22:14:39 +0000 | [diff] [blame] | 157 | } |
| 158 | switch (baud) { |
| 159 | case 9600: dcb.BaudRate = CBR_9600; break; |
| 160 | case 19200: dcb.BaudRate = CBR_19200; break; |
| 161 | case 38400: dcb.BaudRate = CBR_38400; break; |
| 162 | case 57600: dcb.BaudRate = CBR_57600; break; |
| 163 | case 115200: dcb.BaudRate = CBR_115200; break; |
Niklas Söderlund | 2a95e87 | 2012-07-30 19:42:33 +0000 | [diff] [blame] | 164 | default: msg_perr("Error: Could not set baud rate: %s\n", strerror(errno)); |
Stefan Tauner | bb4fed7 | 2012-09-01 21:47:19 +0000 | [diff] [blame] | 165 | return SER_INV_FD; |
Patrick Georgi | e48654c | 2010-01-06 22:14:39 +0000 | [diff] [blame] | 166 | } |
Uwe Hermann | 4395970 | 2010-03-13 17:28:29 +0000 | [diff] [blame] | 167 | dcb.ByteSize = 8; |
| 168 | dcb.Parity = NOPARITY; |
| 169 | dcb.StopBits = ONESTOPBIT; |
Patrick Georgi | e48654c | 2010-01-06 22:14:39 +0000 | [diff] [blame] | 170 | if (!SetCommState(fd, &dcb)) { |
Stefan Tauner | bf88be9 | 2013-04-01 00:45:08 +0000 | [diff] [blame^] | 171 | msg_perr_strerror("Could not change serial port configuration: "); |
Stefan Tauner | bb4fed7 | 2012-09-01 21:47:19 +0000 | [diff] [blame] | 172 | return SER_INV_FD; |
Patrick Georgi | e48654c | 2010-01-06 22:14:39 +0000 | [diff] [blame] | 173 | } |
| 174 | return fd; |
| 175 | #else |
Carl-Daniel Hailfinger | e51ea10 | 2009-11-23 19:20:11 +0000 | [diff] [blame] | 176 | struct termios options; |
| 177 | int fd, i; |
| 178 | fd = open(dev, O_RDWR | O_NOCTTY | O_NDELAY); |
Niklas Söderlund | 2a95e87 | 2012-07-30 19:42:33 +0000 | [diff] [blame] | 179 | if (fd < 0) { |
Stefan Tauner | bf88be9 | 2013-04-01 00:45:08 +0000 | [diff] [blame^] | 180 | msg_perr_strerror("Cannot open serial port: "); |
Stefan Tauner | bb4fed7 | 2012-09-01 21:47:19 +0000 | [diff] [blame] | 181 | return SER_INV_FD; |
Niklas Söderlund | 2a95e87 | 2012-07-30 19:42:33 +0000 | [diff] [blame] | 182 | } |
Carl-Daniel Hailfinger | e51ea10 | 2009-11-23 19:20:11 +0000 | [diff] [blame] | 183 | fcntl(fd, F_SETFL, 0); |
| 184 | tcgetattr(fd, &options); |
| 185 | for (i = 0;; i++) { |
| 186 | if (sp_baudtable[i].baud == 0) { |
| 187 | close(fd); |
Niklas Söderlund | 2a95e87 | 2012-07-30 19:42:33 +0000 | [diff] [blame] | 188 | msg_perr("Error: cannot configure for baudrate %d\n", baud); |
Stefan Tauner | bb4fed7 | 2012-09-01 21:47:19 +0000 | [diff] [blame] | 189 | return SER_INV_FD; |
Carl-Daniel Hailfinger | e51ea10 | 2009-11-23 19:20:11 +0000 | [diff] [blame] | 190 | } |
| 191 | if (sp_baudtable[i].baud == baud) { |
| 192 | cfsetispeed(&options, sp_baudtable[i].flag); |
| 193 | cfsetospeed(&options, sp_baudtable[i].flag); |
| 194 | break; |
| 195 | } |
| 196 | } |
| 197 | options.c_cflag &= ~(PARENB | CSTOPB | CSIZE | CRTSCTS); |
| 198 | options.c_cflag |= (CS8 | CLOCAL | CREAD); |
| 199 | options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); |
| 200 | options.c_iflag &= ~(IXON | IXOFF | IXANY | ICRNL | IGNCR | INLCR); |
| 201 | options.c_oflag &= ~OPOST; |
| 202 | tcsetattr(fd, TCSANOW, &options); |
| 203 | return fd; |
Patrick Georgi | e48654c | 2010-01-06 22:14:39 +0000 | [diff] [blame] | 204 | #endif |
Carl-Daniel Hailfinger | e51ea10 | 2009-11-23 19:20:11 +0000 | [diff] [blame] | 205 | } |
| 206 | |
Virgil-Adrian Teaca | da7c545 | 2012-04-30 23:11:06 +0000 | [diff] [blame] | 207 | void sp_set_pin(enum SP_PIN pin, int val) { |
| 208 | #ifdef _WIN32 |
| 209 | DWORD ctl; |
| 210 | |
| 211 | if(pin == PIN_TXD) { |
| 212 | ctl = val ? SETBREAK: CLRBREAK; |
| 213 | } |
| 214 | else if(pin == PIN_DTR) { |
| 215 | ctl = val ? SETDTR: CLRDTR; |
| 216 | } |
| 217 | else { |
| 218 | ctl = val ? SETRTS: CLRRTS; |
| 219 | } |
| 220 | EscapeCommFunction(sp_fd, ctl); |
| 221 | #else |
| 222 | int ctl, s; |
| 223 | |
| 224 | if(pin == PIN_TXD) { |
| 225 | ioctl(sp_fd, val ? TIOCSBRK : TIOCCBRK, 0); |
| 226 | } |
| 227 | else { |
| 228 | s = (pin == PIN_DTR) ? TIOCM_DTR : TIOCM_RTS; |
| 229 | ioctl(sp_fd, TIOCMGET, &ctl); |
| 230 | |
| 231 | if (val) { |
| 232 | ctl |= s; |
| 233 | } |
| 234 | else { |
| 235 | ctl &= ~s; |
| 236 | } |
| 237 | ioctl(sp_fd, TIOCMSET, &ctl); |
| 238 | } |
| 239 | #endif |
| 240 | } |
| 241 | |
| 242 | int sp_get_pin(enum SP_PIN pin) { |
| 243 | int s; |
| 244 | #ifdef _WIN32 |
| 245 | DWORD ctl; |
| 246 | |
| 247 | s = (pin == PIN_CTS) ? MS_CTS_ON : MS_DSR_ON; |
| 248 | GetCommModemStatus(sp_fd, &ctl); |
| 249 | #else |
| 250 | int ctl; |
| 251 | s = (pin == PIN_CTS) ? TIOCM_CTS : TIOCM_DSR; |
| 252 | ioctl(sp_fd, TIOCMGET, &ctl); |
| 253 | #endif |
| 254 | |
| 255 | return ((ctl & s) ? 1 : 0); |
| 256 | |
| 257 | } |
| 258 | |
Carl-Daniel Hailfinger | e51ea10 | 2009-11-23 19:20:11 +0000 | [diff] [blame] | 259 | void sp_flush_incoming(void) |
| 260 | { |
Patrick Georgi | e48654c | 2010-01-06 22:14:39 +0000 | [diff] [blame] | 261 | #ifdef _WIN32 |
| 262 | PurgeComm(sp_fd, PURGE_RXCLEAR); |
| 263 | #else |
Niklas Söderlund | 7145a50 | 2012-09-07 07:07:07 +0000 | [diff] [blame] | 264 | /* FIXME: error handling */ |
Patrick Georgi | 3b6237d | 2010-01-06 19:09:40 +0000 | [diff] [blame] | 265 | tcflush(sp_fd, TCIFLUSH); |
Patrick Georgi | e48654c | 2010-01-06 22:14:39 +0000 | [diff] [blame] | 266 | #endif |
Carl-Daniel Hailfinger | e51ea10 | 2009-11-23 19:20:11 +0000 | [diff] [blame] | 267 | return; |
| 268 | } |
Carl-Daniel Hailfinger | efa151e | 2010-01-06 16:09:10 +0000 | [diff] [blame] | 269 | |
David Hendricks | 8bb2021 | 2011-06-14 01:35:36 +0000 | [diff] [blame] | 270 | int serialport_shutdown(void *data) |
Carl-Daniel Hailfinger | efa151e | 2010-01-06 16:09:10 +0000 | [diff] [blame] | 271 | { |
Patrick Georgi | e48654c | 2010-01-06 22:14:39 +0000 | [diff] [blame] | 272 | #ifdef _WIN32 |
| 273 | CloseHandle(sp_fd); |
| 274 | #else |
Carl-Daniel Hailfinger | efa151e | 2010-01-06 16:09:10 +0000 | [diff] [blame] | 275 | close(sp_fd); |
Patrick Georgi | e48654c | 2010-01-06 22:14:39 +0000 | [diff] [blame] | 276 | #endif |
Carl-Daniel Hailfinger | efa151e | 2010-01-06 16:09:10 +0000 | [diff] [blame] | 277 | return 0; |
| 278 | } |
| 279 | |
| 280 | int serialport_write(unsigned char *buf, unsigned int writecnt) |
| 281 | { |
Uwe Hermann | d5e85d6 | 2011-07-03 19:44:12 +0000 | [diff] [blame] | 282 | #ifdef _WIN32 |
| 283 | DWORD tmp = 0; |
| 284 | #else |
| 285 | ssize_t tmp = 0; |
| 286 | #endif |
Stefan Tauner | 62574aa | 2012-11-30 16:46:41 +0000 | [diff] [blame] | 287 | unsigned int empty_writes = 250; /* results in a ca. 125ms timeout */ |
Carl-Daniel Hailfinger | efa151e | 2010-01-06 16:09:10 +0000 | [diff] [blame] | 288 | |
Patrick Georgi | 3b6237d | 2010-01-06 19:09:40 +0000 | [diff] [blame] | 289 | while (writecnt > 0) { |
Patrick Georgi | e48654c | 2010-01-06 22:14:39 +0000 | [diff] [blame] | 290 | #ifdef _WIN32 |
| 291 | WriteFile(sp_fd, buf, writecnt, &tmp, NULL); |
| 292 | #else |
Patrick Georgi | 3b6237d | 2010-01-06 19:09:40 +0000 | [diff] [blame] | 293 | tmp = write(sp_fd, buf, writecnt); |
Patrick Georgi | e48654c | 2010-01-06 22:14:39 +0000 | [diff] [blame] | 294 | #endif |
Carl-Daniel Hailfinger | d2f007f | 2010-09-16 22:34:25 +0000 | [diff] [blame] | 295 | if (tmp == -1) { |
| 296 | msg_perr("Serial port write error!\n"); |
Carl-Daniel Hailfinger | efa151e | 2010-01-06 16:09:10 +0000 | [diff] [blame] | 297 | return 1; |
Carl-Daniel Hailfinger | d2f007f | 2010-09-16 22:34:25 +0000 | [diff] [blame] | 298 | } |
Stefan Tauner | 62574aa | 2012-11-30 16:46:41 +0000 | [diff] [blame] | 299 | if (!tmp) { |
| 300 | msg_pdbg2("Empty write\n"); |
| 301 | empty_writes--; |
| 302 | programmer_delay(500); |
| 303 | if (empty_writes == 0) { |
| 304 | msg_perr("Serial port is unresponsive!\n"); |
| 305 | return 1; |
| 306 | } |
| 307 | } |
| 308 | writecnt -= tmp; |
Patrick Georgi | 3b6237d | 2010-01-06 19:09:40 +0000 | [diff] [blame] | 309 | buf += tmp; |
Carl-Daniel Hailfinger | efa151e | 2010-01-06 16:09:10 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | return 0; |
| 313 | } |
| 314 | |
| 315 | int serialport_read(unsigned char *buf, unsigned int readcnt) |
| 316 | { |
Uwe Hermann | d5e85d6 | 2011-07-03 19:44:12 +0000 | [diff] [blame] | 317 | #ifdef _WIN32 |
| 318 | DWORD tmp = 0; |
| 319 | #else |
| 320 | ssize_t tmp = 0; |
| 321 | #endif |
Carl-Daniel Hailfinger | efa151e | 2010-01-06 16:09:10 +0000 | [diff] [blame] | 322 | |
Patrick Georgi | 3b6237d | 2010-01-06 19:09:40 +0000 | [diff] [blame] | 323 | while (readcnt > 0) { |
Patrick Georgi | e48654c | 2010-01-06 22:14:39 +0000 | [diff] [blame] | 324 | #ifdef _WIN32 |
| 325 | ReadFile(sp_fd, buf, readcnt, &tmp, NULL); |
| 326 | #else |
Patrick Georgi | 3b6237d | 2010-01-06 19:09:40 +0000 | [diff] [blame] | 327 | tmp = read(sp_fd, buf, readcnt); |
Patrick Georgi | e48654c | 2010-01-06 22:14:39 +0000 | [diff] [blame] | 328 | #endif |
Carl-Daniel Hailfinger | d2f007f | 2010-09-16 22:34:25 +0000 | [diff] [blame] | 329 | if (tmp == -1) { |
| 330 | msg_perr("Serial port read error!\n"); |
Carl-Daniel Hailfinger | efa151e | 2010-01-06 16:09:10 +0000 | [diff] [blame] | 331 | return 1; |
Carl-Daniel Hailfinger | d2f007f | 2010-09-16 22:34:25 +0000 | [diff] [blame] | 332 | } |
Carl-Daniel Hailfinger | efa151e | 2010-01-06 16:09:10 +0000 | [diff] [blame] | 333 | if (!tmp) |
Sean Nelson | ebb4f5f | 2010-01-09 23:46:39 +0000 | [diff] [blame] | 334 | msg_pdbg("Empty read\n"); |
Patrick Georgi | 3b6237d | 2010-01-06 19:09:40 +0000 | [diff] [blame] | 335 | readcnt -= tmp; |
| 336 | buf += tmp; |
Carl-Daniel Hailfinger | efa151e | 2010-01-06 16:09:10 +0000 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | return 0; |
| 340 | } |