/* * Print a formatted message to stderr, no colour is added. * Interesting - this function implicitly clears 'errno' */ void error_message( const char *fmt, ...) { va_list ap; va_start(ap, fmt); errno = 0; clear_message(); vsnprintf(mesg, sizeof(mesg), fmt, ap); my_fputs(mesg, stderr); /* don't use my_fprintf() here due to %format chars */ my_fflush(stderr); if (cmd_line) { my_fputc('\n', stderr); fflush(stderr); } else { stow_cursor(); (void) sleep(2); clear_message(); } va_end(ap); }
/*pre: an open file * post: integer is written to file */ int my_fput(int i, t_my_file *fp){ if(fp == NULL){ return EOF; } fp -> buff = (char*)&i; fp -> size = sizeof(int); if(my_fflush(fp) == 0){ return i; } else{ return EOF; } }
/*pre: an open file * post: the string s is written to file */ int my_fputs(char *s, t_my_file *fp){ char c; int i = 0; if(fp == NULL){ return EOF; } fp -> buff = s; c = s[i]; while(c != '\0'){ i++; c = s[i]; } fp -> size = i; if(my_fflush(fp) == 0){ return i; } else{ return EOF; } }
void terminate() { my_fflush(); }