mirror of
https://github.com/troglobit/finit.git
synced 2026-10-28 12:30:44 +00:00
Helper code cleanup
Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
This commit is contained in:
1 parent
d17c3160bd
commit
cdbc2c536d
1 file changed
+20
-24
@@ -43,21 +43,23 @@ void ifconfig(char *name, char *inet, char *mask, int up)
|
|||||||
memset(&ifr, 0, sizeof (ifr));
|
memset(&ifr, 0, sizeof (ifr));
|
||||||
strncpy(ifr.ifr_name, name, IFNAMSIZ);
|
strncpy(ifr.ifr_name, name, IFNAMSIZ);
|
||||||
a->sin_family = AF_INET;
|
a->sin_family = AF_INET;
|
||||||
inet_aton(inet, &a->sin_addr);
|
|
||||||
|
|
||||||
if (up) {
|
if (up) {
|
||||||
|
inet_aton(inet, &a->sin_addr);
|
||||||
ioctl(sock, SIOCSIFADDR, &ifr);
|
ioctl(sock, SIOCSIFADDR, &ifr);
|
||||||
inet_aton(mask, &a->sin_addr);
|
inet_aton(mask, &a->sin_addr);
|
||||||
ioctl(sock, SIOCSIFNETMASK, &ifr);
|
ioctl(sock, SIOCSIFNETMASK, &ifr);
|
||||||
ioctl(sock, SIOCGIFFLAGS, &ifr);
|
|
||||||
ifr.ifr_flags |= IFF_UP;
|
|
||||||
ioctl(sock, SIOCSIFFLAGS, &ifr);
|
|
||||||
} else {
|
|
||||||
ioctl(sock, SIOCGIFFLAGS, &ifr);
|
|
||||||
ifr.ifr_flags &= ~IFF_UP;
|
|
||||||
ioctl(sock, SIOCSIFFLAGS, &ifr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ioctl(sock, SIOCGIFFLAGS, &ifr);
|
||||||
|
|
||||||
|
if (up)
|
||||||
|
ifr.ifr_flags |= IFF_UP;
|
||||||
|
else
|
||||||
|
ifr.ifr_flags &= ~IFF_UP;
|
||||||
|
|
||||||
|
ioctl(sock, SIOCSIFFLAGS, &ifr);
|
||||||
|
|
||||||
close(sock);
|
close(sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,25 +70,19 @@ void copyfile(char *src, char *dst, int size)
|
|||||||
char buffer[BUF_SIZE];
|
char buffer[BUF_SIZE];
|
||||||
int s, d, n;
|
int s, d, n;
|
||||||
|
|
||||||
|
/* Size == 0 means copy entire file */
|
||||||
|
if (size == 0)
|
||||||
|
size = INT_MAX;
|
||||||
|
|
||||||
if ((s = open(src, O_RDONLY)) >= 0) {
|
if ((s = open(src, O_RDONLY)) >= 0) {
|
||||||
if ((d = open(dst, O_WRONLY | O_CREAT, 0644)) >= 0) {
|
if ((d = open(dst, O_WRONLY | O_CREAT, 0644)) >= 0) {
|
||||||
|
do {
|
||||||
|
int csize = size > BUF_SIZE ? BUF_SIZE : size;
|
||||||
|
|
||||||
/* Size == 0 means copy entire file */
|
if ((n = read(s, buffer, csize)) > 0)
|
||||||
if (size == 0) {
|
write(d, buffer, n);
|
||||||
do {
|
size -= csize;
|
||||||
if ((n = read(s, buffer, BUF_SIZE)) > 0)
|
} while (size > 0 && n == BUF_SIZE);
|
||||||
write(d, buffer, n);
|
|
||||||
} while (n == BUF_SIZE);
|
|
||||||
} else {
|
|
||||||
do {
|
|
||||||
int csize = size > BUF_SIZE ?
|
|
||||||
BUF_SIZE : size;
|
|
||||||
|
|
||||||
if ((n = read(s, buffer, csize)) > 0)
|
|
||||||
write(d, buffer, n);
|
|
||||||
size -= csize;
|
|
||||||
} while (size > 0 && n == BUF_SIZE);
|
|
||||||
}
|
|
||||||
close(d);
|
close(d);
|
||||||
}
|
}
|
||||||
close(s);
|
close(s);
|
||||||
|
|||||||
Reference in new issue
Block a user