qcaux: add more Pantech UML190 and UML290 ports
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / um / drivers / slip_common.c
blobe89cfc68fc3e077b526186fefc4bd8b810bff9e4
1 #include <string.h>
2 #include "slip_common.h"
3 #include "net_user.h"
5 int slip_proto_read(int fd, void *buf, int len, struct slip_proto *slip)
7 int i, n, size, start;
9 if(slip->more > 0){
10 i = 0;
11 while(i < slip->more){
12 size = slip_unesc(slip->ibuf[i++], slip->ibuf,
13 &slip->pos, &slip->esc);
14 if(size){
15 memcpy(buf, slip->ibuf, size);
16 memmove(slip->ibuf, &slip->ibuf[i],
17 slip->more - i);
18 slip->more = slip->more - i;
19 return size;
22 slip->more = 0;
25 n = net_read(fd, &slip->ibuf[slip->pos],
26 sizeof(slip->ibuf) - slip->pos);
27 if(n <= 0)
28 return n;
30 start = slip->pos;
31 for(i = 0; i < n; i++){
32 size = slip_unesc(slip->ibuf[start + i], slip->ibuf,&slip->pos,
33 &slip->esc);
34 if(size){
35 memcpy(buf, slip->ibuf, size);
36 memmove(slip->ibuf, &slip->ibuf[start+i+1],
37 n - (i + 1));
38 slip->more = n - (i + 1);
39 return size;
42 return 0;
45 int slip_proto_write(int fd, void *buf, int len, struct slip_proto *slip)
47 int actual, n;
49 actual = slip_esc(buf, slip->obuf, len);
50 n = net_write(fd, slip->obuf, actual);
51 if(n < 0)
52 return n;
53 else return len;