{
int tap_addr[4];
- if(gate_addr == NULL) return(0);
+ if(gate_addr == NULL)
+ return 0;
if(sscanf(gate_addr, "%d.%d.%d.%d", &tap_addr[0],
&tap_addr[1], &tap_addr[2], &tap_addr[3]) != 4){
printk("Invalid tap IP address - '%s'\n", gate_addr);
- return(-EINVAL);
+ return -EINVAL;
}
- return(0);
+ return 0;
}
void tap_check_ips(char *gate_addr, unsigned char *eth_addr)
n = os_read_file(fd, buf, len);
if(n == -EAGAIN)
- return(0);
+ return 0;
else if(n == 0)
- return(-ENOTCONN);
- return(n);
+ return -ENOTCONN;
+ return n;
}
int net_recvfrom(int fd, void *buf, int len)
(errno == EINTR)) ;
if(n < 0){
- if(errno == EAGAIN) return(0);
- return(-errno);
+ if(errno == EAGAIN)
+ return 0;
+ return -errno;
}
- else if(n == 0) return(-ENOTCONN);
- return(n);
+ else if(n == 0)
+ return -ENOTCONN;
+ return n;
}
int net_write(int fd, void *buf, int len)
n = os_write_file(fd, buf, len);
if(n == -EAGAIN)
- return(0);
+ return 0;
else if(n == 0)
- return(-ENOTCONN);
- return(n);
+ return -ENOTCONN;
+ return n;
}
int net_send(int fd, void *buf, int len)
while(((n = send(fd, buf, len, 0)) < 0) && (errno == EINTR)) ;
if(n < 0){
- if(errno == EAGAIN) return(0);
- return(-errno);
+ if(errno == EAGAIN)
+ return 0;
+ return -errno;
}
- else if(n == 0) return(-ENOTCONN);
- return(n);
+ else if(n == 0)
+ return -ENOTCONN;
+ return n;
}
int net_sendto(int fd, void *buf, int len, void *to, int sock_len)
while(((n = sendto(fd, buf, len, 0, (struct sockaddr *) to,
sock_len)) < 0) && (errno == EINTR)) ;
if(n < 0){
- if(errno == EAGAIN) return(0);
- return(-errno);
+ if(errno == EAGAIN)
+ return 0;
+ return -errno;
}
- else if(n == 0) return(-ENOTCONN);
- return(n);
+ else if(n == 0)
+ return -ENOTCONN;
+ return n;
}
struct change_pre_exec_data {
err = os_pipe(fds, 1, 0);
if(err < 0){
printk("change_tramp - pipe failed, err = %d\n", -err);
- return(err);
+ return err;
}
pe_data.close_me = fds[0];
pe_data.stdout = fds[1];
if (pid > 0)
CATCH_EINTR(err = waitpid(pid, NULL, 0));
- return(pid);
+ return pid;
}
static void change(char *dev, char *what, unsigned char *addr,
va_start(ap, str);
while((arg = va_arg(ap, char **)) != NULL){
if(*str == '\0')
- return(NULL);
+ return NULL;
end = strchr(str, ',');
if(end != str)
*arg = str;
if(end == NULL)
- return(NULL);
+ return NULL;
*end++ = '\0';
str = end;
}
va_end(ap);
- return(str);
+ return str;
}
-
-/*
- * Overrides for Emacs so that we follow Linus's tabbing style.
- * Emacs will notice this stuff at the end of the file and automatically
- * adjust the settings for this buffer only. This must remain at the end
- * of the file.
- * ---------------------------------------------------------------------------
- * Local variables:
- * c-file-style: "linux"
- * End:
- */
-/*
+/*
* Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
* Licensed under the GPL
*/
} while((err < 0) && (errno == EINTR)) ;
if(err < 0)
- return(-errno);
+ return -errno;
if(ubuf != NULL)
copy_stat(ubuf, &sbuf);
- return(err);
+ return err;
}
int os_stat_file(const char *file_name, struct uml_stat *ubuf)
} while((err < 0) && (errno == EINTR)) ;
if(err < 0)
- return(-errno);
+ return -errno;
if(ubuf != NULL)
copy_stat(ubuf, &sbuf);
- return(err);
+ return err;
}
int os_access(const char* file, int mode)
err = access(file, amode);
if(err < 0)
- return(-errno);
+ return -errno;
- return(0);
+ return 0;
}
void os_print_error(int error, const char* str)
err = ioctl(fd, cmd, arg);
if(err < 0)
- return(-errno);
+ return -errno;
- return(err);
+ return err;
}
int os_window_size(int fd, int *rows, int *cols)
struct winsize size;
if(ioctl(fd, TIOCGWINSZ, &size) < 0)
- return(-errno);
+ return -errno;
*rows = size.ws_row;
*cols = size.ws_col;
- return(0);
+ return 0;
}
int os_new_tty_pgrp(int fd, int pid)
if(tcsetpgrp(fd, pid) < 0)
return -errno;
- return(0);
+ return 0;
}
/* FIXME: ensure namebuf in os_get_if_name is big enough */
int os_get_ifname(int fd, char* namebuf)
{
if(ioctl(fd, SIOCGIFNAME, namebuf) < 0)
- return(-errno);
+ return -errno;
- return(0);
+ return 0;
}
int os_set_slip(int fd)
if(ioctl(fd, SIOCSIFENCAP, &sencap) < 0)
return -errno;
- return(0);
+ return 0;
}
int os_set_owner(int fd, int pid)
int save_errno = errno;
if(fcntl(fd, F_GETOWN, 0) != pid)
- return(-save_errno);
+ return -save_errno;
}
- return(0);
+ return 0;
}
/* FIXME? moved wholesale from sigio_user.c to get fcntls out of that file */
} while((err < 0) && (errno==EINTR)) ;
if(err < 0)
- return(-errno);
+ return -errno;
- return(0);
+ return 0;
}
int os_file_type(char *file)
err = os_stat_file(file, &buf);
if(err < 0)
- return(err);
+ return err;
- if(S_ISDIR(buf.ust_mode)) return(OS_TYPE_DIR);
- else if(S_ISLNK(buf.ust_mode)) return(OS_TYPE_SYMLINK);
- else if(S_ISCHR(buf.ust_mode)) return(OS_TYPE_CHARDEV);
- else if(S_ISBLK(buf.ust_mode)) return(OS_TYPE_BLOCKDEV);
- else if(S_ISFIFO(buf.ust_mode)) return(OS_TYPE_FIFO);
- else if(S_ISSOCK(buf.ust_mode)) return(OS_TYPE_SOCK);
- else return(OS_TYPE_FILE);
+ if(S_ISDIR(buf.ust_mode))
+ return OS_TYPE_DIR;
+ else if(S_ISLNK(buf.ust_mode))
+ return OS_TYPE_SYMLINK;
+ else if(S_ISCHR(buf.ust_mode))
+ return OS_TYPE_CHARDEV;
+ else if(S_ISBLK(buf.ust_mode))
+ return OS_TYPE_BLOCKDEV;
+ else if(S_ISFIFO(buf.ust_mode))
+ return OS_TYPE_FIFO;
+ else if(S_ISSOCK(buf.ust_mode))
+ return OS_TYPE_SOCK;
+ else return OS_TYPE_FILE;
}
int os_file_mode(char *file, struct openflags *mode_out)
actual = lseek64(fd, offset, SEEK_SET);
if(actual != offset)
- return(-errno);
- return(0);
+ return -errno;
+ return 0;
}
static int fault_buffer(void *start, int len,
for(i = 0; i < len; i += page){
if((*copy_proc)(start + i, &c, sizeof(c)))
- return(-EFAULT);
+ return -EFAULT;
}
if((len % page) != 0){
if((*copy_proc)(start + len - 1, &c, sizeof(c)))
- return(-EFAULT);
+ return -EFAULT;
}
- return(0);
+ return 0;
}
static int file_io(int fd, void *buf, int len,
if((n < 0) && (errno == EFAULT)){
err = fault_buffer(buf, len, copy_user_proc);
if(err)
- return(err);
+ return err;
n = (*io_proc)(fd, buf, len);
}
} while((n < 0) && (errno == EINTR));
if(n < 0)
- return(-errno);
- return(n);
+ return -errno;
+ return n;
}
int os_read_file(int fd, void *buf, int len)
{
- return(file_io(fd, buf, len, (int (*)(int, void *, int)) read,
- copy_from_user_proc));
+ return file_io(fd, buf, len, (int (*)(int, void *, int)) read,
+ copy_from_user_proc);
}
int os_write_file(int fd, const void *buf, int len)
{
- return(file_io(fd, (void *) buf, len,
- (int (*)(int, void *, int)) write, copy_to_user_proc));
+ return file_io(fd, (void *) buf, len,
+ (int (*)(int, void *, int)) write, copy_to_user_proc);
}
int os_file_size(char *file, unsigned long long *size_out)
err = os_stat_file(file, &buf);
if(err < 0){
printk("Couldn't stat \"%s\" : err = %d\n", file, -err);
- return(err);
+ return err;
}
*modtime = buf.ust_mtime;
- return(0);
+ return 0;
}
int os_get_exec_close(int fd, int* close_on_exec)
if(err < 0)
goto error;
- return(0);
+ return 0;
error:
printk("os_pipe : Setting FD_CLOEXEC failed, err = %d\n", -err);
(fcntl(fd, F_SETOWN, owner) < 0)){
err = -errno;
printk("os_set_fd_async : Failed to fcntl F_SETOWN "
- "(or F_SETSIG) fd %d to pid %d, errno = %d\n", fd,
+ "(or F_SETSIG) fd %d to pid %d, errno = %d\n", fd,
owner, errno);
return err;
}
- return(0);
+ return 0;
}
int os_clear_fd_async(int fd)
flags &= ~(O_ASYNC | O_NONBLOCK);
if(fcntl(fd, F_SETFL, flags) < 0)
- return(-errno);
- return(0);
+ return -errno;
+ return 0;
}
int os_set_fd_block(int fd, int blocking)
if(fcntl(fd, F_SETFL, flags) < 0)
return -errno;
- return(0);
+ return 0;
}
int os_accept_connection(int fd)
int new;
new = accept(fd, NULL, 0);
- if(new < 0)
- return(-errno);
- return(new);
+ if(new < 0)
+ return -errno;
+ return new;
}
#ifndef SHUT_RD
else if(w) what = SHUT_WR;
else {
printk("os_shutdown_socket : neither r or w was set\n");
- return(-EINVAL);
+ return -EINVAL;
}
err = shutdown(fd, what);
if(err < 0)
- return(-errno);
- return(0);
+ return -errno;
+ return 0;
}
int os_rcv_fd(int fd, int *helper_pid_out)
n = recvmsg(fd, &msg, 0);
if(n < 0)
- return(-errno);
+ return -errno;
else if(n != sizeof(iov.iov_len))
*helper_pid_out = -1;
cmsg = CMSG_FIRSTHDR(&msg);
if(cmsg == NULL){
printk("rcv_fd didn't receive anything, error = %d\n", errno);
- return(-1);
+ return -1;
}
- if((cmsg->cmsg_level != SOL_SOCKET) ||
+ if((cmsg->cmsg_level != SOL_SOCKET) ||
(cmsg->cmsg_type != SCM_RIGHTS)){
printk("rcv_fd didn't receive a descriptor\n");
- return(-1);
+ return -1;
}
new = ((int *) CMSG_DATA(cmsg))[0];
- return(new);
+ return new;
}
int os_create_unix_socket(char *file, int len, int close_on_exec)
if(err < 0)
return -errno;
- return(sock);
+ return sock;
}
void os_flush_stdout(void)
printk("F_SETLK failed, file already locked by pid %d\n", lock.l_pid);
err = save;
out:
- return(err);
+ return err;
}
-
-/*
- * Overrides for Emacs so that we follow Linus's tabbing style.
- * Emacs will notice this stuff at the end of the file and automatically
- * adjust the settings for this buffer only. This must remain at the end
- * of the file.
- * ---------------------------------------------------------------------------
- * Local variables:
- * c-file-style: "linux"
- * End:
- */