| 407 | | int fd = open(m_szFileName, O_WRONLY | O_CREAT | O_TRUNC, 00600); |
| | 403 | |
| | 404 | // Make sure history dir exists before trying to write a file in it |
| | 405 | char historydir[MAX_FILENAME_LEN]; |
| | 406 | snprintf(historydir, sizeof(historydir) - 1, "%s/%s", BASE_DIR, HISTORY_DIR); |
| | 407 | if (mkdir(historydir, 0700) == -1 && errno != EEXIST) |
| | 408 | { |
| | 409 | fprintf(stderr, "Couldn't mkdir %s: %s\n", historydir, strerror(errno)); |
| | 410 | return; |
| | 411 | } |
| | 412 | |
| | 413 | int fd = open(m_szFileName, O_WRONLY | O_CREAT | (append ? O_APPEND : O_TRUNC), 00600); |
| 431 | | |
| 432 | | |
| 433 | | //---Append-------------------------------------------------------------------- |
| 434 | | /*! \brief Appends a message to the history |
| 435 | | * |
| 436 | | * Appends message _sz to the history. If the history file does not exist it |
| 437 | | * will be created. |
| 438 | | */ |
| 439 | | void CUserHistory::Append(const char *_sz) |
| 440 | | { |
| 441 | | if (m_szFileName == NULL || _sz == NULL) return; |
| 442 | | int fd = open(m_szFileName, O_WRONLY | O_CREAT | O_APPEND, 00600); |
| 443 | | if (fd == -1) |
| 444 | | { |
| 445 | | gLog.Error("%sUnable to open history file (%s):\n%s%s.\n", L_ERRORxSTR, |
| 446 | | m_szFileName, L_BLANKxSTR, strerror(errno)); |
| 447 | | return; |
| 448 | | } |
| 449 | | write(fd, _sz, strlen(_sz)); |
| 450 | | write(fd, "\n", 1); |
| 451 | | close(fd); |
| 452 | | } |
| 453 | | |
| 454 | | |