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

  1. http server v0.1_http_reponse.c

    #include <string.h> #include <sys/stat.h> #include <sys/mman.h> #include <fcntl ...

  2. http server v0.1_http_server.c

    /**************************************************************** filename: http_server.c author: xx ...

  3. http server v0.1_http_parse.c

    #include <stdio.h> #include <string.h> #include <stdlib.h> #include "mime.h&q ...

  4. http server v0.1_mime.c

    #include <string.h> #include "mime.h" static STR_MIME_MAP mime_map[]= { MIME_MAP(MIM ...

  5. 用FileZilla Server开FTP

    FileZilla(教程)是经典的开源FTP解决方案,包括FileZilla客户端和FileZilla Server.其中,FileZilla Server的功能比起商业软件FTP Serv-U毫不逊 ...

  6. DNS隧道之DNS2TCP实现——dns2tcpc必须带server IP才可以,此外ssh可以穿过墙的,设置代理上网

    我自己的命令: server端: dns2tcpd -F -d 1 -f ./dns2tcpd.conf 输出: 09:08:59 : Debug options.c:97 Add resource ...

  7. docker 下 安装rancher 笔记

    sudo yum update 更新系统环境 curl -sSL https://get.docker.com/ | sh 安装最新docker版本 systemctl start docker.se ...

  8. 容器基础(七): 使用docker compose部署程序

    配置 在上一节的基础上,  增加如下的docker-compose.yml文件, 然后用docker-compose up命令启动容器进行部署: version: " services: s ...

  9. 容器基础(八): 使用docker swarm部署程序

    环境 基于上一节的env/server:v0.1, env/worker:v0.1镜像, 在基于debian8.2的两台机器上测试部署docker swarm. docker service部署 ➜ ...

随机推荐

  1. 包的定义和导入-----package

    1.包的定义 其中:   . 表示当前路径 2.包的导入 一个类需要被外包访问的话,需要定义为public class. package org.lxh.demo08.a ; public class ...

  2. Android 解决双卡双待手机解析短信异常

    开发中,难免会遇到各种各样的适配问题,尤其是经过深度修改定制过的系统,有的无论是软硬件上都有很大的区别,这里不得不提到一种奇葩的机型,没错,那就是双卡双待的手机(比如XT800, A60, S8600 ...

  3. List<T>实体去重分组:

    实体去重分组: //实体类 public class Province { public string id { get; set; } public string name { get; set; ...

  4. 【PHP分享】Windows tail工具分享

    作者:zhanhailiang 日期:2014-09-28 在Linux下能够使用tail -f工具实时查看输出的日志.近期切换到本地Windows开发环境,顿时有点不爽.百度了下,最终找到tail的 ...

  5. 使用QEMU调试Linux内核代码

    http://blog.chinaunix.net/uid-20729583-id-1884617.html http://www.linuxidc.com/Linux/2014-08/105510. ...

  6. hadoop错误org.apache.hadoop.mapred.MapTask$NewOutputCollector@17bda0f2

    错误: org.apache.hadoop.mapred.MapTask$NewOutputCollector@17bda0f2 java.io.IOException: Spill failed 错 ...

  7. android之AlertDialog 点击其他区域自动消失

    遇到一个问题记录下来,在开发中使用了AlertDialog,想点击屏幕其他区域的时候让这个dialog消失,一开始不做任何设置,在小米手机可以正常显示,但是在三星中却有问题,后来发现少了一个属性: V ...

  8. 必应代码搜索 Bing Code Search 安装

    微软这几天推出基于bing搜索引擎的  Bing Code Search ,可直接在浏览器上搜索和运行代码.目前中文版必应无法使用本功能,有需要的同学可以转到英文版进行搜索: 英文版必应:  http ...

  9. Js判断对象是否为空,Js判断字符串是否为空

    Js判断对象是否为空,Js判断字符串是否为空,JS检查字符串是否为空字符串 >>>>>>>>>>>>>>>&g ...

  10. java.io.EOFException错误

    TOmcat启动后报:IOException while loading persisted sessions: Java.io.EOFException错误 - IOException while ...