dlog.cpp
来自「dget是一个基于Linux平台的多线程下载工具, 采用C++开发。主要支持FT」· C++ 代码 · 共 113 行
CPP
113 行
/* * by balancesli * balancesli@gmail.com * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */#include <stdio.h>#include <stdlib.h>#include <sys/param.h>#include <sys/stat.h>#include <errno.h>#include <string.h>#include <unistd.h>#include "dLog.h"#include "dget.h"#include "Utils.h"TLog :: TLog(char * s) : ConnCnt(4) { int Length = strlen(s) + 1; FileName = new char[Length]; strcpy(FileName, s);}TLog :: ~TLog(){ delete []FileName;}int TLog :: CreateLogFile(int n){ char buffer[128]; FILE *fp = NULL; sprintf(buffer, "%s%s.log", FileName, DEFAULT_FILE_EXT); if (!(fp = fopen(buffer, "wb"))) return -1; fwrite(&n, sizeof(n), 1, fp); fclose(fp); return 0;}bool TLog :: IsLogFileExist(void){ char buffer[128]; int ret; struct stat stbuf; sprintf(buffer, "%s%s.log", FileName, DEFAULT_FILE_EXT); ret = stat(buffer, &stbuf); if (ret == -1) return false; else return true;}int TLog :: DeleteLogFile(void){ char buffer[MAXPATHLEN]; int ret; sprintf(buffer, "%s%s.log", FileName, DEFAULT_FILE_EXT); ret = unlink(buffer); if (ret == -1) { if (errno == ENOENT) { return 0; } return -1; } return 0;}int TLog :: ReadLogFile(void){ char buffer[MAXPATHLEN]; FILE *fp = NULL; sprintf(buffer, "%s%s.log", FileName, DEFAULT_FILE_EXT); if (!(fp = fopen(buffer, "rb"))) return -1; if (fread(&ConnCnt, sizeof(int), 1, fp) != 1) { fclose(fp); return -1; } fclose(fp); return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?