Commit ece92c25 authored by cdf009's avatar cdf009

wrapper

parent 2960be41
#include <fcntl.h> /* Obtain O_* constant definitions */
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/socket.h>
#include<stdlib.h>
#include<ctype.h>
#include<errno.h>
#include<stdio.h>
#include<string.h>
pid_t Fork(void){
pid_t check;
check = fork();
if (check == -1){
perror("ERROR: fork not used properly");
exit(-1);
}
return check;
}
int Read(int fd, void *buf, size_t count){ // reading error handling
int str1;
if((str1 = read(fd, buf, count)) == -1){
perror("ERROR: readin!!!");
exit(-1);
}
return str1;
}
int Write(int fd, const void *buf, size_t count){ //writing error handling
int str1;
if ((str1 = write(fd, buf, count)) == -1){
perror("ERROR: writin!!!");
exit(-1);
}
return str1;
}
int Pipe(int pipefd[2]){ //piping error handling
if (pipe(pipefd) == -1){
perror("ERROR: pipin!!!");
exit(-1);
}
return 0;
}
pid_t Wait(int *status){
if (wait(status) == -1){
perror("ERROR");
exit(-1);
}
return 0;
}
pid_t Waitpid(pid_t pid, int *status, int options){
if (waitpid(pid, status, options) == -1){
perror("ERROR");
exit(-1);
}
return 0;
}
int Open(const char *pathname, int flags){
if (open(pathname, flags) == -1){
perror("ERROR");
exit(-1);
}
return 0;
}
int Close(int fd){
if (close(fd) == -1){
perror("ERROR");
exit(-1);
}
return 0;
}
int Connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen){
if (connect(sockfd, addr, addrlen) == -1){
perror("ERROR");
exit(-1);
}
return 0;
}
int Bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen){
if (bind(sockfd, addr, addrlen) == -1){
perror("ERROR");
exit(-1);
}
return 0;
}
int Listen(int sockfd, int backlog){
if (listen(sockfd, backlog) == -1){
perror("ERROR");
exit(-1);
}
return 0;
}
int Accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen){
if (accept(sockfd, addr, addrlen) == -1){
perror("ERROR");
exit(-1);
}
return 0;
}
#ifndef WRAPPERS_H
#define WRAPPERS_H
#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <fcntl.h> /* Obtain O_* constant definitions */
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/socket.h>
pid_t fork(void);
int pipe(int pipefd[2]);
pid_t wait(int *status);
pid_t waitpid(pid_t pid, int *status, int options);
int open(const char *pathname, int flags);
int close(int fd);
int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
int listen(int sockfd, int backlog);
int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment