Garbage Value in File after write

前端 未结 1 685
攒了一身酷
攒了一身酷 2021-01-25 23:12

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         


        
相关标签:
1条回答
  • 2021-01-25 23:47

    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:

    write_ret = write(log_fd, error_msg, strlen(error_msg));
    
    0 讨论(0)
提交回复
热议问题