📄 input_check.c
字号:
#include <stdio.h>#include <sys/types.h>#include <regex.h>#include <sys/stat.h>#include <unistd.h>#include <string.h>#include "input_check.h"#define FNAMELEN 100int server_checkfile(char *filename){ if(access(filename,R_OK)<0){// printf("server no such file, please check it\n"); return 1; } return 0;}int server_checkDIR(char *filename){ char *p,*q; char dir[FNAMELEN]={0}; struct stat buf; for(p=filename; *p!='\0'; p++){ if(*p=='/') q=p; } strncpy(dir, filename, q-filename); stat(dir, &buf); if(!S_ISDIR(buf.st_mode)){// printf("server no such direct, please check it\n"); return 1; } return 0;}int client_checkfile(char *filename){ if(access(filename, R_OK)<0){ printf("Sorry, Client no such file, please check it!\n"); return 1; } return 0;}int client_checkDIR(char *directory){ struct stat buf; stat(directory, &buf); if(!S_ISDIR(buf.st_mode)){ printf("Sorry, Client no such directory, please check it!\n"); return 1; } return 0;}int checkIP(char *ip_addr){ char *pattern; int x, z, lno = 0, cflags = 1; regex_t reg; regmatch_t pm[10]; const size_t nmatch = 10; pattern="\\b(((2[0-4][0-9]|25[0-5]|[01]?[0-9][0-9]?)\\.){3}(2[0-4][0-9]|25[0-5]|[01]?[0-9][0-9]?))\\b"; z = regcomp(®, pattern, REG_EXTENDED); if (z != 0){ printf("regcomp error\n"); return 1; } z = regexec(®, ip_addr, nmatch, pm, 0); if(z!=0){ printf("Sorry, the IP address is not regular\n"); return 1; } regfree(®); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -