Make roken build on windows
Signed-off-by: Love Hornquist Astrand <lha@h5l.org>
This commit is contained in:

committed by
Love Hornquist Astrand

parent
c4b95f7330
commit
d00f9984a5
appl
ftp
ftpd
gssmask
kf
kx
popper
rsh
telnet
telnetd
test
kadmin
kdc
lib
krb5
roken
NTMakefilebase64.cbase64.hbswap.cchown.ccloexec.cclosefrom.cconcat.ccopyhostent.cdaemon.cdirent-test.cdirent.cdirent.hindlfcn.hdlfcn_w32.cdumpdata.cecalloc.cemalloc.cenvironment.ceread.cerealloc.cerr.cerr.hinerrx.cesetenv.cestrdup.cewrite.cfchown.cflock.cfnmatch.cfnmatch.hinfreeaddrinfo.cfreehostent.cgai_strerror.cget_default_username.cget_window_size.cgetaddrinfo.cgetaddrinfo_hostspec.cgetarg.cgetarg.hgetcap.cgetcwd.cgetdtablesize.cgetegid.cgeteuid.cgetgid.cgethostname.cgetifaddrs-test.cgetifaddrs.cgetifaddrs_w32.cgetipnodebyaddr.cgetipnodebyname.cgetnameinfo.cgetnameinfo_verified.cgetopt.cgetprogname.cgettimeofday.cgetuid.cgetusershell.cglob.chex.chex.hhostent_find_fqdn.chstrerror.cinet_aton.cinet_ntop.cinet_pton.cinitgroups.cinnetgr.ciruserok.cissuid.ck_getpwnam.ck_getpwuid.clocaltime_r.clstat.cmemmove.cmini_inetd.cmkstemp.cndbm_wrap.cndbm_wrap.hnet_read.cnet_write.cparse_bytes.cparse_bytes.hparse_time-test.cparse_time.cparse_time.hparse_units.cparse_units.hputenv.crcmd.creadv.crealloc.crecvmsg.cresolve-test.cresolve.cresolve.hrkpty.croken-common.hroken.h.inroken_gethostby.crtbl.crtbl.hsendmsg.csetegid.csetenv.cseteuid.csetprogname.csignal.csimple_exec.csimple_exec_w32.csleep.csnprintf.csocket.csockstartup_w32.cstrcasecmp.cstrcollect.cstrdup.cstrerror.cstrftime.cstrlcat.cstrlcpy.cstrlwr.cstrncasecmp.cstrndup.cstrnlen.cstrpftime-test.cstrpftime-test.hstrpool.cstrptime.cstrsep.cstrsep_copy.cstrtok_r.cstrupr.cswab.csyslog.hsyslogc.ctest-mem.ctest-mem.htest-mini_inetd.ctimeval.ctm2time.cunsetenv.cunvis.cverify.cverr.cverrx.cvis.cvis.hinvsyslog.cvwarn.cvwarnx.cwarnerr.cwarnx.cwrite_pid.cwritev.cxfree.c
@ -329,7 +329,7 @@ main(int argc, char **argv)
|
||||
#endif
|
||||
|
||||
if(interactive_flag)
|
||||
mini_inetd (port);
|
||||
mini_inetd(port, NULL);
|
||||
|
||||
/*
|
||||
* LOG_NDELAY sets up the logging connection immediately,
|
||||
|
@ -1252,7 +1252,7 @@ main(int argc, char **argv)
|
||||
err(1, "error opening %s", lf);
|
||||
}
|
||||
|
||||
mini_inetd(htons(port));
|
||||
mini_inetd(htons(port), NULL);
|
||||
fprintf(logfile, "connected\n");
|
||||
|
||||
{
|
||||
|
@ -284,7 +284,7 @@ static int
|
||||
doit (int port, const char *service)
|
||||
{
|
||||
if (do_inetd)
|
||||
mini_inetd(port);
|
||||
mini_inetd(port, NULL);
|
||||
return proto (STDIN_FILENO, service);
|
||||
}
|
||||
|
||||
|
@ -772,7 +772,7 @@ main (int argc, char **argv)
|
||||
}
|
||||
|
||||
if (!inetd_flag)
|
||||
mini_inetd (port);
|
||||
mini_inetd (port, NULL);
|
||||
|
||||
signal (SIGCHLD, childhandler);
|
||||
return doit(STDIN_FILENO, tcp_flag);
|
||||
|
@ -301,7 +301,7 @@ pop_init(POP *p,int argcount,char **argmessage)
|
||||
portnum = p->kerberosp ?
|
||||
pop_getportbyname(p, "kpop", "tcp", 1109) :
|
||||
pop_getportbyname(p, "pop", "tcp", 110);
|
||||
mini_inetd (portnum);
|
||||
mini_inetd (portnum, NULL);
|
||||
}
|
||||
|
||||
/* Get the address and socket of the client to whom I am speaking */
|
||||
|
@ -961,7 +961,7 @@ main(int argc, char **argv)
|
||||
errx (1, "getaddrinfo: %s", gai_strerror (error));
|
||||
}
|
||||
}
|
||||
mini_inetd_addrinfo (ai);
|
||||
mini_inetd_addrinfo (ai, NULL);
|
||||
freeaddrinfo(ai);
|
||||
}
|
||||
|
||||
|
@ -370,7 +370,7 @@ main(int argc, char **argv)
|
||||
port = k_getportbyname("telnet", "tcp", htons(23));
|
||||
#endif
|
||||
}
|
||||
mini_inetd (port);
|
||||
mini_inetd (port, NULL);
|
||||
} else if (argc > 0) {
|
||||
usage(1);
|
||||
/* NOT REACHED */
|
||||
|
@ -155,7 +155,7 @@ proto (int sock, const char *service)
|
||||
static int
|
||||
doit (int port, const char *service)
|
||||
{
|
||||
mini_inetd (port);
|
||||
mini_inetd (port, NULL);
|
||||
|
||||
return proto (STDIN_FILENO, service);
|
||||
}
|
||||
|
@ -168,7 +168,7 @@ main(int argc, char **argv)
|
||||
"tcp", 749);
|
||||
else
|
||||
debug_port = htons(atoi(port_str));
|
||||
mini_inetd(debug_port);
|
||||
mini_inetd(debug_port, NULL);
|
||||
} else {
|
||||
struct sockaddr_storage __ss;
|
||||
struct sockaddr *sa = (struct sockaddr *)&__ss;
|
||||
|
@ -133,7 +133,7 @@ main(int argc, char **argv)
|
||||
}
|
||||
if (!inetd_flag) {
|
||||
mini_inetd (krb5_getportbyname (context, "hprop", "tcp",
|
||||
HPROP_PORT));
|
||||
HPROP_PORT), NULL);
|
||||
}
|
||||
sin_len = sizeof(ss);
|
||||
if(getpeername(fd, sa, &sin_len) < 0)
|
||||
|
@ -132,7 +132,6 @@ check_directory(krb5_context context,
|
||||
if((d = opendir(dirname)) == NULL)
|
||||
return errno;
|
||||
|
||||
#ifdef HAVE_DIRFD
|
||||
{
|
||||
int fd;
|
||||
struct stat st2;
|
||||
@ -147,7 +146,6 @@ check_directory(krb5_context context,
|
||||
return EACCES;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
while((dent = readdir(d)) != NULL) {
|
||||
if(strcmp(dent->d_name, ".") == 0 ||
|
||||
|
@ -79,7 +79,7 @@ libroken_la_OBJS = \
|
||||
$(OBJ)\resolve.obj \
|
||||
$(OBJ)\roken_gethostby.obj \
|
||||
$(OBJ)\rtbl.obj \
|
||||
$(OBJ)\sendmsg_w32.obj \
|
||||
$(OBJ)\sendmsg.obj \
|
||||
$(OBJ)\setenv.obj \
|
||||
$(OBJ)\setprogname.obj \
|
||||
$(OBJ)\simple_exec_w32.obj \
|
||||
|
@ -51,7 +51,7 @@ pos(char c)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
base64_encode(const void *data, int size, char **str)
|
||||
{
|
||||
char *s, *p;
|
||||
@ -120,7 +120,7 @@ token_decode(const char *token)
|
||||
return (marker << 24) | val;
|
||||
}
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
base64_decode(const char *str, void *data)
|
||||
{
|
||||
const char *p;
|
||||
|
@ -38,16 +38,18 @@
|
||||
|
||||
#ifndef ROKEN_LIB_FUNCTION
|
||||
#ifdef _WIN32
|
||||
#define ROKEN_LIB_FUNCTION _stdcall
|
||||
#define ROKEN_LIB_FUNCTION
|
||||
#define ROKEN_LIB_CALL __cdecl
|
||||
#else
|
||||
#define ROKEN_LIB_FUNCTION
|
||||
#define ROKEN_LIB_CALL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
base64_encode(const void *, int, char **);
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
base64_decode(const char *, void *);
|
||||
|
||||
#endif
|
||||
|
@ -36,7 +36,7 @@
|
||||
|
||||
#ifndef HAVE_BSWAP32
|
||||
|
||||
unsigned int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL
|
||||
bswap32 (unsigned int val)
|
||||
{
|
||||
return (val & 0xff) << 24 |
|
||||
@ -48,7 +48,7 @@ bswap32 (unsigned int val)
|
||||
|
||||
#ifndef HAVE_BSWAP16
|
||||
|
||||
unsigned short ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION unsigned short ROKEN_LIB_CALL
|
||||
bswap16 (unsigned short val)
|
||||
{
|
||||
return (val & 0xff) << 8 |
|
||||
|
@ -35,7 +35,7 @@
|
||||
|
||||
#include "roken.h"
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
chown(const char *path, uid_t owner, gid_t group)
|
||||
{
|
||||
return 0;
|
||||
|
@ -33,14 +33,12 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#include "roken.h"
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
rk_cloexec(int fd)
|
||||
{
|
||||
#ifdef HAVE_FCNTL
|
||||
int ret;
|
||||
|
||||
ret = fcntl(fd, F_GETFD);
|
||||
@ -48,10 +46,13 @@ rk_cloexec(int fd)
|
||||
return;
|
||||
if (fcntl(fd, F_SETFD, ret | FD_CLOEXEC) == -1)
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
rk_cloexec_file(FILE *f)
|
||||
{
|
||||
#ifdef HAVE_FCNTL
|
||||
rk_cloexec(fileno(f));
|
||||
#endif
|
||||
}
|
||||
|
@ -42,7 +42,7 @@
|
||||
|
||||
#include "roken.h"
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
closefrom(int fd)
|
||||
{
|
||||
int num = getdtablesize();
|
||||
|
@ -35,7 +35,7 @@
|
||||
|
||||
#include "roken.h"
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
roken_concat (char *s, size_t len, ...)
|
||||
{
|
||||
int ret;
|
||||
@ -47,7 +47,7 @@ roken_concat (char *s, size_t len, ...)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
roken_vconcat (char *s, size_t len, va_list args)
|
||||
{
|
||||
const char *a;
|
||||
@ -65,7 +65,7 @@ roken_vconcat (char *s, size_t len, va_list args)
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
|
||||
roken_vmconcat (char **s, size_t max_len, va_list args)
|
||||
{
|
||||
const char *a;
|
||||
@ -97,7 +97,7 @@ roken_vmconcat (char **s, size_t max_len, va_list args)
|
||||
return len;
|
||||
}
|
||||
|
||||
size_t ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
|
||||
roken_mconcat (char **s, size_t max_len, ...)
|
||||
{
|
||||
int ret;
|
||||
|
@ -39,7 +39,7 @@
|
||||
* return a malloced copy of `h'
|
||||
*/
|
||||
|
||||
struct hostent * ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
|
||||
copyhostent (const struct hostent *h)
|
||||
{
|
||||
struct hostent *res;
|
||||
|
@ -47,7 +47,7 @@ static char sccsid[] = "@(#)daemon.c 8.1 (Berkeley) 6/4/93";
|
||||
|
||||
#include "roken.h"
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
daemon(int nochdir, int noclose)
|
||||
{
|
||||
int fd;
|
||||
|
278
lib/roken/dirent-test.c
Normal file
278
lib/roken/dirent-test.c
Normal file
@ -0,0 +1,278 @@
|
||||
/***********************************************************************
|
||||
* Copyright (c) 2009, Secure Endpoints Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <direct.h>
|
||||
#include <errno.h>
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
#include "dirent.h"
|
||||
|
||||
/* Note that we create a known directory structure in a subdirectory
|
||||
of the current directory to run our tests. */
|
||||
|
||||
#define TESTDIR "dirent-test-dir"
|
||||
|
||||
const char * dir_entries[] = {
|
||||
"A",
|
||||
"B",
|
||||
"C",
|
||||
"CAA",
|
||||
"CAAA",
|
||||
"CABBBB",
|
||||
"CAABBB.txt",
|
||||
"A filename with spaces"
|
||||
};
|
||||
|
||||
const char * entries_begin_with_C[] = {
|
||||
"C",
|
||||
"CAA",
|
||||
"CAAA",
|
||||
"CABBBB",
|
||||
"CAABBB.txt"
|
||||
};
|
||||
|
||||
const char * entries_end_with_A[] = {
|
||||
"A",
|
||||
"CAA",
|
||||
"CAAA"
|
||||
};
|
||||
|
||||
const int n_dir_entries = sizeof(dir_entries)/sizeof(dir_entries[0]);
|
||||
|
||||
int teardown_test(void);
|
||||
|
||||
void fail_test(const char * reason, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, reason);
|
||||
vfprintf(stderr, reason, args);
|
||||
va_end(args);
|
||||
|
||||
fprintf(stderr, " : errno = %d (%s)\n", errno, strerror(errno));
|
||||
teardown_test();
|
||||
abort();
|
||||
}
|
||||
|
||||
void fail_test_nf(const char * format, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
fprintf(stderr, "FAIL:");
|
||||
|
||||
va_start(args, format);
|
||||
vfprintf(stderr, format, args);
|
||||
va_end(args);
|
||||
|
||||
fprintf(stderr, " : errno = %d (%s)\n", errno, strerror(errno));
|
||||
}
|
||||
|
||||
int touch(const char * filename)
|
||||
{
|
||||
int fd;
|
||||
|
||||
fd = _open(filename, _O_CREAT, _S_IREAD| _S_IWRITE);
|
||||
|
||||
if (fd == -1)
|
||||
return -1;
|
||||
|
||||
return _close(fd);
|
||||
}
|
||||
|
||||
int setup_test(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
fprintf(stderr, "Creating test directory %s ...\n", TESTDIR);
|
||||
|
||||
if (_mkdir(TESTDIR))
|
||||
fail_test("Can't create test directory \"" TESTDIR "\"");
|
||||
|
||||
if (_chdir(TESTDIR))
|
||||
fail_test("Can't change to test directory");
|
||||
|
||||
for (i=0; i < n_dir_entries; i++) {
|
||||
if (touch(dir_entries[i]))
|
||||
fail_test("Can't create test file '%s'", dir_entries[i]);
|
||||
}
|
||||
|
||||
fprintf(stderr, "Done with test setup.\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int teardown_test(void)
|
||||
{
|
||||
char dirname[_MAX_PATH];
|
||||
size_t len;
|
||||
int i;
|
||||
|
||||
printf ("Begin cleanup...\n");
|
||||
|
||||
if (_getcwd(dirname, sizeof(dirname)/sizeof(char)) != NULL &&
|
||||
|
||||
(len = strlen(dirname)) > sizeof(TESTDIR)/sizeof(char) &&
|
||||
|
||||
!strcmp(dirname + len + 1 - sizeof(TESTDIR)/sizeof(char), TESTDIR)) {
|
||||
|
||||
/* fallthrough */
|
||||
|
||||
} else {
|
||||
/* did we create the directory? */
|
||||
|
||||
if (!_rmdir( TESTDIR )) {
|
||||
fprintf(stderr, "Removed test directory\n");
|
||||
return 0;
|
||||
} else {
|
||||
if (errno == ENOTEMPTY) {
|
||||
if (_chdir(TESTDIR)) {
|
||||
fprintf(stderr, "Can't change to test directory. Aborting cleanup.\n");
|
||||
return -1;
|
||||
} else {
|
||||
/* fallthrough */
|
||||
}
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stderr, "Cleaning up test directory %s ...\n", TESTDIR);
|
||||
|
||||
for (i=0; i < n_dir_entries; i++) {
|
||||
if (_unlink(dir_entries[i])) {
|
||||
/* if the test setup failed, we expect this to happen for
|
||||
at least some files */
|
||||
}
|
||||
}
|
||||
|
||||
if (_chdir("..")) {
|
||||
fprintf(stderr, "Can't escape test directory. Giving in.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (_rmdir( TESTDIR )) {
|
||||
fprintf(stderr, "Can't remove test directory.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Cleaned up test directory\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int check_list(const char * filespec, const char ** list, int n, int expect_dot_and_dotdot)
|
||||
{
|
||||
DIR * d;
|
||||
struct dirent * e;
|
||||
int n_found = 0;
|
||||
int i;
|
||||
int rv = 0;
|
||||
int retry = 1;
|
||||
|
||||
d = opendir(filespec);
|
||||
if (d == NULL) {
|
||||
fail_test_nf("opendir failed for [%s]", filespec);
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("Checking filespec [%s]... ", filespec);
|
||||
|
||||
retry:
|
||||
while ((e = readdir(d)) != NULL) {
|
||||
n_found ++;
|
||||
|
||||
if (expect_dot_and_dotdot &&
|
||||
(!strcmp(e->d_name, ".") ||
|
||||
!strcmp(e->d_name, "..")))
|
||||
continue;
|
||||
|
||||
for (i=0; i < n; i++) {
|
||||
if (!strcmp(list[i], e->d_name))
|
||||
break;
|
||||
}
|
||||
|
||||
if (i == n) {
|
||||
fail_test_nf("Found unexpected entry [%s]", e->d_name);
|
||||
rv = -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (n_found != n) {
|
||||
fail_test_nf("Unexpected number of entries [%d]. Expected %d", n_found, n);
|
||||
rv = -1;
|
||||
}
|
||||
|
||||
if (retry) {
|
||||
retry = 0;
|
||||
n_found = 0;
|
||||
|
||||
rewinddir(d);
|
||||
goto retry;
|
||||
}
|
||||
|
||||
if (closedir(d)) {
|
||||
fail_test_nf("closedir() failed");
|
||||
}
|
||||
|
||||
printf("done\n");
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
int run_tests()
|
||||
{
|
||||
/* assumes that the test directory has been set up and we have
|
||||
changed into the test directory. */
|
||||
|
||||
check_list("*", dir_entries, n_dir_entries + 2, 1);
|
||||
check_list("*.*", dir_entries, n_dir_entries + 2, 1);
|
||||
check_list("C*", entries_begin_with_C, sizeof(entries_begin_with_C)/sizeof(entries_begin_with_C[0]), 0);
|
||||
check_list("*A", entries_end_with_A, sizeof(entries_end_with_A)/sizeof(entries_end_with_A[0]), 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
if (setup_test())
|
||||
return 1;
|
||||
|
||||
run_tests();
|
||||
|
||||
teardown_test();
|
||||
|
||||
return 0;
|
||||
}
|
180
lib/roken/dirent.c
Normal file
180
lib/roken/dirent.c
Normal file
@ -0,0 +1,180 @@
|
||||
/***********************************************************************
|
||||
* Copyright (c) 2009, Secure Endpoints Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include<config.h>
|
||||
#endif
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <io.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include "dirent.h"
|
||||
|
||||
#ifndef _WIN32
|
||||
#error Only implemented for Win32
|
||||
#endif
|
||||
|
||||
struct _dirent_dirinfo {
|
||||
int magic;
|
||||
long n_entries;
|
||||
long nc_entries;
|
||||
long cursor;
|
||||
struct dirent **entries;
|
||||
};
|
||||
#define DIRINFO_MAGIC 0xf8c0639d
|
||||
#define IS_DP(p) ((p) && ((DIR *)(p))->magic == DIRINFO_MAGIC)
|
||||
|
||||
#define INITIAL_ENTRIES 16
|
||||
|
||||
ROKEN_LIB_FUNCTION DIR * ROKEN_LIB_CALL
|
||||
opendir(const char * filespec)
|
||||
{
|
||||
DIR * dp;
|
||||
struct _finddata_t fd;
|
||||
intptr_t fd_handle;
|
||||
|
||||
memset(&fd, 0, sizeof(fd));
|
||||
|
||||
fd_handle = _findfirst(filespec, &fd);
|
||||
|
||||
if (fd_handle == -1)
|
||||
return NULL;
|
||||
|
||||
dp = malloc(sizeof(*dp));
|
||||
if (dp == NULL)
|
||||
goto done;
|
||||
|
||||
memset(dp, 0, sizeof(*dp));
|
||||
dp->magic = DIRINFO_MAGIC;
|
||||
dp->cursor = 0;
|
||||
dp->n_entries = 0;
|
||||
dp->nc_entries = INITIAL_ENTRIES;
|
||||
dp->entries = calloc(dp->nc_entries, sizeof(dp->entries[0]));
|
||||
|
||||
if (dp->entries == NULL) {
|
||||
closedir(dp);
|
||||
dp = NULL;
|
||||
goto done;
|
||||
}
|
||||
|
||||
do {
|
||||
long len = strlen(fd.name);
|
||||
struct dirent * e;
|
||||
|
||||
if (dp->n_entries == dp->nc_entries) {
|
||||
struct dirent ** ne;
|
||||
|
||||
dp->nc_entries *= 2;
|
||||
ne = realloc(dp->entries, sizeof(dp->entries[0]) * dp->nc_entries);
|
||||
|
||||
if (ne == NULL) {
|
||||
closedir(dp);
|
||||
dp = NULL;
|
||||
goto done;
|
||||
}
|
||||
|
||||
dp->entries = ne;
|
||||
}
|
||||
|
||||
e = malloc(sizeof(*e) + len * sizeof(char));
|
||||
if (e == NULL) {
|
||||
closedir(dp);
|
||||
dp = NULL;
|
||||
goto done;
|
||||
}
|
||||
|
||||
e->d_ino = 0; /* no inodes :( */
|
||||
strcpy_s(e->d_name, len + 1, fd.name);
|
||||
|
||||
dp->entries[dp->n_entries++] = e;
|
||||
|
||||
} while (_findnext(fd_handle, &fd) == 0);
|
||||
|
||||
done:
|
||||
if (fd_handle != -1)
|
||||
_findclose(fd_handle);
|
||||
|
||||
return dp;
|
||||
}
|
||||
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
closedir(DIR * dp)
|
||||
{
|
||||
if (!IS_DP(dp))
|
||||
return EINVAL;
|
||||
|
||||
if (dp->entries) {
|
||||
long i;
|
||||
|
||||
for (i=0; i < dp->n_entries; i++) {
|
||||
free(dp->entries[i]);
|
||||
}
|
||||
|
||||
free(dp->entries);
|
||||
}
|
||||
|
||||
free(dp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
ROKEN_LIB_FUNCTION struct dirent * ROKEN_LIB_CALL
|
||||
readdir(DIR * dp)
|
||||
{
|
||||
if (!IS_DP(dp) ||
|
||||
dp->cursor < 0 ||
|
||||
dp->cursor >= dp->n_entries)
|
||||
|
||||
return NULL;
|
||||
|
||||
return dp->entries[dp->cursor++];
|
||||
}
|
||||
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
rewinddir(DIR * dp)
|
||||
{
|
||||
if (IS_DP(dp))
|
||||
dp->cursor = 0;
|
||||
}
|
||||
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
seekdir(DIR * dp, long offset)
|
||||
{
|
||||
if (IS_DP(dp) && offset >= 0 && offset < dp->n_entries)
|
||||
dp->cursor = offset;
|
||||
}
|
||||
|
||||
ROKEN_LIB_FUNCTION long ROKEN_LIB_CALL
|
||||
telldir(DIR * dp)
|
||||
{
|
||||
return dp->cursor;
|
||||
}
|
66
lib/roken/dirent.hin
Normal file
66
lib/roken/dirent.hin
Normal file
@ -0,0 +1,66 @@
|
||||
/***********************************************************************
|
||||
* Copyright (c) 2009, Secure Endpoints Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef __DIRENT_H__
|
||||
#define __DIRENT_H__
|
||||
|
||||
#ifndef ROKEN_LIB_FUNCTION
|
||||
#ifdef _WIN32
|
||||
#define ROKEN_LIB_FUNCTION
|
||||
#define ROKEN_LIB_CALL __cdecl
|
||||
#else
|
||||
#define ROKEN_LIB_FUNCTION
|
||||
#define ROKEN_LIB_CALL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#include<sys/types.h>
|
||||
|
||||
struct dirent {
|
||||
ino_t d_ino;
|
||||
char d_name[1];
|
||||
};
|
||||
|
||||
typedef struct _dirent_dirinfo DIR;
|
||||
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL closedir(DIR *);
|
||||
|
||||
ROKEN_LIB_FUNCTION DIR * ROKEN_LIB_CALL opendir(const char *);
|
||||
|
||||
ROKEN_LIB_FUNCTION struct dirent * ROKEN_LIB_CALL readdir(DIR *);
|
||||
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL rewinddir(DIR *);
|
||||
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL seekdir(DIR *, long);
|
||||
|
||||
ROKEN_LIB_FUNCTION long ROKEN_LIB_CALL telldir(DIR *);
|
||||
|
||||
#endif
|
78
lib/roken/dlfcn.h
Normal file
78
lib/roken/dlfcn.h
Normal file
@ -0,0 +1,78 @@
|
||||
/***********************************************************************
|
||||
* Copyright (c) 2009, Secure Endpoints Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
#ifndef __dlfcn_h__
|
||||
#define __dlfcn_h__
|
||||
|
||||
#ifndef ROKEN_LIB_FUNCTION
|
||||
#ifdef _WIN32
|
||||
#define ROKEN_LIB_FUNCTION
|
||||
#define ROKEN_LIB_CALL __cdecl
|
||||
#else
|
||||
#define ROKEN_LIB_FUNCTION
|
||||
#define ROKEN_LIB_CALL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define DLSYM_RET_TYPE void *
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
|
||||
/* Implementation based on
|
||||
http://www.opengroup.org/onlinepubs/009695399/basedefs/dlfcn.h.html */
|
||||
|
||||
#define RTLD_LAZY (1<<0)
|
||||
|
||||
#define RTLD_NOW (1<<1)
|
||||
|
||||
#define RTLD_GLOBAL (1<<2)
|
||||
|
||||
#define RTLD_LOCAL (1<<3)
|
||||
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
dlclose(void *);
|
||||
|
||||
ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
|
||||
dlerror(void);
|
||||
|
||||
ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL
|
||||
dlopen(const char *, int);
|
||||
|
||||
ROKEN_LIB_FUNCTION DLSYM_RET_TYPE ROKEN_LIB_CALL
|
||||
dlsym(void *, const char *);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* __dlfcn_h__ */
|
96
lib/roken/dlfcn_w32.c
Normal file
96
lib/roken/dlfcn_w32.c
Normal file
@ -0,0 +1,96 @@
|
||||
/***********************************************************************
|
||||
* Copyright (c) 2009, Secure Endpoints Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
#include <windows.h>
|
||||
#include <dlfcn.h>
|
||||
#include <strsafe.h>
|
||||
|
||||
#define ERR_STR_LEN 256
|
||||
|
||||
__declspec(thread) static char err_str[ERR_STR_LEN];
|
||||
|
||||
static void set_error(const char * e) {
|
||||
StringCbCopy(err_str, sizeof(err_str), e);
|
||||
}
|
||||
|
||||
static void set_error_from_last(void) {
|
||||
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
|
||||
0, GetLastError(), 0,
|
||||
err_str, sizeof(err_str)/sizeof(err_str[0]),
|
||||
NULL);
|
||||
}
|
||||
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
dlclose(void * vhm)
|
||||
{
|
||||
BOOL brv;
|
||||
|
||||
brv = FreeLibrary((HMODULE) vhm);
|
||||
if (!brv) {
|
||||
set_error_from_last();
|
||||
}
|
||||
return !brv;
|
||||
}
|
||||
|
||||
ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
|
||||
dlerror(void)
|
||||
{
|
||||
return err_str;
|
||||
}
|
||||
|
||||
ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL
|
||||
dlopen(const char *fn, int flags)
|
||||
{
|
||||
HMODULE hm;
|
||||
|
||||
/* We don't support dlopen(0, ...) on Windows.*/
|
||||
if ( fn == NULL ) {
|
||||
set_error("Not implemented");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
hm = LoadLibrary(fn);
|
||||
|
||||
if (hm == NULL) {
|
||||
set_error_from_last();
|
||||
}
|
||||
|
||||
return (void *) hm;
|
||||
}
|
||||
|
||||
ROKEN_LIB_FUNCTION DLSYM_RET_TYPE ROKEN_LIB_CALL
|
||||
dlsym(void * vhm, const char * func_name)
|
||||
{
|
||||
HMODULE hm = (HMODULE) vhm;
|
||||
|
||||
return GetProcAddress(hm, func_name);
|
||||
}
|
||||
|
@ -33,15 +33,13 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#include "roken.h"
|
||||
|
||||
/*
|
||||
* Write datablob to a filename, don't care about errors.
|
||||
*/
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
rk_dumpdata (const char *filename, const void *buf, size_t size)
|
||||
{
|
||||
int fd;
|
||||
@ -57,7 +55,7 @@ rk_dumpdata (const char *filename, const void *buf, size_t size)
|
||||
* Read all data from a filename, care about errors.
|
||||
*/
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
rk_undumpdata(const char *filename, void **buf, size_t *size)
|
||||
{
|
||||
struct stat sb;
|
||||
|
@ -42,7 +42,7 @@
|
||||
* Like calloc but never fails.
|
||||
*/
|
||||
|
||||
void * ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL
|
||||
ecalloc (size_t number, size_t size)
|
||||
{
|
||||
void *tmp = calloc (number, size);
|
||||
|
@ -42,7 +42,7 @@
|
||||
* Like malloc but never fails.
|
||||
*/
|
||||
|
||||
void * ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL
|
||||
emalloc (size_t sz)
|
||||
{
|
||||
void *tmp = malloc (sz);
|
||||
|
@ -127,7 +127,7 @@ read_env_file(FILE *F, char ***env, int *assigned)
|
||||
* list of malloced strings in `env'
|
||||
*/
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
read_environment(const char *file, char ***env)
|
||||
{
|
||||
int assigned;
|
||||
@ -141,7 +141,7 @@ read_environment(const char *file, char ***env)
|
||||
return assigned;
|
||||
}
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
free_environment(char **env)
|
||||
{
|
||||
int i;
|
||||
|
@ -33,16 +33,13 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "roken.h"
|
||||
|
||||
/*
|
||||
* Like read but never fails (and never returns partial data).
|
||||
*/
|
||||
|
||||
ssize_t ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
||||
eread (int fd, void *buf, size_t nbytes)
|
||||
{
|
||||
ssize_t ret;
|
||||
|
@ -42,7 +42,7 @@
|
||||
* Like realloc but never fails.
|
||||
*/
|
||||
|
||||
void * ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void * ROKEN_LIB_CALL
|
||||
erealloc (void *ptr, size_t sz)
|
||||
{
|
||||
void *tmp = realloc (ptr, sz);
|
||||
|
@ -35,7 +35,7 @@
|
||||
|
||||
#include "err.h"
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
err(int eval, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
@ -48,40 +48,42 @@
|
||||
|
||||
#ifndef ROKEN_LIB_FUNCTION
|
||||
#ifdef _WIN32
|
||||
#define ROKEN_LIB_FUNCTION _stdcall
|
||||
#define ROKEN_LIB_FUNCTION
|
||||
#define ROKEN_LIB_CALL __cdecl
|
||||
#else
|
||||
#define ROKEN_LIB_FUNCTION
|
||||
#define ROKEN_LIB_CALL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
verr(int eval, const char *fmt, va_list ap)
|
||||
__attribute__ ((noreturn, format (printf, 2, 0)));
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
err(int eval, const char *fmt, ...)
|
||||
__attribute__ ((noreturn, format (printf, 2, 3)));
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
verrx(int eval, const char *fmt, va_list ap)
|
||||
__attribute__ ((noreturn, format (printf, 2, 0)));
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
errx(int eval, const char *fmt, ...)
|
||||
__attribute__ ((noreturn, format (printf, 2, 3)));
|
||||
void ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
vwarn(const char *fmt, va_list ap)
|
||||
__attribute__ ((format (printf, 1, 0)));
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
warn(const char *fmt, ...)
|
||||
__attribute__ ((format (printf, 1, 2)));
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
vwarnx(const char *fmt, va_list ap)
|
||||
__attribute__ ((format (printf, 1, 0)));
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
warnx(const char *fmt, ...)
|
||||
__attribute__ ((format (printf, 1, 2)));
|
||||
|
||||
|
@ -35,7 +35,7 @@
|
||||
|
||||
#include "err.h"
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
errx(int eval, const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
@ -37,7 +37,7 @@
|
||||
|
||||
#include <err.h>
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
esetenv(const char *var, const char *val, int rewrite)
|
||||
{
|
||||
if (setenv (rk_UNCONST(var), rk_UNCONST(val), rewrite))
|
||||
|
@ -42,7 +42,7 @@
|
||||
* Like strdup but never fails.
|
||||
*/
|
||||
|
||||
char * ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
|
||||
estrdup (const char *str)
|
||||
{
|
||||
char *tmp = strdup (str);
|
||||
|
@ -33,16 +33,13 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <err.h>
|
||||
|
||||
#include "roken.h"
|
||||
|
||||
/*
|
||||
* Like write but never fails (and never returns partial data).
|
||||
*/
|
||||
|
||||
ssize_t ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
||||
ewrite (int fd, const void *buf, size_t nbytes)
|
||||
{
|
||||
ssize_t ret;
|
||||
|
@ -35,7 +35,7 @@
|
||||
|
||||
#include "roken.h"
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
fchown(int fd, uid_t owner, gid_t group)
|
||||
{
|
||||
return 0;
|
||||
|
@ -37,11 +37,11 @@
|
||||
|
||||
#include "roken.h"
|
||||
|
||||
|
||||
#define OP_MASK (LOCK_SH | LOCK_EX | LOCK_UN)
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
rk_flock(int fd, int operation)
|
||||
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
fk_flock(int fd, int operation)
|
||||
{
|
||||
#if defined(HAVE_FCNTL) && defined(F_SETLK)
|
||||
struct flock arg;
|
||||
@ -75,6 +75,76 @@ rk_flock(int fd, int operation)
|
||||
break;
|
||||
}
|
||||
return code;
|
||||
|
||||
#elif defined(_WIN32)
|
||||
/* Windows */
|
||||
|
||||
#define FLOCK_OFFSET_LOW 0
|
||||
#define FLOCK_OFFSET_HIGH 0
|
||||
#define FLOCK_LENGTH_LOW 0x00000000
|
||||
#define FLOCK_LENGTH_HIGH 0x80000000
|
||||
|
||||
HANDLE hFile;
|
||||
OVERLAPPED ov;
|
||||
BOOL rv = FALSE;
|
||||
DWORD f = 0;
|
||||
|
||||
hFile = (HANDLE) _get_osfhandle(fd);
|
||||
if (hFile == NULL || hFile == INVALID_HANDLE_VALUE) {
|
||||
_set_errno(EBADF);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ZeroMemory(&ov, sizeof(ov));
|
||||
ov.hEvent = NULL;
|
||||
ov.Offset = FLOCK_OFFSET_LOW;
|
||||
ov.OffsetHigh = FLOCK_OFFSET_HIGH;
|
||||
|
||||
if (operation & LOCK_NB)
|
||||
f = LOCKFILE_FAIL_IMMEDIATELY;
|
||||
|
||||
switch (operation & OP_MASK) {
|
||||
case LOCK_UN: /* Unlock */
|
||||
rv = UnlockFileEx(hFile, 0,
|
||||
FLOCK_LENGTH_LOW, FLOCK_LENGTH_HIGH, &ov);
|
||||
break;
|
||||
|
||||
case LOCK_SH: /* Shared lock */
|
||||
rv = LockFileEx(hFile, f, 0,
|
||||
FLOCK_LENGTH_LOW, FLOCK_LENGTH_HIGH, &ov);
|
||||
break;
|
||||
|
||||
case LOCK_EX: /* Exclusive lock */
|
||||
rv = LockFileEx(hFile, f|LOCKFILE_EXCLUSIVE_LOCK, 0,
|
||||
FLOCK_LENGTH_LOW, FLOCK_LENGTH_HIGH,
|
||||
&ov);
|
||||
break;
|
||||
|
||||
default:
|
||||
_set_errno(EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!rv) {
|
||||
switch (GetLastError()) {
|
||||
case ERROR_SHARING_VIOLATION:
|
||||
case ERROR_LOCK_VIOLATION:
|
||||
case ERROR_IO_PENDING:
|
||||
_set_errno(EWOULDBLOCK);
|
||||
break;
|
||||
|
||||
case ERROR_ACCESS_DENIED:
|
||||
_set_errno(EACCES);
|
||||
break;
|
||||
|
||||
default:
|
||||
_set_errno(ENOLCK);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
|
@ -45,6 +45,12 @@ static char rcsid[] = "$NetBSD: fnmatch.c,v 1.11 1995/02/27 03:43:06 cgd Exp $";
|
||||
* Compares a filename or pathname to a pattern.
|
||||
*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include <config.h>
|
||||
#endif
|
||||
|
||||
#include <roken.h>
|
||||
|
||||
#include <fnmatch.h>
|
||||
#include <string.h>
|
||||
|
||||
@ -52,7 +58,7 @@ static char rcsid[] = "$NetBSD: fnmatch.c,v 1.11 1995/02/27 03:43:06 cgd Exp $";
|
||||
|
||||
static const char *rangematch (const char *, int, int);
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
rk_fnmatch(const char *pattern, const char *string, int flags)
|
||||
{
|
||||
const char *stringstart;
|
||||
|
@ -36,9 +36,11 @@
|
||||
|
||||
#ifndef ROKEN_LIB_FUNCTION
|
||||
#ifdef _WIN32
|
||||
#define ROKEN_LIB_FUNCTION _stdcall
|
||||
#define ROKEN_LIB_FUNCTION __declspec(dllimport)
|
||||
#define ROKEN_LIB_CALL __stdcall
|
||||
#else
|
||||
#define ROKEN_LIB_FUNCTION
|
||||
#define ROKEN_LIB_CALL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
@ -39,7 +39,7 @@
|
||||
* free the list of `struct addrinfo' starting at `ai'
|
||||
*/
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
freeaddrinfo(struct addrinfo *ai)
|
||||
{
|
||||
struct addrinfo *tofree;
|
||||
|
@ -39,7 +39,7 @@
|
||||
* free a malloced hostent
|
||||
*/
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
freehostent (struct hostent *h)
|
||||
{
|
||||
char **p;
|
||||
|
@ -62,7 +62,7 @@ static struct gai_error {
|
||||
*
|
||||
*/
|
||||
|
||||
const char * ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL
|
||||
gai_strerror(int ecode)
|
||||
{
|
||||
struct gai_error *g;
|
||||
|
@ -40,7 +40,7 @@
|
||||
* NULL if we can't guess at all.
|
||||
*/
|
||||
|
||||
const char * ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL
|
||||
get_default_username (void)
|
||||
{
|
||||
const char *user;
|
||||
@ -73,5 +73,11 @@ get_default_username (void)
|
||||
return pwd->pw_name;
|
||||
}
|
||||
#endif
|
||||
#ifdef _WIN32
|
||||
/* TODO: We can call GetUserNameEx() and figure out a
|
||||
username. However, callers do not free the return value of this
|
||||
function. */
|
||||
#endif
|
||||
|
||||
return user;
|
||||
}
|
||||
|
@ -57,7 +57,7 @@
|
||||
|
||||
#include "roken.h"
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
get_window_size(int fd, struct winsize *wp)
|
||||
{
|
||||
int ret = -1;
|
||||
@ -85,6 +85,20 @@ get_window_size(int fd, struct winsize *wp)
|
||||
wp->ws_col = dst[0];
|
||||
ret = 0;
|
||||
}
|
||||
#elif defined(_WIN32)
|
||||
{
|
||||
intptr_t fh = 0;
|
||||
CONSOLE_SCREEN_BUFFER_INFO sb_info;
|
||||
|
||||
fh = _get_osfhandle(fd);
|
||||
if (fh != (intptr_t) INVALID_HANDLE_VALUE &&
|
||||
GetConsoleScreenBufferInfo((HANDLE) fh, &sb_info)) {
|
||||
wp->ws_row = 1 + sb_info.srWindow.Bottom - sb_info.srWindow.Top;
|
||||
wp->ws_col = 1 + sb_info.srWindow.Right - sb_info.srWindow.Left;
|
||||
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (ret != 0) {
|
||||
char *s;
|
||||
|
@ -365,7 +365,7 @@ get_nodes (const char *nodename,
|
||||
* };
|
||||
*/
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
getaddrinfo(const char *nodename,
|
||||
const char *servname,
|
||||
const struct addrinfo *hints,
|
||||
|
@ -37,7 +37,7 @@
|
||||
|
||||
/* getaddrinfo via string specifying host and port */
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
roken_getaddrinfo_hostspec2(const char *hostspec,
|
||||
int socktype,
|
||||
int port,
|
||||
@ -92,7 +92,7 @@ roken_getaddrinfo_hostspec2(const char *hostspec,
|
||||
return getaddrinfo (host, portstr, &hints, ai);
|
||||
}
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
roken_getaddrinfo_hostspec(const char *hostspec,
|
||||
int port,
|
||||
struct addrinfo **ai)
|
||||
|
@ -91,7 +91,7 @@ mandoc_template(struct getargs *args,
|
||||
const char *extra_string,
|
||||
char *(i18n)(const char *))
|
||||
{
|
||||
int i;
|
||||
size_t i;
|
||||
char timestr[64], cmd[64];
|
||||
char buf[128];
|
||||
const char *p;
|
||||
@ -207,7 +207,7 @@ builtin_i18n(const char *str)
|
||||
return rk_UNCONST(str);
|
||||
}
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
arg_printusage (struct getargs *args,
|
||||
size_t num_args,
|
||||
const char *progname,
|
||||
@ -217,7 +217,7 @@ arg_printusage (struct getargs *args,
|
||||
progname, extra_string, builtin_i18n);
|
||||
}
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
arg_printusage_i18n (struct getargs *args,
|
||||
size_t num_args,
|
||||
const char *usage,
|
||||
@ -225,8 +225,7 @@ arg_printusage_i18n (struct getargs *args,
|
||||
const char *extra_string,
|
||||
char *(i18n)(const char *))
|
||||
{
|
||||
int i;
|
||||
size_t max_len = 0;
|
||||
size_t i, max_len = 0;
|
||||
char buf[128];
|
||||
int col = 0, columns;
|
||||
struct winsize ws;
|
||||
@ -474,6 +473,7 @@ arg_match_long(struct getargs *args, size_t num_args,
|
||||
|
||||
default:
|
||||
abort ();
|
||||
UNREACHABLE(return 0);
|
||||
}
|
||||
|
||||
/* not reached */
|
||||
@ -550,7 +550,7 @@ arg_match_short (struct getargs *args, size_t num_args,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
getarg(struct getargs *args, size_t num_args,
|
||||
int argc, char **argv, int *goptind)
|
||||
{
|
||||
@ -562,7 +562,7 @@ getarg(struct getargs *args, size_t num_args,
|
||||
#elif defined(HAVE_RANDOM)
|
||||
srandom(time(NULL));
|
||||
#else
|
||||
srand (time(NULL));
|
||||
srand ((int) time(NULL));
|
||||
#endif
|
||||
(*goptind)++;
|
||||
for(i = *goptind; i < argc; i++) {
|
||||
@ -586,7 +586,7 @@ getarg(struct getargs *args, size_t num_args,
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
free_getarg_strings (getarg_strings *s)
|
||||
{
|
||||
free (s->strings);
|
||||
|
@ -40,9 +40,11 @@
|
||||
|
||||
#ifndef ROKEN_LIB_FUNCTION
|
||||
#ifdef _WIN32
|
||||
#define ROKEN_LIB_FUNCTION _stdcall
|
||||
#define ROKEN_LIB_FUNCTION
|
||||
#define ROKEN_LIB_CALL __cdecl
|
||||
#else
|
||||
#define ROKEN_LIB_FUNCTION
|
||||
#define ROKEN_LIB_CALL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -86,17 +88,17 @@ typedef struct getarg_collect_info {
|
||||
void *data;
|
||||
} getarg_collect_info;
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
getarg(struct getargs *args, size_t num_args,
|
||||
int argc, char **argv, int *goptind);
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
arg_printusage (struct getargs *args,
|
||||
size_t num_args,
|
||||
const char *progname,
|
||||
const char *extra_string);
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
arg_printusage_i18n (struct getargs *args,
|
||||
size_t num_args,
|
||||
const char *usage,
|
||||
@ -104,7 +106,7 @@ arg_printusage_i18n (struct getargs *args,
|
||||
const char *extra_string,
|
||||
char *(i18n)(const char *));
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
free_getarg_strings (getarg_strings *);
|
||||
|
||||
#endif /* __GETARG_H__ */
|
||||
|
@ -83,24 +83,24 @@ static int getent (char **, size_t *, char **, int, const char *, int, char *);
|
||||
static int nfcmp (char *, char *);
|
||||
|
||||
|
||||
int ROKEN_LIB_FUNCTION cgetset(const char *ent);
|
||||
char *ROKEN_LIB_FUNCTION cgetcap(char *buf, const char *cap, int type);
|
||||
int ROKEN_LIB_FUNCTION cgetent(char **buf, char **db_array, const char *name);
|
||||
int ROKEN_LIB_FUNCTION cgetmatch(const char *buf, const char *name);
|
||||
int ROKEN_LIB_FUNCTION cgetclose(void);
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL cgetset(const char *ent);
|
||||
ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL cgetcap(char *buf, const char *cap, int type);
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL cgetent(char **buf, char **db_array, const char *name);
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL cgetmatch(const char *buf, const char *name);
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL cgetclose(void);
|
||||
#if 0
|
||||
int cgetfirst(char **buf, char **db_array);
|
||||
int cgetnext(char **bp, char **db_array);
|
||||
#endif
|
||||
int ROKEN_LIB_FUNCTION cgetstr(char *buf, const char *cap, char **str);
|
||||
int ROKEN_LIB_FUNCTION cgetustr(char *buf, const char *cap, char **str);
|
||||
int ROKEN_LIB_FUNCTION cgetnum(char *buf, const char *cap, long *num);
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL cgetstr(char *buf, const char *cap, char **str);
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL cgetustr(char *buf, const char *cap, char **str);
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL cgetnum(char *buf, const char *cap, long *num);
|
||||
/*
|
||||
* Cgetset() allows the addition of a user specified buffer to be added
|
||||
* to the database array, in effect "pushing" the buffer on top of the
|
||||
* virtual database. 0 is returned on success, -1 on failure.
|
||||
*/
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
cgetset(const char *ent)
|
||||
{
|
||||
const char *source, *check;
|
||||
@ -153,7 +153,7 @@ cgetset(const char *ent)
|
||||
* If (cap, '@') or (cap, terminator, '@') is found before (cap, terminator)
|
||||
* return NULL.
|
||||
*/
|
||||
char * ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
|
||||
cgetcap(char *buf, const char *cap, int type)
|
||||
{
|
||||
char *bp;
|
||||
@ -204,7 +204,7 @@ cgetcap(char *buf, const char *cap, int type)
|
||||
* encountered (couldn't open/read a file, etc.), and -3 if a potential
|
||||
* reference loop is detected.
|
||||
*/
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
cgetent(char **buf, char **db_array, const char *name)
|
||||
{
|
||||
size_t dummy;
|
||||
@ -700,7 +700,7 @@ static FILE *pfp;
|
||||
static int slash;
|
||||
static char **dbp;
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
cgetclose(void)
|
||||
{
|
||||
if (pfp != NULL) {
|
||||
@ -847,7 +847,7 @@ cgetnext(char **bp, char **db_array)
|
||||
* couldn't be found, -2 if a system error was encountered (storage
|
||||
* allocation failure).
|
||||
*/
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
cgetstr(char *buf, const char *cap, char **str)
|
||||
{
|
||||
u_int m_room;
|
||||
@ -980,7 +980,7 @@ cgetstr(char *buf, const char *cap, char **str)
|
||||
* -1 if the requested string capability couldn't be found, -2 if a system
|
||||
* error was encountered (storage allocation failure).
|
||||
*/
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
cgetustr(char *buf, const char *cap, char **str)
|
||||
{
|
||||
u_int m_room;
|
||||
@ -1049,7 +1049,7 @@ cgetustr(char *buf, const char *cap, char **str)
|
||||
* the long pointed to by num. 0 is returned on success, -1 if the requested
|
||||
* numeric capability couldn't be found.
|
||||
*/
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
cgetnum(char *buf, const char *cap, long *num)
|
||||
{
|
||||
long n;
|
||||
|
@ -42,7 +42,7 @@
|
||||
|
||||
#include "roken.h"
|
||||
|
||||
char* ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION char* ROKEN_LIB_CALL
|
||||
getcwd(char *path, size_t size)
|
||||
{
|
||||
char xxx[MaxPathLen];
|
||||
|
@ -61,7 +61,7 @@
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
getdtablesize(void)
|
||||
{
|
||||
int files = -1;
|
||||
|
@ -37,7 +37,7 @@
|
||||
|
||||
#ifndef HAVE_GETEGID
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
getegid(void)
|
||||
{
|
||||
return getgid();
|
||||
|
@ -37,7 +37,7 @@
|
||||
|
||||
#ifndef HAVE_GETEUID
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
geteuid(void)
|
||||
{
|
||||
return getuid();
|
||||
|
@ -36,7 +36,7 @@
|
||||
|
||||
#ifndef HAVE_GETGID
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
getgid(void)
|
||||
{
|
||||
return 17;
|
||||
|
@ -47,7 +47,7 @@
|
||||
* interface is identical to gethostname(2).)
|
||||
*/
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
gethostname(char *name, int namelen)
|
||||
{
|
||||
#if defined(HAVE_UNAME)
|
||||
|
@ -3,6 +3,8 @@
|
||||
* (Royal Institute of Technology, Stockholm, Sweden).
|
||||
* All rights reserved.
|
||||
*
|
||||
* Portions Copyright (c) 2009, Secure Endpoints Inc. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
@ -38,18 +40,62 @@
|
||||
|
||||
#include <ifaddrs.h>
|
||||
|
||||
static void
|
||||
print_addr(const char *s, struct sockaddr *sa)
|
||||
{
|
||||
int i;
|
||||
printf(" %s=%d/", s, sa->sa_family);
|
||||
#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
|
||||
for(i = 0; i < sa->sa_len - ((long)sa->sa_data - (long)&sa->sa_family); i++)
|
||||
printf("%02x", ((unsigned char*)sa->sa_data)[i]);
|
||||
#else
|
||||
for(i = 0; i < sizeof(sa->sa_data); i++)
|
||||
printf("%02x", ((unsigned char*)sa->sa_data)[i]);
|
||||
#endif
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
static void
|
||||
print_ifaddrs(struct ifaddrs *x)
|
||||
{
|
||||
struct ifaddrs *p;
|
||||
|
||||
for(p = x; p; p = p->ifa_next) {
|
||||
printf("%s\n", p->ifa_name);
|
||||
printf(" flags=%x\n", p->ifa_flags);
|
||||
if(p->ifa_addr)
|
||||
print_addr("addr", p->ifa_addr);
|
||||
if(p->ifa_dstaddr)
|
||||
print_addr("dstaddr", p->ifa_dstaddr);
|
||||
if(p->ifa_netmask)
|
||||
print_addr("netmask", p->ifa_netmask);
|
||||
printf(" %p\n", p->ifa_data);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
struct ifaddrs *addrs = NULL;
|
||||
int ret;
|
||||
|
||||
if (rk_SOCK_INIT())
|
||||
errx(1, "Couldn't initialize sockets. Err=%d\n", rk_SOCK_ERRNO);
|
||||
|
||||
ret = getifaddrs(&addrs);
|
||||
if (ret != 0)
|
||||
err(1, "getifaddrs");
|
||||
|
||||
if (addrs == NULL)
|
||||
errx(1, "address == NULL");
|
||||
|
||||
print_ifaddrs(addrs);
|
||||
|
||||
/* Check that freeifaddrs doesn't crash */
|
||||
freeifaddrs(addrs);
|
||||
|
||||
if (rk_SOCK_EXIT())
|
||||
errx(1, "Couldn't uninitialize sockets. Err=%d\n", rk_SOCK_ERRNO);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -498,7 +498,7 @@ nl_open(void)
|
||||
}
|
||||
|
||||
/* ====================================================================== */
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
rk_getifaddrs(struct ifaddrs **ifap)
|
||||
{
|
||||
int sd;
|
||||
@ -1165,7 +1165,7 @@ getlifaddrs2(struct ifaddrs **ifap,
|
||||
}
|
||||
#endif /* defined(HAVE_IPV6) && defined(SIOCGLIFCONF) && defined(SIOCGLIFFLAGS) */
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
rk_getifaddrs(struct ifaddrs **ifap)
|
||||
{
|
||||
int ret = -1;
|
||||
@ -1193,7 +1193,9 @@ rk_getifaddrs(struct ifaddrs **ifap)
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
#endif /* !AF_NETLINK */
|
||||
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
rk_freeifaddrs(struct ifaddrs *ifp)
|
||||
{
|
||||
struct ifaddrs *p, *q;
|
||||
@ -1214,8 +1216,6 @@ rk_freeifaddrs(struct ifaddrs *ifp)
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* !AF_NETLINK */
|
||||
|
||||
#ifdef TEST
|
||||
|
||||
void
|
||||
|
163
lib/roken/getifaddrs_w32.c
Normal file
163
lib/roken/getifaddrs_w32.c
Normal file
@ -0,0 +1,163 @@
|
||||
/***********************************************************************
|
||||
* Copyright (c) 2009, Secure Endpoints Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* - Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* - Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
||||
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
**********************************************************************/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include<config.h>
|
||||
#endif
|
||||
|
||||
#include <roken.h>
|
||||
|
||||
#include <ifaddrs.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
#error This is a Windows specific implementation.
|
||||
#endif
|
||||
|
||||
static struct sockaddr *
|
||||
dupaddr(const sockaddr_gen * src)
|
||||
{
|
||||
sockaddr_gen * d = malloc(sizeof(*d));
|
||||
|
||||
if (d) {
|
||||
memcpy(d, src, sizeof(*d));
|
||||
}
|
||||
|
||||
return (struct sockaddr *) d;
|
||||
}
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
rk_getifaddrs(struct ifaddrs **ifpp)
|
||||
{
|
||||
SOCKET s = INVALID_SOCKET;
|
||||
size_t il_len = 8192;
|
||||
int ret = -1;
|
||||
INTERFACE_INFO *il = NULL;
|
||||
|
||||
*ifpp = NULL;
|
||||
|
||||
s = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
if (s == INVALID_SOCKET)
|
||||
return -1;
|
||||
|
||||
for (;;) {
|
||||
DWORD cbret = 0;
|
||||
|
||||
il = malloc(il_len);
|
||||
if (!il)
|
||||
break;
|
||||
|
||||
ZeroMemory(il, il_len);
|
||||
|
||||
if (WSAIoctl(s, SIO_GET_INTERFACE_LIST, NULL, 0,
|
||||
(LPVOID) il, il_len, &cbret,
|
||||
NULL, NULL) == 0) {
|
||||
il_len = cbret;
|
||||
break;
|
||||
}
|
||||
|
||||
free (il);
|
||||
il = NULL;
|
||||
|
||||
if (WSAGetLastError() == WSAEFAULT && cbret > il_len) {
|
||||
il_len = cbret;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!il)
|
||||
goto _exit;
|
||||
|
||||
/* il is an array of INTERFACE_INFO structures. il_len has the
|
||||
actual size of the buffer. The number of elements is
|
||||
il_len/sizeof(INTERFACE_INFO) */
|
||||
|
||||
{
|
||||
size_t n = il_len / sizeof(INTERFACE_INFO);
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < n; i++ ) {
|
||||
struct ifaddrs *ifp;
|
||||
|
||||
ifp = malloc(sizeof(*ifp));
|
||||
if (ifp == NULL)
|
||||
break;
|
||||
|
||||
ZeroMemory(ifp, sizeof(*ifp));
|
||||
|
||||
ifp->ifa_next = NULL;
|
||||
ifp->ifa_name = NULL;
|
||||
ifp->ifa_flags = il[i].iiFlags;
|
||||
ifp->ifa_addr = dupaddr(&il[i].iiAddress);
|
||||
ifp->ifa_netmask = dupaddr(&il[i].iiNetmask);
|
||||
ifp->ifa_broadaddr = dupaddr(&il[i].iiBroadcastAddress);
|
||||
ifp->ifa_data = NULL;
|
||||
|
||||
*ifpp = ifp;
|
||||
ifpp = &ifp->ifa_next;
|
||||
}
|
||||
|
||||
if (i == n)
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
_exit:
|
||||
|
||||
if (s != INVALID_SOCKET)
|
||||
closesocket(s);
|
||||
|
||||
if (il)
|
||||
free (il);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
rk_freeifaddrs(struct ifaddrs *ifp)
|
||||
{
|
||||
struct ifaddrs *p, *q;
|
||||
|
||||
for(p = ifp; p; ) {
|
||||
if (p->ifa_name)
|
||||
free(p->ifa_name);
|
||||
if(p->ifa_addr)
|
||||
free(p->ifa_addr);
|
||||
if(p->ifa_dstaddr)
|
||||
free(p->ifa_dstaddr);
|
||||
if(p->ifa_netmask)
|
||||
free(p->ifa_netmask);
|
||||
if(p->ifa_data)
|
||||
free(p->ifa_data);
|
||||
q = p;
|
||||
p = p->ifa_next;
|
||||
free(q);
|
||||
}
|
||||
}
|
@ -40,7 +40,7 @@
|
||||
* to a malloced struct hostent or NULL.
|
||||
*/
|
||||
|
||||
struct hostent * ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
|
||||
getipnodebyaddr (const void *src, size_t len, int af, int *error_num)
|
||||
{
|
||||
struct hostent *tmp;
|
||||
|
@ -44,7 +44,7 @@ static int h_errno = NO_RECOVERY;
|
||||
* to a malloced struct hostent or NULL.
|
||||
*/
|
||||
|
||||
struct hostent * ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION struct hostent * ROKEN_LIB_CALL
|
||||
getipnodebyname (const char *name, int af, int flags, int *error_num)
|
||||
{
|
||||
struct hostent *tmp;
|
||||
|
@ -91,7 +91,7 @@ doit (int af,
|
||||
*
|
||||
*/
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
getnameinfo(const struct sockaddr *sa, socklen_t salen,
|
||||
char *host, size_t hostlen,
|
||||
char *serv, size_t servlen,
|
||||
|
@ -43,7 +43,7 @@
|
||||
* NI_NAMEREQD flag is set or return the numeric address as a string.
|
||||
*/
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
getnameinfo_verified(const struct sockaddr *sa, socklen_t salen,
|
||||
char *host, size_t hostlen,
|
||||
char *serv, size_t servlen,
|
||||
|
@ -51,7 +51,7 @@ char *optarg; /* argument associated with option */
|
||||
#define BADARG (int)':'
|
||||
#define EMSG ""
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
getopt(nargc, nargv, ostr)
|
||||
int nargc;
|
||||
char * const *nargv;
|
||||
|
@ -40,7 +40,7 @@ const char *__progname;
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_GETPROGNAME
|
||||
const char * ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL
|
||||
getprogname(void)
|
||||
{
|
||||
return __progname;
|
||||
|
@ -38,13 +38,13 @@
|
||||
/*
|
||||
* Simple gettimeofday that only returns seconds.
|
||||
*/
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
gettimeofday (struct timeval *tp, void *ignore)
|
||||
{
|
||||
time_t t;
|
||||
|
||||
t = time(NULL);
|
||||
tp->tv_sec = t;
|
||||
tp->tv_sec = (long) t;
|
||||
tp->tv_usec = 0;
|
||||
return 0;
|
||||
}
|
||||
|
@ -36,7 +36,7 @@
|
||||
|
||||
#ifndef HAVE_GETUID
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
getuid(void)
|
||||
{
|
||||
return 17;
|
||||
|
@ -81,7 +81,7 @@ static char **initshells (void);
|
||||
/*
|
||||
* Get a list of shells from _PATH_SHELLS, if it exists.
|
||||
*/
|
||||
char * ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION char * ROKEN_LIB_CALL
|
||||
getusershell()
|
||||
{
|
||||
char *ret;
|
||||
@ -94,7 +94,7 @@ getusershell()
|
||||
return (ret);
|
||||
}
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
endusershell()
|
||||
{
|
||||
if (shells != NULL)
|
||||
@ -106,7 +106,7 @@ endusershell()
|
||||
curshell = NULL;
|
||||
}
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
setusershell()
|
||||
{
|
||||
curshell = initshells();
|
||||
|
@ -164,7 +164,7 @@ static int match (Char *, Char *, Char *);
|
||||
static void qprintf (const char *, Char *);
|
||||
#endif
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
glob(const char *pattern,
|
||||
int flags,
|
||||
int (*errfunc)(const char *, int),
|
||||
@ -739,7 +739,7 @@ match(Char *name, Char *pat, Char *patend)
|
||||
}
|
||||
|
||||
/* Free allocated data belonging to a glob_t structure. */
|
||||
void ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
globfree(glob_t *pglob)
|
||||
{
|
||||
int i;
|
||||
|
@ -50,7 +50,7 @@ pos(char c)
|
||||
return -1;
|
||||
}
|
||||
|
||||
ssize_t ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
||||
hex_encode(const void *data, size_t size, char **str)
|
||||
{
|
||||
const unsigned char *q = data;
|
||||
@ -80,7 +80,7 @@ hex_encode(const void *data, size_t size, char **str)
|
||||
return i * 2;
|
||||
}
|
||||
|
||||
ssize_t ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
||||
hex_decode(const char *str, void *data, size_t len)
|
||||
{
|
||||
size_t l;
|
||||
|
@ -38,18 +38,20 @@
|
||||
|
||||
#ifndef ROKEN_LIB_FUNCTION
|
||||
#ifdef _WIN32
|
||||
#define ROKEN_LIB_FUNCTION _stdcall
|
||||
#define ROKEN_LIB_FUNCTION
|
||||
#define ROKEN_LIB_CALL __cdecl
|
||||
#else
|
||||
#define ROKEN_LIB_FUNCTION
|
||||
#define ROKEN_LIB_CALL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define hex_encode rk_hex_encode
|
||||
#define hex_decode rk_hex_decode
|
||||
|
||||
ssize_t ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
||||
hex_encode(const void *, size_t, char **);
|
||||
ssize_t ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
||||
hex_decode(const char *, void *, size_t);
|
||||
|
||||
#endif /* _rk_HEX_H_ */
|
||||
|
@ -39,7 +39,7 @@
|
||||
* Try to find a fqdn (with `.') in he if possible, else return h_name
|
||||
*/
|
||||
|
||||
const char * ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL
|
||||
hostent_find_fqdn (const struct hostent *he)
|
||||
{
|
||||
const char *ret = he->h_name;
|
||||
|
@ -64,7 +64,7 @@ extern int h_nerr;
|
||||
|
||||
#endif
|
||||
|
||||
const char * ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL
|
||||
hstrerror(int herr)
|
||||
{
|
||||
if (0 <= herr && herr < h_nerr)
|
||||
|
@ -38,7 +38,7 @@
|
||||
/* Minimal implementation of inet_aton.
|
||||
* Cannot distinguish between failure and a local broadcast address. */
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
inet_aton(const char *cp, struct in_addr *addr)
|
||||
{
|
||||
addr->s_addr = inet_addr(cp);
|
||||
|
@ -113,7 +113,7 @@ inet_ntop_v6 (const void *src, char *dst, size_t size)
|
||||
}
|
||||
#endif /* HAVE_IPV6 */
|
||||
|
||||
const char * ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION const char * ROKEN_LIB_CALL
|
||||
inet_ntop(int af, const void *src, char *dst, size_t size)
|
||||
{
|
||||
switch (af) {
|
||||
|
@ -35,7 +35,64 @@
|
||||
|
||||
#include "roken.h"
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
#ifdef HAVE_WINSOCK
|
||||
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
inet_pton(int af, const char *src, void *dst)
|
||||
{
|
||||
switch (af) {
|
||||
case AF_INET:
|
||||
{
|
||||
struct sockaddr_in si4;
|
||||
INT r;
|
||||
INT s = sizeof(si4);
|
||||
|
||||
si4.sin_family = AF_INET;
|
||||
r = WSAStringToAddress(src, AF_INET, NULL, (LPSOCKADDR) &si4, &s);
|
||||
|
||||
if (r == 0) {
|
||||
memcpy(dst, &si4.sin_addr, sizeof(si4.sin_addr));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case AF_INET6:
|
||||
{
|
||||
struct sockaddr_in6 si6;
|
||||
INT r;
|
||||
INT s = sizeof(si6);
|
||||
|
||||
si6.sin6_family = AF_INET6;
|
||||
r = WSAStringToAddress(src, AF_INET6, NULL, (LPSOCKADDR) &si6, &s);
|
||||
|
||||
if (r == 0) {
|
||||
memcpy(dst, &si6.sin6_addr, sizeof(si6.sin6_addr));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
_set_errno( EAFNOSUPPORT );
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* the call failed */
|
||||
{
|
||||
int le = WSAGetLastError();
|
||||
|
||||
if (le == WSAEINVAL)
|
||||
return 0;
|
||||
|
||||
_set_errno(le);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
#else /* !HAVE_WINSOCK */
|
||||
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
inet_pton(int af, const char *src, void *dst)
|
||||
{
|
||||
if (af != AF_INET) {
|
||||
@ -44,3 +101,5 @@ inet_pton(int af, const char *src, void *dst)
|
||||
}
|
||||
return inet_aton (src, dst);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -35,7 +35,7 @@
|
||||
|
||||
#include "roken.h"
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
initgroups(const char *name, gid_t basegid)
|
||||
{
|
||||
return 0;
|
||||
|
@ -35,7 +35,7 @@
|
||||
|
||||
#ifndef HAVE_INNETGR
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
innetgr(const char *netgroup, const char *machine,
|
||||
const char *user, const char *domain)
|
||||
{
|
||||
|
@ -214,7 +214,7 @@ __ivaliduser(FILE *hostf, unsigned raddr, const char *luser,
|
||||
*
|
||||
* Returns 0 if ok, -1 if not ok.
|
||||
*/
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
iruserok(unsigned raddr, int superuser, const char *ruser, const char *luser)
|
||||
{
|
||||
char *cp;
|
||||
|
@ -35,7 +35,7 @@
|
||||
|
||||
#include "roken.h"
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
issuid(void)
|
||||
{
|
||||
#if defined(HAVE_ISSETUGID)
|
||||
|
@ -38,7 +38,7 @@
|
||||
#include <shadow.h>
|
||||
#endif
|
||||
|
||||
struct passwd * ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION struct passwd * ROKEN_LIB_CALL
|
||||
k_getpwnam (const char *user)
|
||||
{
|
||||
struct passwd *p;
|
||||
|
@ -38,7 +38,7 @@
|
||||
#include <shadow.h>
|
||||
#endif
|
||||
|
||||
struct passwd * ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION struct passwd * ROKEN_LIB_CALL
|
||||
k_getpwuid (uid_t uid)
|
||||
{
|
||||
struct passwd *p;
|
||||
|
@ -39,7 +39,7 @@
|
||||
|
||||
#ifndef HAVE_LOCALTIME_R
|
||||
|
||||
struct tm * ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION struct tm * ROKEN_LIB_CALL
|
||||
localtime_r(const time_t *timer, struct tm *result)
|
||||
{
|
||||
struct tm *tm;
|
||||
|
@ -35,7 +35,7 @@
|
||||
|
||||
#include "roken.h"
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
lstat(const char *path, struct stat *buf)
|
||||
{
|
||||
return stat(path, buf);
|
||||
|
@ -41,7 +41,7 @@
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
void* ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void* ROKEN_LIB_CALL
|
||||
memmove(void *s1, const void *s2, size_t n)
|
||||
{
|
||||
char *s=(char*)s2, *d=(char*)s1;
|
||||
|
@ -41,61 +41,93 @@
|
||||
*/
|
||||
|
||||
static void
|
||||
accept_it (int s)
|
||||
accept_it (rk_socket_t s, rk_socket_t *ret_socket)
|
||||
{
|
||||
int s2;
|
||||
rk_socket_t as;
|
||||
|
||||
s2 = accept(s, NULL, NULL);
|
||||
if(s2 < 0)
|
||||
as = accept(s, NULL, NULL);
|
||||
if(rk_IS_BAD_SOCKET(as))
|
||||
err (1, "accept");
|
||||
close(s);
|
||||
dup2(s2, STDIN_FILENO);
|
||||
dup2(s2, STDOUT_FILENO);
|
||||
/* dup2(s2, STDERR_FILENO); */
|
||||
close(s2);
|
||||
|
||||
if (ret_socket) {
|
||||
|
||||
*ret_socket = as;
|
||||
|
||||
} else {
|
||||
int fd = socket_to_fd(as, 0);
|
||||
|
||||
/* We would use _O_RDONLY for the socket_to_fd() call for
|
||||
STDIN, but there are instances where we assume that STDIN
|
||||
is a r/w socket. */
|
||||
|
||||
dup2(fd, STDIN_FILENO);
|
||||
dup2(fd, STDOUT_FILENO);
|
||||
|
||||
rk_closesocket(as);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Listen on a specified port, emulating inetd.
|
||||
/**
|
||||
* Listen on a specified addresses
|
||||
*
|
||||
* Listens on the specified addresses for incoming connections. If
|
||||
* the \a ret_socket parameter is \a NULL, on return STDIN and STDOUT
|
||||
* will be connected to an accepted socket. If the \a ret_socket
|
||||
* parameter is non-NULL, the accepted socket will be returned in
|
||||
* *ret_socket. In the latter case, STDIN and STDOUT will be left
|
||||
* unmodified.
|
||||
*
|
||||
* This function does not return if there is an error or if no
|
||||
* connection is established.
|
||||
*
|
||||
* @param[in] ai Addresses to listen on
|
||||
* @param[out] ret_socket If non-NULL receives the accepted socket.
|
||||
*
|
||||
* @see mini_inetd()
|
||||
*/
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
mini_inetd_addrinfo (struct addrinfo *ai)
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
mini_inetd_addrinfo (struct addrinfo *ai, rk_socket_t *ret_socket)
|
||||
{
|
||||
int ret;
|
||||
struct addrinfo *a;
|
||||
int n, nalloc, i;
|
||||
int *fds;
|
||||
rk_socket_t *fds;
|
||||
fd_set orig_read_set, read_set;
|
||||
int max_fd = -1;
|
||||
rk_socket_t max_fd = (rk_socket_t)-1;
|
||||
|
||||
for (nalloc = 0, a = ai; a != NULL; a = a->ai_next)
|
||||
++nalloc;
|
||||
|
||||
fds = malloc (nalloc * sizeof(*fds));
|
||||
if (fds == NULL)
|
||||
if (fds == NULL) {
|
||||
errx (1, "mini_inetd: out of memory");
|
||||
UNREACHABLE(return);
|
||||
}
|
||||
|
||||
FD_ZERO(&orig_read_set);
|
||||
|
||||
for (i = 0, a = ai; a != NULL; a = a->ai_next) {
|
||||
fds[i] = socket (a->ai_family, a->ai_socktype, a->ai_protocol);
|
||||
if (fds[i] < 0)
|
||||
if (rk_IS_BAD_SOCKET(fds[i]))
|
||||
continue;
|
||||
socket_set_reuseaddr (fds[i], 1);
|
||||
socket_set_ipv6only(fds[i], 1);
|
||||
if (bind (fds[i], a->ai_addr, a->ai_addrlen) < 0) {
|
||||
if (rk_IS_SOCKET_ERROR(bind (fds[i], a->ai_addr, a->ai_addrlen))) {
|
||||
warn ("bind af = %d", a->ai_family);
|
||||
close(fds[i]);
|
||||
rk_closesocket(fds[i]);
|
||||
fds[i] = rk_INVALID_SOCKET;
|
||||
continue;
|
||||
}
|
||||
if (listen (fds[i], SOMAXCONN) < 0) {
|
||||
if (rk_IS_SOCKET_ERROR(listen (fds[i], SOMAXCONN))) {
|
||||
warn ("listen af = %d", a->ai_family);
|
||||
close(fds[i]);
|
||||
rk_closesocket(fds[i]);
|
||||
fds[i] = rk_INVALID_SOCKET;
|
||||
continue;
|
||||
}
|
||||
#ifndef NO_LIMIT_FD_SETSIZE
|
||||
if (fds[i] >= FD_SETSIZE)
|
||||
errx (1, "fd too large");
|
||||
#endif
|
||||
FD_SET(fds[i], &orig_read_set);
|
||||
max_fd = max(max_fd, fds[i]);
|
||||
++i;
|
||||
@ -108,23 +140,40 @@ mini_inetd_addrinfo (struct addrinfo *ai)
|
||||
read_set = orig_read_set;
|
||||
|
||||
ret = select (max_fd + 1, &read_set, NULL, NULL, NULL);
|
||||
if (ret < 0 && errno != EINTR)
|
||||
if (rk_IS_SOCKET_ERROR(ret) && rk_SOCK_ERRNO != EINTR)
|
||||
err (1, "select");
|
||||
} while (ret <= 0);
|
||||
|
||||
for (i = 0; i < n; ++i)
|
||||
if (FD_ISSET (fds[i], &read_set)) {
|
||||
accept_it (fds[i]);
|
||||
accept_it (fds[i], ret_socket);
|
||||
for (i = 0; i < n; ++i)
|
||||
close(fds[i]);
|
||||
rk_closesocket(fds[i]);
|
||||
free(fds);
|
||||
return;
|
||||
}
|
||||
abort ();
|
||||
}
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
mini_inetd (int port)
|
||||
/**
|
||||
* Listen on a specified port
|
||||
*
|
||||
* Listens on the specified port for incoming connections. If the \a
|
||||
* ret_socket parameter is \a NULL, on return STDIN and STDOUT will be
|
||||
* connected to an accepted socket. If the \a ret_socket parameter is
|
||||
* non-NULL, the accepted socket will be returned in *ret_socket. In
|
||||
* the latter case, STDIN and STDOUT will be left unmodified.
|
||||
*
|
||||
* This function does not return if there is an error or if no
|
||||
* connection is established.
|
||||
*
|
||||
* @param[in] port Port to listen on
|
||||
* @param[out] ret_socket If non-NULL receives the accepted socket.
|
||||
*
|
||||
* @see mini_inetd_addrinfo()
|
||||
*/
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
mini_inetd(int port, rk_socket_t * ret_socket)
|
||||
{
|
||||
int error;
|
||||
struct addrinfo *ai, hints;
|
||||
@ -141,7 +190,8 @@ mini_inetd (int port)
|
||||
if (error)
|
||||
errx (1, "getaddrinfo: %s", gai_strerror (error));
|
||||
|
||||
mini_inetd_addrinfo(ai);
|
||||
mini_inetd_addrinfo(ai, ret_socket);
|
||||
|
||||
freeaddrinfo(ai);
|
||||
}
|
||||
|
||||
|
@ -42,9 +42,11 @@
|
||||
#endif
|
||||
#include <errno.h>
|
||||
|
||||
#include <roken.h>
|
||||
|
||||
#ifndef HAVE_MKSTEMP
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
mkstemp(char *template)
|
||||
{
|
||||
int start, i;
|
||||
|
@ -60,7 +60,7 @@ static DBC *cursor;
|
||||
|
||||
#define D(X) ((DB*)(X))
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
dbm_close (DBM *db)
|
||||
{
|
||||
#ifdef HAVE_DB3
|
||||
@ -71,7 +71,7 @@ dbm_close (DBM *db)
|
||||
#endif
|
||||
}
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
dbm_delete (DBM *db, datum dkey)
|
||||
{
|
||||
DBT key;
|
||||
@ -129,19 +129,19 @@ dbm_get (DB *db, int flags)
|
||||
#define DB_KEYEXIST 1
|
||||
#endif
|
||||
|
||||
datum ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION datum ROKEN_LIB_CALL
|
||||
dbm_firstkey (DBM *db)
|
||||
{
|
||||
return dbm_get(D(db), DB_FIRST);
|
||||
}
|
||||
|
||||
datum ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION datum ROKEN_LIB_CALL
|
||||
dbm_nextkey (DBM *db)
|
||||
{
|
||||
return dbm_get(D(db), DB_NEXT);
|
||||
}
|
||||
|
||||
DBM* ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION DBM* ROKEN_LIB_CALL
|
||||
dbm_open (const char *file, int flags, mode_t mode)
|
||||
{
|
||||
DB *db;
|
||||
@ -184,7 +184,7 @@ dbm_open (const char *file, int flags, mode_t mode)
|
||||
return (DBM*)db;
|
||||
}
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
dbm_store (DBM *db, datum dkey, datum dvalue, int flags)
|
||||
{
|
||||
int ret;
|
||||
@ -204,13 +204,13 @@ dbm_store (DBM *db, datum dkey, datum dvalue, int flags)
|
||||
RETURN(ret);
|
||||
}
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
dbm_error (DBM *db)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
dbm_clearerr (DBM *db)
|
||||
{
|
||||
return 0;
|
||||
|
@ -41,9 +41,11 @@
|
||||
|
||||
#ifndef ROKEN_LIB_FUNCTION
|
||||
#ifdef _WIN32
|
||||
#define ROKEN_LIB_FUNCTION _stdcall
|
||||
#define ROKEN_LIB_FUNCTION
|
||||
#define ROKEN_LIB_CALL __cdecl
|
||||
#else
|
||||
#define ROKEN_LIB_FUNCTION
|
||||
#define ROKEN_LIB_CALL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -78,14 +80,14 @@ typedef struct {
|
||||
} DBM;
|
||||
#endif
|
||||
|
||||
int ROKEN_LIB_FUNCTION dbm_clearerr (DBM*);
|
||||
void ROKEN_LIB_FUNCTION dbm_close (DBM*);
|
||||
int ROKEN_LIB_FUNCTION dbm_delete (DBM*, datum);
|
||||
int ROKEN_LIB_FUNCTION dbm_error (DBM*);
|
||||
datum ROKEN_LIB_FUNCTION dbm_fetch (DBM*, datum);
|
||||
datum ROKEN_LIB_FUNCTION dbm_firstkey (DBM*);
|
||||
datum ROKEN_LIB_FUNCTION dbm_nextkey (DBM*);
|
||||
DBM* ROKEN_LIB_FUNCTION dbm_open (const char*, int, mode_t);
|
||||
int ROKEN_LIB_FUNCTION dbm_store (DBM*, datum, datum, int);
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL dbm_clearerr (DBM*);
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL dbm_close (DBM*);
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL dbm_delete (DBM*, datum);
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL dbm_error (DBM*);
|
||||
ROKEN_LIB_FUNCTION datum ROKEN_LIB_CALL dbm_fetch (DBM*, datum);
|
||||
ROKEN_LIB_FUNCTION datum ROKEN_LIB_CALL dbm_firstkey (DBM*);
|
||||
ROKEN_LIB_FUNCTION datum ROKEN_LIB_CALL dbm_nextkey (DBM*);
|
||||
ROKEN_LIB_FUNCTION DBM* ROKEN_LIB_CALL dbm_open (const char*, int, mode_t);
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL dbm_store (DBM*, datum, datum, int);
|
||||
|
||||
#endif /* __ndbm_wrap_h__ */
|
||||
|
@ -33,29 +33,23 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "roken.h"
|
||||
|
||||
/*
|
||||
* Like read but never return partial data.
|
||||
*/
|
||||
|
||||
ssize_t ROKEN_LIB_FUNCTION
|
||||
net_read (int fd, void *buf, size_t nbytes)
|
||||
#ifndef _WIN32
|
||||
|
||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
||||
net_read (rk_socket_t fd, void *buf, size_t nbytes)
|
||||
{
|
||||
char *cbuf = (char *)buf;
|
||||
ssize_t count;
|
||||
size_t rem = nbytes;
|
||||
|
||||
while (rem > 0) {
|
||||
#ifdef WIN32
|
||||
count = recv (fd, cbuf, rem, 0);
|
||||
#else
|
||||
count = read (fd, cbuf, rem);
|
||||
#endif
|
||||
if (count < 0) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
@ -69,3 +63,36 @@ net_read (int fd, void *buf, size_t nbytes)
|
||||
}
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
||||
net_read(rk_socket_t sock, void *buf, size_t nbytes)
|
||||
{
|
||||
char *cbuf = (char *)buf;
|
||||
ssize_t count;
|
||||
size_t rem = nbytes;
|
||||
|
||||
while (rem > 0) {
|
||||
count = recv (sock, cbuf, rem, 0);
|
||||
if (count < 0) {
|
||||
|
||||
/* With WinSock, the error EINTR (WSAEINTR), is used to
|
||||
indicate that a blocking call was cancelled using
|
||||
WSACancelBlockingCall(). */
|
||||
|
||||
#ifndef HAVE_WINSOCK
|
||||
if (rk_SOCK_ERRNO == EINTR)
|
||||
continue;
|
||||
#endif
|
||||
return count;
|
||||
} else if (count == 0) {
|
||||
return count;
|
||||
}
|
||||
cbuf += count;
|
||||
rem -= count;
|
||||
}
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -33,29 +33,23 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "roken.h"
|
||||
|
||||
/*
|
||||
* Like write but never return partial data.
|
||||
*/
|
||||
|
||||
ssize_t ROKEN_LIB_FUNCTION
|
||||
net_write (int fd, const void *buf, size_t nbytes)
|
||||
#ifndef _WIN32
|
||||
|
||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
||||
net_write (rk_socket_t fd, const void *buf, size_t nbytes)
|
||||
{
|
||||
const char *cbuf = (const char *)buf;
|
||||
ssize_t count;
|
||||
size_t rem = nbytes;
|
||||
|
||||
while (rem > 0) {
|
||||
#ifdef WIN32
|
||||
count = send (fd, cbuf, rem, 0);
|
||||
#else
|
||||
count = write (fd, cbuf, rem);
|
||||
#endif
|
||||
if (count < 0) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
@ -67,3 +61,28 @@ net_write (int fd, const void *buf, size_t nbytes)
|
||||
}
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
|
||||
net_write(rk_socket_t sock, const void *buf, size_t nbytes)
|
||||
{
|
||||
const char *cbuf = (const char *)buf;
|
||||
ssize_t count;
|
||||
size_t rem = nbytes;
|
||||
|
||||
while (rem > 0) {
|
||||
count = send (sock, cbuf, rem, 0);
|
||||
if (count < 0) {
|
||||
if (errno == EINTR)
|
||||
continue;
|
||||
else
|
||||
return count;
|
||||
}
|
||||
cbuf += count;
|
||||
rem -= count;
|
||||
}
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -56,19 +56,19 @@ static struct units bytes_short_units[] = {
|
||||
{ NULL, 0 }
|
||||
};
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
parse_bytes (const char *s, const char *def_unit)
|
||||
{
|
||||
return parse_units (s, bytes_units, def_unit);
|
||||
}
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
unparse_bytes (int t, char *s, size_t len)
|
||||
{
|
||||
return unparse_units (t, bytes_units, s, len);
|
||||
}
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
unparse_bytes_short (int t, char *s, size_t len)
|
||||
{
|
||||
return unparse_units_approx (t, bytes_short_units, s, len);
|
||||
|
@ -38,19 +38,21 @@
|
||||
|
||||
#ifndef ROKEN_LIB_FUNCTION
|
||||
#ifdef _WIN32
|
||||
#define ROKEN_LIB_FUNCTION _stdcall
|
||||
#define ROKEN_LIB_FUNCTION
|
||||
#define ROKEN_LIB_CALL __cdecl
|
||||
#else
|
||||
#define ROKEN_LIB_FUNCTION
|
||||
#define ROKEN_LIB_CALL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
parse_bytes (const char *s, const char *def_unit);
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
unparse_bytes (int t, char *s, size_t len);
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
unparse_bytes_short (int t, char *s, size_t len);
|
||||
|
||||
#endif /* __PARSE_BYTES_H__ */
|
||||
|
@ -40,8 +40,8 @@
|
||||
|
||||
static struct testcase {
|
||||
size_t size;
|
||||
time_t val;
|
||||
char *str;
|
||||
int val;
|
||||
char *str;
|
||||
} tests[] = {
|
||||
{ 8, 1, "1 second" },
|
||||
{ 17, 61, "1 minute 1 second" },
|
||||
@ -97,6 +97,7 @@ main(int argc, char **argv)
|
||||
errx(1, "test %i not zero terminated", i);
|
||||
rk_test_mem_free("underrun");
|
||||
}
|
||||
|
||||
buf = rk_test_mem_alloc(RK_TM_OVERRUN, "overrun",
|
||||
tests[i].str, tests[i].size + 1);
|
||||
j = parse_time(buf, "s");
|
||||
@ -110,6 +111,7 @@ main(int argc, char **argv)
|
||||
if (j != tests[i].val)
|
||||
errx(1, "parse_time failed for test %d", i);
|
||||
rk_test_mem_free("underrun");
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -50,25 +50,25 @@ static struct units time_units[] = {
|
||||
{NULL, 0},
|
||||
};
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
parse_time (const char *s, const char *def_unit)
|
||||
{
|
||||
return parse_units (s, time_units, def_unit);
|
||||
}
|
||||
|
||||
size_t ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
|
||||
unparse_time (int t, char *s, size_t len)
|
||||
{
|
||||
return unparse_units (t, time_units, s, len);
|
||||
}
|
||||
|
||||
size_t ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
|
||||
unparse_time_approx (int t, char *s, size_t len)
|
||||
{
|
||||
return unparse_units_approx (t, time_units, s, len);
|
||||
}
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
print_time_table (FILE *f)
|
||||
{
|
||||
print_units_table (time_units, f);
|
||||
|
@ -38,22 +38,24 @@
|
||||
|
||||
#ifndef ROKEN_LIB_FUNCTION
|
||||
#ifdef _WIN32
|
||||
#define ROKEN_LIB_FUNCTION _stdcall
|
||||
#define ROKEN_LIB_FUNCTION
|
||||
#define ROKEN_LIB_CALL __cdecl
|
||||
#else
|
||||
#define ROKEN_LIB_FUNCTION
|
||||
#define ROKEN_LIB_CALL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
parse_time (const char *s, const char *def_unit);
|
||||
|
||||
size_t
|
||||
ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
|
||||
unparse_time (int t, char *s, size_t len);
|
||||
|
||||
size_t
|
||||
ROKEN_LIB_FUNCTION size_t ROKEN_LIB_CALL
|
||||
unparse_time_approx (int t, char *s, size_t len);
|
||||
|
||||
void
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
print_time_table (FILE *f);
|
||||
|
||||
#endif /* __PARSE_TIME_H__ */
|
||||
|
@ -70,7 +70,7 @@ parse_something (const char *s, const struct units *units,
|
||||
|
||||
p = s;
|
||||
while (*p) {
|
||||
double val;
|
||||
int val;
|
||||
char *next;
|
||||
const struct units *u, *partial_unit;
|
||||
size_t u_len;
|
||||
@ -80,7 +80,7 @@ parse_something (const char *s, const struct units *units,
|
||||
while(isspace((unsigned char)*p) || *p == ',')
|
||||
++p;
|
||||
|
||||
val = strtod (p, &next); /* strtol(p, &next, 0); */
|
||||
val = (int) strtod (p, &next); /* strtol(p, &next, 0); */
|
||||
if (p == next) {
|
||||
val = 0;
|
||||
if(!accept_no_val_p)
|
||||
@ -149,7 +149,7 @@ acc_units(int res, int val, unsigned mult)
|
||||
return res + val * mult;
|
||||
}
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
parse_units (const char *s, const struct units *units,
|
||||
const char *def_unit)
|
||||
{
|
||||
@ -175,7 +175,7 @@ acc_flags(int res, int val, unsigned mult)
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
parse_flags (const char *s, const struct units *units,
|
||||
int orig)
|
||||
{
|
||||
@ -208,7 +208,7 @@ unparse_something (int num, const struct units *units, char *s, size_t len,
|
||||
tmp = (*print) (s, len, divisor, u->name, num);
|
||||
if (tmp < 0)
|
||||
return tmp;
|
||||
if (tmp > len) {
|
||||
if (tmp > (int) len) {
|
||||
len = 0;
|
||||
s = NULL;
|
||||
} else {
|
||||
@ -245,7 +245,7 @@ update_unit_approx (int in, unsigned mult)
|
||||
return update_unit (in, mult);
|
||||
}
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
unparse_units (int num, const struct units *units, char *s, size_t len)
|
||||
{
|
||||
return unparse_something (num, units, s, len,
|
||||
@ -254,7 +254,7 @@ unparse_units (int num, const struct units *units, char *s, size_t len)
|
||||
"0");
|
||||
}
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
unparse_units_approx (int num, const struct units *units, char *s, size_t len)
|
||||
{
|
||||
return unparse_something (num, units, s, len,
|
||||
@ -263,7 +263,7 @@ unparse_units_approx (int num, const struct units *units, char *s, size_t len)
|
||||
"0");
|
||||
}
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
print_units_table (const struct units *units, FILE *f)
|
||||
{
|
||||
const struct units *u, *u2;
|
||||
@ -308,7 +308,7 @@ update_flag (int in, unsigned mult)
|
||||
return in - mult;
|
||||
}
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
unparse_flags (int num, const struct units *units, char *s, size_t len)
|
||||
{
|
||||
return unparse_something (num, units, s, len,
|
||||
@ -317,7 +317,7 @@ unparse_flags (int num, const struct units *units, char *s, size_t len)
|
||||
"");
|
||||
}
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
print_flags_table (const struct units *units, FILE *f)
|
||||
{
|
||||
const struct units *u;
|
||||
|
@ -41,9 +41,11 @@
|
||||
|
||||
#ifndef ROKEN_LIB_FUNCTION
|
||||
#ifdef _WIN32
|
||||
#define ROKEN_LIB_FUNCTION _stdcall
|
||||
#define ROKEN_LIB_FUNCTION
|
||||
#define ROKEN_LIB_CALL __cdecl
|
||||
#else
|
||||
#define ROKEN_LIB_FUNCTION
|
||||
#define ROKEN_LIB_CALL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -52,28 +54,28 @@ struct units {
|
||||
unsigned mult;
|
||||
};
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
parse_units (const char *s, const struct units *units,
|
||||
const char *def_unit);
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
print_units_table (const struct units *units, FILE *f);
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
parse_flags (const char *s, const struct units *units,
|
||||
int orig);
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
unparse_units (int num, const struct units *units, char *s, size_t len);
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
unparse_units_approx (int num, const struct units *units, char *s,
|
||||
size_t len);
|
||||
|
||||
int ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION int ROKEN_LIB_CALL
|
||||
unparse_flags (int num, const struct units *units, char *s, size_t len);
|
||||
|
||||
void ROKEN_LIB_FUNCTION
|
||||
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
|
||||
print_flags_table (const struct units *units, FILE *f);
|
||||
|
||||
#endif /* __PARSE_UNITS_H__ */
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user