I am making a log function which stores in a file.
int log_func(char* msg) { int log_fd=0; ssize_t write_ret=0; int close_logfile_ret=0; time_t r
You write the whole error_msg array, even the contents after the string terminator. Instead you should use strlen to get the length of the string in the array, and only write that:
error_msg
strlen
write_ret = write(log_fd, error_msg, strlen(error_msg));