Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* write_terminal(int32_tfd, const void*buf, int32_t nbytes)
- * DESCRIPTION: Should output a string to the terminal
- * INPUTS: file descriptor, buffer, and number of bytes read from buffer
- * OUTPUTS: Number of bytes written or -1 on fail
- */
- int32_t write_terminal(int32_t fd, const void * buf, int32_t nbytes){
- int32_t written=0; int32_t i=0;
- //create temp buffer of size of 1 byte
- uint8_t *temp_buf=(uint8_t *)buf;
- int count;
- // check if we previously have had 19 bytes (Starting 391 SHell\n)
- // also check if we have printed 1 instance of 391OS>
- if(prev_nbytes==LEN_PROMPT && prev_buf[0]=='S' && prev_buf[1]=='t' && _391OS_count==1){
- _391OS_count=0; // reset the flags
- return 0;
- }
- else{
- _391OS_count=1; // reset the flags
- }
- // if buff is NULL or nothing to be copied or less than 0 is requested copy, return
- if(buf==NULL || nbytes<0){
- return -1;
- }
- //cli();
- for(i=0; i<nbytes; i++){
- //print each character starting from index 0 to nbytes
- putc(temp_buf[i]);
- position(0,0,1);
- written++;
- }
- //sti();
- if(nbytes==written){
- // make sure to copy the right number of bytes to the prev_buf for checking
- // and not to overflow it
- if(nbytes<LEN_PROMPT){
- count=nbytes;
- }
- else{
- count=LEN_PROMPT;
- }
- // update the prev_buf to contain whatever was last entered
- for(i=0; i<count; i++){
- prev_buf[i]=temp_buf[i];
- }
- prev_nbytes=nbytes; // update prev_nbytes
- return nbytes;
- }
- else{
- prev_nbytes=-1;
- return -1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement