This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: microblaze getchar() not functioning properly


Hi Andrew,

   I have missed placing the braces, thank you for reviewing and
correcting the code.

Thanks,
Nagaraju

On Wed, Aug 24, 2011 at 4:21 PM, Andrew Bennett
<Andrew.Bennett@imgtec.com> wrote:
>> Can you please let me know whether the above change were correct..
>
> I am assuming here that the code you pasted is correct.
>
> If so, the read_macro function will only read and return one byte due to
> the if statement being incorrectly bracketed. ?If the function is called
> with a buffer of more than 1 byte (ie. nbytes > 1) the buffer will only
> contain 1 character rather than the number of characters given in
> nbytes.
>
> I think the code should read:
>
> int read_micro (int fd, char* buf, int nbytes)
> {
> ?int i = 0;
>
> ?for (i = 0; i < nbytes; i++) {
> ? ?*(buf + i) = inbyte();
> ? ?if ((*(buf + i) == '\n' || *(buf + i) == '\r'))
> ? ?{
> ? ? ?i++;
> ? ? ?break;
> ? ?}
> ?}
>
> ?return i;
> }
>
> Regards,
>
>
> Andrew
>
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]