Changeset 6177
- Timestamp:
- 05/01/08 01:43:10 (5 months ago)
- Location:
- trunk/licq
- Files:
-
- 2 modified
-
include/licq_history.h (modified) (1 diff)
-
src/history.cpp (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/licq/include/licq_history.h
r4526 r6177 16 16 void SetFile(const char *, unsigned long); 17 17 void SetFile(const char *, const char *, unsigned long); 18 void Append(const char *);18 void Append(const char* buf) { Write(buf, true); } 19 19 bool Load(HistoryList &); 20 20 static void Clear(HistoryList &); 21 void Save(const char *);21 void Save(const char* buf) { Write(buf, false); } 22 22 const char *Description() { return m_szDescription; } 23 23 const char *FileName() { return m_szFileName; } 24 25 /** 26 * Write to the history file, creating it if necessary 27 * 28 * @param buf String with data to write 29 * @param append True to append data or false to overwrite file 30 */ 31 void Write(const char* buf, bool append); 32 24 33 protected: 25 34 char *m_szFileName; -
trunk/licq/src/history.cpp
r4526 r6177 11 11 #endif 12 12 13 #include <cstdio> 13 14 #include <string.h> 14 15 #include <unistd.h> … … 397 398 } 398 399 399 //---Save---------------------------------------------------------------------- 400 /*! \brief Writes history to disk 401 * 402 * Writes history to disk. If file does not exists it is created. 403 */ 404 void CUserHistory::Save(const char *buf) 400 void CUserHistory::Write(const char* buf, bool append) 405 401 { 406 402 if (m_szFileName == NULL || buf == NULL) return; 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); 408 414 if (fd == -1) 409 415 { … … 413 419 } 414 420 write(fd, buf, strlen(buf)); 421 if (append) 422 write(fd, "\n", 1); 415 423 close(fd); 416 424 } … … 429 437 hist.erase(hist.begin(), hist.end()); 430 438 } 431 432 433 //---Append--------------------------------------------------------------------434 /*! \brief Appends a message to the history435 *436 * Appends message _sz to the history. If the history file does not exist it437 * 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
