mirror of https://github.com/zrafa/xinu-avr.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
955 B
39 lines
955 B
/* lflread.c - lflread */ |
|
|
|
#include <xinu.h> |
|
|
|
/*------------------------------------------------------------------------ |
|
* lflread - Read from a previously opened local file |
|
*------------------------------------------------------------------------ |
|
*/ |
|
devcall lflread ( |
|
struct dentry *devptr, /* Entry in device switch table */ |
|
char *buff, /* Buffer to hold bytes */ |
|
int32 count /* Max bytes to read */ |
|
) |
|
{ |
|
uint32 numread; /* Number of bytes read */ |
|
int32 nxtbyte; /* Character or SYSERR/EOF */ |
|
|
|
if (count < 0) { |
|
return SYSERR; |
|
} |
|
|
|
/* Iterate and use lflgetc to read individual bytes */ |
|
|
|
for (numread=0 ; numread < count ; numread++) { |
|
nxtbyte = lflgetc(devptr); |
|
if (nxtbyte == SYSERR) { |
|
return SYSERR; |
|
} else if (nxtbyte == EOF) { /* EOF before finished */ |
|
if (numread == 0) { |
|
return EOF; |
|
} else { |
|
return numread; |
|
} |
|
} else { |
|
*buff++ = (char) (0xff & nxtbyte); |
|
} |
|
} |
|
return numread; |
|
}
|
|
|