#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函数包装的更多相关文章

  1. 谈一下关于C++函数包装问题

    在C++中,我们经常遇到在某个特定的时刻,需要将函数进行包装调用,尤其是当我们需要将不同签名的函数放到同一个集合时,由于函数签名不一致导致我们不能直接将各式各样的函数指针放到诸如list这样的集合中, ...

  2. PHP后门的eval类和system类 函数到底有哪些区别

    一. 一直以来对PHP的eval这一类函数和system这一类存在疑惑的地方,今天彻底研究了一下,写查PHP一句话的时候可以更有把握一些.其实都是一些满基础的知识,大佬别喷.干安全的基础很重要. 二. ...

  3. Linux网络IO函数以及TCP连接函数包装

    标准I/O VS 网络IO 标准I/O又称为标准I/O流,从某种意义上讲是全双工的,因为程序能够在同一个流上执行输入和输出. Unix/Linux对网络的抽象是一种称为套接字的文件类型.和任何Unix ...

  4. 118.类包装器与lambda函数包装器(伪函数实现)

    #include <iostream> #include <list> using namespace std; //函数包装器,左边参数右边函数 template<cl ...

  5. Dalvik模式下System.loadLibrary函数的执行流程分析

    本文博客地址:http://blog.csdn.net/qq1084283172/article/details/78212010 Android逆向分析的过程中免不了碰到Android so被加固的 ...

  6. [System.OutOfMemoryException] {函数求值已禁用,因为出现内存不足异常。

    [System.OutOfMemoryException] {函数求值已禁用,因为出现内存不足异常. StringBuilder 赋值的时候超过内存的大小,要即时去清空文本的值. 也可能是DataSe ...

  7. 【ASP.NET】 中 system.math 函数使用

    1 /* 字段 */ 2 Math.E; //2.71828182845905 3 Math.PI; //3.14159265358979 4 5 /* 静态方法 */ 6 Math.Abs; //绝 ...

  8. System.Length 函数

    function _PCharLen(P: _PAnsiChr): Longint;{$IFNDEF LEGACY_PCHARLEN}begin  Result := 0;  if P <> ...

  9. PHP 数据库连接工具类(MySQLI函数包装)

    ====================mysql===================== <?php class mysql { private $mysqli; private $resu ...

随机推荐

  1. Python3基础 filter与lambda表达式配合 筛选出1-100之间的奇数

    镇场诗: 诚听如来语,顿舍世间名与利.愿做地藏徒,广演是经阎浮提. 愿尽吾所学,成就一良心博客.愿诸后来人,重现智慧清净体.-------------------------------------- ...

  2. PHP生成带有干扰线的验证码,干扰点、字符倾斜

    PHP生成验证码的类代码,本验证码类支持生成干扰点.干扰线等干扰像素,还可以使字符倾斜.在类中你可以定义验证码宽度.高度.长度.倾斜角度等参数,后附有用法: <?php class class_ ...

  3. 真机调试iwatch

    http://blog.csdn.net/chenyufeng1991/article/details/48976639 错误:no symbols for paired Apple Watch 错误 ...

  4. ios 清除列表选中状态

    [tableView deselectRowAtIndexPath:indexPath animated:YES];

  5. 解压文件--linux

    linux下不同的文件格式用不同的命令解压. 对于tar.gz文件,用以下命令. .tar.gz 和 .tgz解压:tar zxvf FileName.tar.gz压缩:tar zcvf FileNa ...

  6. 互信息应用于SNP特征选择的局限

    互信息已广泛应用于特征选择问题,但应用在 SNP 选择上还存在着一些局限.第一,互信息只能衡量一个 SNP 组合与表型的相关性, 无法衡量多个 SNP 与表型的相关性.第二, 利用互信息排序 SNP ...

  7. 用JS的数组缓存一些东西

    var cache_index = new Array(); //首页的ajax缓存 //ajax 推荐的游戏和软件 function change_tuijian(sid,div_class){ i ...

  8. Flex移动应用程序开发的技巧和窍门(四)

    范例文件 flex-mobile-dev-tips-tricks-pt4.zip 这是本系列文章的第四部分,该系列文章涵盖Flex移动开发的秘诀与窍门. 第一部分关注切换视图以及切换执行应用时的数据处 ...

  9. ADO.NET 防止SQL注入

    规避SQL注入 如果不规避,在黑窗口里面输入内容时利用拼接语句可以对数据进行攻击 如:输入Code值 p001' union select * from Info where '1'='1 //这样可 ...

  10. Ceph QoS 初探(下)

    作者:吴香伟 发表于 2017/01/24 版权声明:可以任意转载,转载时务必以超链接形式标明文章原始出处和作者信息以及版权声明 存储QoS是个可以做很大也可以做很小的特性.SolidFire认为将Q ...