#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. iOS 专题 之 界面开发 之 控件

    iOS 之 UIViewController iOS 之 Navagation Button iOS 之 UIButton iOS 之 UITextField iOS 之 UIStackView iO ...

  2. sqlite3命令行

    1.查看版本信息 sqlite3 -verion 2.创建/打开数据库 sqlite3 数据库名 例:sqlite3 test.db 如果test.db不存在就创建 如果存在,则打开3.退出 .q/. ...

  3. 阿里CEO张勇公开信:把眼光从股市回到客户身上

     8月25日消息,面对全球资本市场的剧烈波动,阿里巴巴集团CEO张勇今日发表致员工信,倡议全体阿里员工把眼光从股市回到客户身上,脚踏实地的服务帮助客户,为客户创造价值,继而为股东和自己创造价值.  张 ...

  4. java_web学习(12)JDBC

    数据持久化       持久化(persistence):把数据保存到可掉电式存储设备中以供之后使用.大多数情况下,特别是企业级应用,数据持久化意味着将内存中的数据保存到硬盘上加以”固化”,而持久化的 ...

  5. JavaScript 模块化及 SeaJs 源码分析

    网页的结构越来越复杂,简直可以看做一个简单APP,如果还像以前那样把所有的代码都放到一个文件里面会有一些问题: 全局变量互相影响 JavaScript文件变大,影响加载速度 结构混乱.很难维护 和后端 ...

  6. Apache自带压力测试工具ab用法简介

    ab命令原理 ab命令会创建很多的并发访问线程,模拟多个访问者同时对某一URL进行访问.它的测试目标是基于URL的,因此,既可以用来测试Apache的负载压力,也可以测试nginx.lighthttp ...

  7. MariaDB多源复制环境搭建(多主一丛)

    环境: 192.168.1.248 HE1 主库 192.168.1.249 HE2 主库 192.168.1.250 HE3 从库 主库授权备份账户 mysql>  grant SELECT, ...

  8. JavaScript 44 Puzzlers

    http://mp.weixin.qq.com/s?__biz=MzAxODE2MjM1MA==&mid=2651550987&idx=1&sn=f7a84b59de14d0b ...

  9. jQuery的$(window).load与、(document).ready和window.onload的关系

    jQuery的$(window).load与.(document).ready和window.onload的关系 $(function() { console.log('document.ready ...

  10. 深入理解Java Proxy

    深入理解Java Proxy: http://blog.csdn.net/rokii/article/details/4046098 整理之后的代码: package com.stono.reftes ...