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 ...
随机推荐
- 安卓Visibility属性
可见(visible) XML文件:android:visibility="visible" Java代码:view.setVisibility(View.VISIBLE); 不可 ...
- 关于String的相关常见方法
package Stirng类; /** * String 常见的相关方法摘要 * @author Administrator * */ public class DemoStringMethod { ...
- 基于Python,scrapy,redis的分布式爬虫实现框架
原文 http://www.xgezhang.com/python_scrapy_redis_crawler.html 爬虫技术,无论是在学术领域,还是在工程领域,都扮演者非常重要的角色.相比于其他 ...
- NPM 简单实用说明
https://nodejs.org/en/download/ 下载并按照,直接下一步就可以,最后会在C:\Program Files 新建一个nodejs文件夹,里面有一个node.exe.双击就启 ...
- fastreport.net cdoe 自己的代码
//初始 Report report1 = new Report(); report1.Clear(); string Re ...
- 10 Python+Selenium键盘事件
[环境信息] python3.6+selenium3.0.2+Firefox50.0+win7 [操作方法] 导入方法:from selenium.webdriver.common.keys impo ...
- Intellij idea 15配置tomcat,maven
刚导了个项目进去,想把项目运行起开,怎么也找不到tomcat... ctrl + alt +s,打开设置窗,搜索 Application Server Tomcat: 点中间绿色的“+”号,添加选择t ...
- 记录一次事故——idea,sbt,scala
没事千万不要点idea的update啊,就算它自己弹出来的也不要管哦. 我们自己的IDE在使用过程中总会有各种settting的配置,更新之后这些都没有了,而且自己本地安装的插件也就都没有了,所以更新 ...
- 如何在windows下载和安装Apache
进入apache服务器官网http://httpd.apache.org/,这里我们以下载稳定版的httpd 2.4.25为例,点击"Files for Microsoft Windows& ...
- 关于android:id="@+id/xx"的理解
之前学习android的时候,对android:id="@+id/xx"总感觉混淆,不理解,刚看了一篇文章.现在貌似是恍然大悟.故做了一下笔记,希望帮助有共同问题的人... and ...