mirror of
https://codeberg.org/scip/pcp.git
synced 2025-12-17 12:00:56 +01:00
made the platform replacement functions extern
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
This file is part of Pretty Curved Privacy (pcp1).
|
This file is part of Pretty Curved Privacy (pcp1).
|
||||||
|
|
||||||
Copyright (C) 2013 T.Linden.
|
Copyright (C) 2013-2014 T.v.Dein.
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
You can contact me by mail: <tlinden AT cpan DOT org>.
|
You can contact me by mail: <tom AT vondein DOT org>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -68,16 +68,12 @@
|
|||||||
|
|
||||||
#ifndef HAVE_ARC4RANDOM
|
#ifndef HAVE_ARC4RANDOM
|
||||||
#include <sodium.h>
|
#include <sodium.h>
|
||||||
static inline u_int32_t arc4random() {
|
u_int32_t arc4random();
|
||||||
return randombytes_random();
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_ARC4RANDOM_BUF
|
#ifndef HAVE_ARC4RANDOM_BUF
|
||||||
#include <sodium.h>
|
#include <sodium.h>
|
||||||
static inline void arc4random_buf(void *buf, size_t nbytes) {
|
void arc4random_buf(void *buf, size_t nbytes);
|
||||||
randombytes((unsigned char*)buf, nbytes);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@@ -88,17 +84,7 @@ static inline void arc4random_buf(void *buf, size_t nbytes) {
|
|||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
static inline void err(int eval, const char *fmt, ...) {
|
void err(int eval, const char *fmt, ...);
|
||||||
va_list ap;
|
|
||||||
va_start(ap, fmt);
|
|
||||||
fprintf(stderr, "pcp1");
|
|
||||||
if (fmt != NULL) {
|
|
||||||
fprintf(stderr, ": ");
|
|
||||||
vfprintf(stderr, fmt, ap);
|
|
||||||
}
|
|
||||||
fprintf(stderr, ": %s\n", strerror(errno));
|
|
||||||
va_end(ap);
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
@@ -112,28 +98,7 @@ static inline void err(int eval, const char *fmt, ...) {
|
|||||||
#ifndef HAVE_VASPRINTF
|
#ifndef HAVE_VASPRINTF
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
static inline
|
int vasprintf(char **ret, const char *format, va_list args);
|
||||||
int vasprintf(char **ret, const char *format, va_list args) {
|
|
||||||
va_list copy;
|
|
||||||
va_copy(copy, args);
|
|
||||||
|
|
||||||
*ret = 0;
|
|
||||||
|
|
||||||
int count = vsnprintf(NULL, 0, format, args);
|
|
||||||
if (count >= 0) {
|
|
||||||
char* buffer = (char *)malloc(count + 1);
|
|
||||||
if (buffer != NULL) {
|
|
||||||
count = vsnprintf(buffer, count + 1, format, copy);
|
|
||||||
if (count < 0)
|
|
||||||
free(buffer);
|
|
||||||
else
|
|
||||||
*ret = buffer;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
va_end(copy); /* Each va_start() or va_copy() needs a va_end() */
|
|
||||||
|
|
||||||
return count;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -144,43 +109,16 @@ int vasprintf(char **ret, const char *format, va_list args) {
|
|||||||
|
|
||||||
|
|
||||||
#ifndef HAVE_STRNLEN
|
#ifndef HAVE_STRNLEN
|
||||||
static inline size_t
|
size_t
|
||||||
strnlen(const char *msg, size_t maxlen)
|
strnlen(const char *msg, size_t maxlen);
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
for (i=0; i<maxlen; i++)
|
|
||||||
if (msg[i] == '\0')
|
|
||||||
break;
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifndef HAVE_STRNSTR
|
#ifndef HAVE_STRNSTR
|
||||||
/* via FreeBSD libc */
|
/* via FreeBSD libc */
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
static inline char *
|
char *
|
||||||
strnstr(const char *s, const char *find, size_t slen)
|
strnstr(const char *s, const char *find, size_t slen);
|
||||||
{
|
|
||||||
char c, sc;
|
|
||||||
size_t len;
|
|
||||||
|
|
||||||
if ((c = *find++) != '\0') {
|
|
||||||
len = strlen(find);
|
|
||||||
do {
|
|
||||||
do {
|
|
||||||
if (slen-- < 1 || (sc = *s++) == '\0')
|
|
||||||
return (NULL);
|
|
||||||
} while (sc != c);
|
|
||||||
if (len > slen)
|
|
||||||
return (NULL);
|
|
||||||
} while (strncmp(s, find, len) != 0);
|
|
||||||
s--;
|
|
||||||
}
|
|
||||||
return ((char *)s);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* size_t format string */
|
/* size_t format string */
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ lib_LTLIBRARIES = libpcp1.la
|
|||||||
pkgconfigdir = $(libdir)/pkgconfig
|
pkgconfigdir = $(libdir)/pkgconfig
|
||||||
pkgconfig_DATA = libpcp1.pc
|
pkgconfig_DATA = libpcp1.pc
|
||||||
|
|
||||||
libpcp1_la_SOURCES = mac.c mem.c pad.c version.c \
|
libpcp1_la_SOURCES = platform.c mac.c mem.c pad.c version.c \
|
||||||
z85.c zmq_z85.c key.c randomart.c \
|
z85.c zmq_z85.c key.c randomart.c \
|
||||||
vault.c fatal.c jenhash.c digital_crc32.c \
|
vault.c fatal.c jenhash.c digital_crc32.c \
|
||||||
crypto.c ed.c keyhash.c scrypt.c \
|
crypto.c ed.c keyhash.c scrypt.c \
|
||||||
|
|||||||
112
libpcp/platform.c
Normal file
112
libpcp/platform.c
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
/*
|
||||||
|
This file is part of Pretty Curved Privacy (pcp1).
|
||||||
|
|
||||||
|
Copyright (C) 2013-2014 T.v.Dein.
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
You can contact me by mail: <tom AT vondein DOT org>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "platform.h"
|
||||||
|
|
||||||
|
#ifndef HAVE_ARC4RANDOM
|
||||||
|
u_int32_t arc4random() {
|
||||||
|
return randombytes_random();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_ARC4RANDOM_BUF
|
||||||
|
#include <sodium.h>
|
||||||
|
void arc4random_buf(void *buf, size_t nbytes) {
|
||||||
|
randombytes((unsigned char*)buf, nbytes);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_ERR_H
|
||||||
|
void err(int eval, const char *fmt, ...) {
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
fprintf(stderr, "pcp1");
|
||||||
|
if (fmt != NULL) {
|
||||||
|
fprintf(stderr, ": ");
|
||||||
|
vfprintf(stderr, fmt, ap);
|
||||||
|
}
|
||||||
|
fprintf(stderr, ": %s\n", strerror(errno));
|
||||||
|
va_end(ap);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_VASPRINTF
|
||||||
|
int vasprintf(char **ret, const char *format, va_list args) {
|
||||||
|
va_list copy;
|
||||||
|
va_copy(copy, args);
|
||||||
|
|
||||||
|
*ret = 0;
|
||||||
|
|
||||||
|
int count = vsnprintf(NULL, 0, format, args);
|
||||||
|
if (count >= 0) {
|
||||||
|
char* buffer = (char *)malloc(count + 1);
|
||||||
|
if (buffer != NULL) {
|
||||||
|
count = vsnprintf(buffer, count + 1, format, copy);
|
||||||
|
if (count < 0)
|
||||||
|
free(buffer);
|
||||||
|
else
|
||||||
|
*ret = buffer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
va_end(copy); /* Each va_start() or va_copy() needs a va_end() */
|
||||||
|
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_STRNLEN
|
||||||
|
size_t
|
||||||
|
strnlen(const char *msg, size_t maxlen)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
for (i=0; i<maxlen; i++)
|
||||||
|
if (msg[i] == '\0')
|
||||||
|
break;
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef HAVE_STRNSTR
|
||||||
|
/* via FreeBSD libc */
|
||||||
|
char *
|
||||||
|
strnstr(const char *s, const char *find, size_t slen)
|
||||||
|
{
|
||||||
|
char c, sc;
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
if ((c = *find++) != '\0') {
|
||||||
|
len = strlen(find);
|
||||||
|
do {
|
||||||
|
do {
|
||||||
|
if (slen-- < 1 || (sc = *s++) == '\0')
|
||||||
|
return (NULL);
|
||||||
|
} while (sc != c);
|
||||||
|
if (len > slen)
|
||||||
|
return (NULL);
|
||||||
|
} while (strncmp(s, find, len) != 0);
|
||||||
|
s--;
|
||||||
|
}
|
||||||
|
return ((char *)s);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user