http server v0.1_http_webapp.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
/*----------------------------------------------------------------- functionname: file_exist
param: NA
return: NA
author: xxxx check if file is exist in webapp
history:
create by xxxx, 2014.1.08, add simple abilities
-------------------------------------------------------------*/
int file_exist(char* url)
{
int ret;
int len = ;
char* path= NULL; if(url == NULL)
return -; len = strlen(url);
if(len <= )
return -; path = (char*)malloc(len);
strncpy(path, url, len); printf("[%s]\n", path);
// remove blanks on head and tailof url
ret = access(path, R_OK);
if(ret == -)
perror("uri not exist"); free(path);
return ret; } long get_file_size(FILE* fs)
{
if(fs == NULL)
return -; fseek(fs, , SEEK_END);
return ftell(fs);
} char *itoa(int num, char *str, int radix)
{
//0的情况
if (num==)
{
str[]='';
str[]='\0';
return str;
} char string[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; char* ptr = str;
int i;
int j; while (num)
{
*ptr++ = string[num % radix];
num /= radix; if (num < radix)
{
*ptr++ = string[num];
*ptr = '\0';
break;
}
}
//两边对调
j = ptr - str - ; for (i = ; i < (ptr - str) / ; i++)
{
int temp = str[i];
str[i] = str[j];
str[j--] = temp;
} return str;
} int io_write(int fd, void *usrbuf, int n)
{
int nleft = n;
int nwritten;
char *bufp = usrbuf; while (nleft > ) {
if ((nwritten = write(fd, bufp, nleft)) <= ) {
if (errno == EINTR) /* interrupted by sig handler return */
nwritten = ; /* and call write() again */
else
return -; /* errorno set by write() */
}
nleft -= nwritten;
bufp += nwritten;
}
return n;
}
#ifndef __HTTP_WEBAPP_H
#define __HTTP_WEBAPP_H int file_exist(char* url);
long get_file_size(FILE* fs);
int io_write(int fd, void *usrbuf, int n);
char *itoa(int num, char *str, int radix); #endif
http server v0.1_http_webapp.c的更多相关文章
- http server v0.1_http_reponse.c
#include <string.h> #include <sys/stat.h> #include <sys/mman.h> #include <fcntl ...
- http server v0.1_http_server.c
/**************************************************************** filename: http_server.c author: xx ...
- http server v0.1_http_parse.c
#include <stdio.h> #include <string.h> #include <stdlib.h> #include "mime.h&q ...
- http server v0.1_mime.c
#include <string.h> #include "mime.h" static STR_MIME_MAP mime_map[]= { MIME_MAP(MIM ...
- 用FileZilla Server开FTP
FileZilla(教程)是经典的开源FTP解决方案,包括FileZilla客户端和FileZilla Server.其中,FileZilla Server的功能比起商业软件FTP Serv-U毫不逊 ...
- DNS隧道之DNS2TCP实现——dns2tcpc必须带server IP才可以,此外ssh可以穿过墙的,设置代理上网
我自己的命令: server端: dns2tcpd -F -d 1 -f ./dns2tcpd.conf 输出: 09:08:59 : Debug options.c:97 Add resource ...
- docker 下 安装rancher 笔记
sudo yum update 更新系统环境 curl -sSL https://get.docker.com/ | sh 安装最新docker版本 systemctl start docker.se ...
- 容器基础(七): 使用docker compose部署程序
配置 在上一节的基础上, 增加如下的docker-compose.yml文件, 然后用docker-compose up命令启动容器进行部署: version: " services: s ...
- 容器基础(八): 使用docker swarm部署程序
环境 基于上一节的env/server:v0.1, env/worker:v0.1镜像, 在基于debian8.2的两台机器上测试部署docker swarm. docker service部署 ➜ ...
随机推荐
- Android 完美退出 App (Exit)
最近两天为了解决Android上面退出程序问题折腾了半死,在google & baidu 上面找了很久.很久出来的完全千篇一律,说的方法有三,但是经过我试验后全部不行. 三个方法分别是: ki ...
- mysql 插入语句
mysql 插入语句 什么时候用单引号,什么时候不用? 1.先创建一个表 create table user(username varchar(255),age int,marry boolean,b ...
- adb取出安装在手机中的apk
Android实战技巧之十八:adb取出安装在手机中的apk 场景: 朋友看见你Android手机中的游戏或应用很好玩,也想装一个此程序,但限于网络条件不能从网上下载.那么最简单的办法就是直接从你手机 ...
- Chapter 3. Installing Gradle 安装gradle
3.1. Prerequisites Gradle requires a Java JDK or JRE to be installed, version 6 or higher (to check, ...
- 所有Mac用户都需要知道的9个实用终端命令行<转>
转自 http://www.macx.cn/thread-2075903-1-1.html 通常情况下,只有高端用户才会经常用到终端应用.这并不意味着命令行非常难学,有的时候命令行可以轻松.快速的解决 ...
- hp惠普服务器监控硬盘
惠普 hpssacli 工具使用 查看raid卡信息(包括控制器状态.Cache状态.电池状态) # hpssacli ctrl all show status 查看raid详细信息 # hpssac ...
- AppCan中两种获取信息的方法
<div id="newsInfo">正在加载...</div> 1.JSON格式: [{'R': '1','NOTI_ID': '9','NOTI_TIT ...
- 在eclipse中部署发布web项目 和 更改eclipseweb项目发布的路径
我的工作空间:d:workspaceweb项目名称:xxx在eclipse配置完tomcat后,发布到的路径是 d:\workspace\.metadata\.plugins\org.eclipse. ...
- python小爬虫【1】
爬取百度贴吧的图片 分析贴吧源代码,图片所在位置是:<img class="BDE_Image" src=“........jpg” pic_ext..... 所以正则匹配是 ...
- 深入理解shared pool共享池之library cache系列一
结论 1,oradebug dump library_cache不同级别dump的library cache内容及粒度会有所区别,具体见测试开始部分2,本文测示基于oradebug dump libr ...