system, fileExist函数包装
#include "stdio.h"
#include <string>
#include<sys/types.h>
#include<fcntl.h>
#include <sys/stat.h>
using std::string; #include <iostream>
#include <map>
#include <string>
#include <sys/time.h>
#include <errno.h>
#include <iconv.h>
#include <stdlib.h>
#include <stdarg.h>
#include <sys/select.h>
#include <sys/time.h> string System(string &strrtn, const char *cpFormat, ...)
{
if (cpFormat == NULL)
return strrtn; char cpcmd[];
char cpline[];
FILE *fp;
va_list val; va_start(val, cpFormat);
vsnprintf(cpcmd, sizeof(cpcmd)-, cpFormat, val);
va_end(val); fp = popen(cpcmd, "r"); while (fgets(cpline, , fp) != NULL)
{
strrtn += cpline;
}
pclose(fp);
return strrtn;
} bool fileExist(const char *cpfile)
{
if (NULL == cpfile)
return false; struct stat st;
if (stat(cpfile, &st) == -)
return false; return (!( st.st_mode & S_IFDIR));
} int fileSize(const char *cpfilename)
{
struct stat st; // 须处理符号链接文件
if (stat(cpfilename, &st) != )
return -;
return st.st_size;
} int main(int argc, char*argv[])
{
string arg = argv[];
string fileName = arg;
string path = "";
string file = path + fileName; int size = fileSize(file.c_str()); if(!fileExist(file.c_str()))
{
printf("The file not exists! name: %s size: %d \n", file.c_str(), size);
}
else
{
printf("file exists! name: %s size: %d\n", file.c_str(), size);
} int fd = open(file.c_str(), O_RDONLY);
if(fd == -)
{
printf("can not open file: %d\n", fd);
}
else
{
printf("open file %d\n", fd);
} string calsize = "ls -l " + fileName + " | awk '{print $5}'";
string val;
val = System(val, calsize.c_str());
if(val.size() != )
{
printf("size is %d\n", atoi(val.c_str()));
}
else
{
printf("error\n");
}
return ;
}
system, fileExist函数包装的更多相关文章
- 谈一下关于C++函数包装问题
在C++中,我们经常遇到在某个特定的时刻,需要将函数进行包装调用,尤其是当我们需要将不同签名的函数放到同一个集合时,由于函数签名不一致导致我们不能直接将各式各样的函数指针放到诸如list这样的集合中, ...
- PHP后门的eval类和system类 函数到底有哪些区别
一. 一直以来对PHP的eval这一类函数和system这一类存在疑惑的地方,今天彻底研究了一下,写查PHP一句话的时候可以更有把握一些.其实都是一些满基础的知识,大佬别喷.干安全的基础很重要. 二. ...
- Linux网络IO函数以及TCP连接函数包装
标准I/O VS 网络IO 标准I/O又称为标准I/O流,从某种意义上讲是全双工的,因为程序能够在同一个流上执行输入和输出. Unix/Linux对网络的抽象是一种称为套接字的文件类型.和任何Unix ...
- 118.类包装器与lambda函数包装器(伪函数实现)
#include <iostream> #include <list> using namespace std; //函数包装器,左边参数右边函数 template<cl ...
- Dalvik模式下System.loadLibrary函数的执行流程分析
本文博客地址:http://blog.csdn.net/qq1084283172/article/details/78212010 Android逆向分析的过程中免不了碰到Android so被加固的 ...
- [System.OutOfMemoryException] {函数求值已禁用,因为出现内存不足异常。
[System.OutOfMemoryException] {函数求值已禁用,因为出现内存不足异常. StringBuilder 赋值的时候超过内存的大小,要即时去清空文本的值. 也可能是DataSe ...
- 【ASP.NET】 中 system.math 函数使用
1 /* 字段 */ 2 Math.E; //2.71828182845905 3 Math.PI; //3.14159265358979 4 5 /* 静态方法 */ 6 Math.Abs; //绝 ...
- System.Length 函数
function _PCharLen(P: _PAnsiChr): Longint;{$IFNDEF LEGACY_PCHARLEN}begin Result := 0; if P <> ...
- PHP 数据库连接工具类(MySQLI函数包装)
====================mysql===================== <?php class mysql { private $mysqli; private $resu ...
随机推荐
- vuejs 子组件传递父组件的第一种方式
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- C#中的协变OUT和逆变
泛型接口和泛型委托中经常使用可变性 in 逆变,out 协变 从 list<string>转到list<object> 称为协变 (string 从object 派生,那么 ...
- driver_register()函数解析
driver_register()函数解析 /** * driver_register - register driver with bus * @drv: driver to register * ...
- centos 单独安装nginx
安装包下载网址: http://nginx.org/en/download.html 进入Linux文件夹执行 wget http://nginx.org/download/nginx-1.8.0.t ...
- php 常用代码段
1.写文件 $fp = fopen("jsapi_ticket.json", "w+"); fwrite($fp, $str); fclose($fp); 2. ...
- IE6下完美兼容css3圆角和阴影属性的htc插件PIE.htc
1.(推荐:)css插件PIE.htc,这个才是真正完美兼容css3的圆角和阴影属性在IE6环境下使用的效果,但要注意的是:下面的代码必须写在html文件的head标签内,否则无效(不能从外部引用下面 ...
- WPF DataPager控件
最近在项目中遇到远程加载数据的问题,由于服务器采用分页方式返回数据,因此客户端也相应的制作了一个分页控件.代码相对简单,算做入门级的源码. 效果如图: 初步分析,分页功能只需要3个核心变量:PageI ...
- WPF学习之数据绑定
WPF中的数据绑定提供了很强大的功能.与普通的WinForm程序相比,其绑定功能为我们提供了很多便利,例如Binding对象的自动通知/刷新,Converter,Validation Rules,Tw ...
- winform的Textbox设置只读之后ForeColor无效的解决方法
winform的Textbox设置只读之后ForeColor无效. 通过以下方法就可以解决: 设置为只读之后,把BackColor改一下,然后运行一下窗口,再设置ForeColor就没问题了. tbT ...
- Js中Array数组学习总结
第一次写博客...有点方... 小白一枚(是真的小白),自学前端,下面来说说我在学习过程中总结的一些数组操作,如果说哪有错误,请各位大神多多指出,小的虚心接受. 引用类型分为Object类型(所谓的对 ...