error() function is glibc-specific, make own implementation
This commit is contained in:
20
lib.c
20
lib.c
@@ -2,12 +2,26 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <error.h>
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "config.h"
|
||||
#include "lib.h"
|
||||
|
||||
const char *program_invocation_name;
|
||||
|
||||
void error(int status, int errnum, const char *fmt, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
fflush(stdout);
|
||||
fprintf(stderr, "%s: ", program_invocation_name);
|
||||
vfprintf(stderr, fmt, ap);
|
||||
if (errnum) fprintf(stderr, ": %s", strerror(errnum));
|
||||
fprintf(stderr, "\n");
|
||||
if(status) exit(status);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void bits2ip4(bits b, mask_t m, char *s, int size) {
|
||||
// convert bits to in4_addr
|
||||
struct in4_addr ip;
|
||||
@@ -62,7 +76,7 @@ void ip42bits(char *s, bits b, mask_t *m) {
|
||||
}
|
||||
// convert ip to binary
|
||||
struct in4_addr ip;
|
||||
if (!inet_pton(AF_INET, s, &ip)) error(1, errno, "ip42bits");
|
||||
if (inet_pton(AF_INET, s, &ip) < 1) error(1, errno, "ip42bits");
|
||||
// convert binary ip to bits
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
for (int j = 0; j < 8; ++j) {
|
||||
@@ -87,7 +101,7 @@ void ip62bits(char *s, bits b, mask_t *m) {
|
||||
}
|
||||
// convert ip to binary
|
||||
struct in6_addr ip;
|
||||
if (!inet_pton(AF_INET6, s, &ip)) error(1, errno, "ip62bits");
|
||||
if (inet_pton(AF_INET6, s, &ip) < 1) error(1, errno, "ip62bits");
|
||||
// convert binary ip to bits
|
||||
for (int i = 0; i < 16; ++i) {
|
||||
for (int j = 0; j < 8; ++j) {
|
||||
|
||||
Reference in New Issue
Block a user