Cac
view release on metacpan or search on metacpan
gen/perl_callout.c view on Meta::CPAN
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#ifndef WIN32
#include <unistd.h>
#endif
#include <stdlib.h>
#if 0
#include <bzlib.h>
#include <aeslib/aeslib.h>
#endif
#include <EXTERN.h>
#include <perl.h>
#include <cacembed.h>
int perl_is_master = 0; // this is public
static PerlInterpreter *my_perl = 0;
EXTERN_C void xs_init (pTHX);
EXTERN_C int zperl (ZARRAYP in, ZARRAYP out);
EXTERN_C int zpget (const char *var, ZARRAYP out);
EXTERN_C int zpset (const char *var, ZARRAYP val);
EXTERN_C int zpreset (ZARRAYP out);
EXTERN_C int zpc0 (const char *func, ZARRAYP out);
EXTERN_C int zpc1 (const char *func, ZARRAYP in1, ZARRAYP out);
EXTERN_C int zpc2 (const char *func, ZARRAYP in1, ZARRAYP in2, ZARRAYP out);
EXTERN_C int zpc3 (const char *func, ZARRAYP in1, ZARRAYP in2, ZARRAYP in3, ZARRAYP out);
EXTERN_C int zpc4 (const char *func, ZARRAYP in1, ZARRAYP in2, ZARRAYP in3, ZARRAYP in4, ZARRAYP out);
EXTERN_C int zpc5 (const char *func, ZARRAYP in1, ZARRAYP in2, ZARRAYP in3, ZARRAYP in4, ZARRAYP in5, ZARRAYP out);
EXTERN_C int zpc6 (const char *func, ZARRAYP in1, ZARRAYP in2, ZARRAYP in3, ZARRAYP in4, ZARRAYP in5, ZARRAYP in6, ZARRAYP out);
EXTERN_C int zpc7 (const char *func, ZARRAYP in1, ZARRAYP in2, ZARRAYP in3, ZARRAYP in4, ZARRAYP in5, ZARRAYP in6, ZARRAYP in7, ZARRAYP out);
EXTERN_C int zpc8 (const char *func, ZARRAYP in1, ZARRAYP in2, ZARRAYP in3, ZARRAYP in4, ZARRAYP in5, ZARRAYP in6, ZARRAYP in7, ZARRAYP in8, ZARRAYP out);
EXTERN_C int zperr (ZARRAYP out);
#if 0
#include <openssl/opensslv.h>
#include <openssl/rand.h>
EXTERN_C int zrandbytes(int num, ZARRAYP p);
#endif
#if 0
EXTERN_C int zgetenv(const char *var, ZARRAYP val);
#endif
// #define DEBUG 1
#if 0
EXTERN_C int zopen_out (const char *p, int *ret);
EXTERN_C int zopen_in (const char *p, int *ret);
EXTERN_C int zwrite (int fd, ZARRAYP a);
EXTERN_C int zread (int fd, ZARRAYP a);
EXTERN_C int zclose (int fd, ZARRAYP ret);
EXTERN_C int zsetkey (int fd, ZARRAYP p);
EXTERN_C int zerror (int i, int j);
EXTERN_C int zfilecheck (const char *p, ZARRAYP ret);
EXTERN_C int zstat(const char *p, int *ret);
EXTERN_C int zunlink(const char *p, int *ret);
EXTERN_C int zrmdir(const char *p, int *ret);
EXTERN_C int zmkdir(const char *p, int *ret);
EXTERN_C int zrename(const char *old, const char *neu, int *ret);
EXTERN_C int zreaddir(const char *dirname, ZARRAYP out);
EXTERN_C int zcryptv(ZARRAYP out);
EXTERN_C int zcompressv(ZARRAYP out);
#ifdef OPENSSL
EXTERN_C int zopensslv(ZARRAYP out);
#endif
#endif
ZFBEGIN
#if 0
ZFENTRY ("ZOPENOUT", "cP", zopen_out)
ZFENTRY ("ZOPENIN", "cP", zopen_in)
ZFENTRY ("ZWRITE", "ib", zwrite)
ZFENTRY ("ZREAD", "iB", zread)
ZFENTRY ("ZCLOSE", "iB", zclose)
ZFENTRY ("ZSETKEY", "ib", zsetkey)
ZFENTRY ("ZERROR", "ii", zerror)
ZFENTRY ("ZFILECHECK", "cB", zfilecheck)
ZFENTRY ("ZSTAT", "cP", zstat)
ZFENTRY ("ZUNLINK", "cP", zunlink)
ZFENTRY ("ZRMDIR", "cP", zrmdir)
ZFENTRY ("ZMKDIR", "cP", zmkdir)
ZFENTRY ("ZRENAME", "ccP", zrename)
ZFENTRY ("ZCRYPTV", "B", zcryptv)
ZFENTRY ("ZCOMPRESSV", "B", zcompressv)
// windows sucks
ZFENTRY ("ZREADDIR", "cB", zreaddir)
#endif
#ifdef CACHE_PERL
ZFENTRY ("PERL", "bB", zperl)
ZFENTRY ("PGET", "cB", zpget)
ZFENTRY ("PSET", "cb", zpset)
ZFENTRY ("PCA", "cB", zpc0)
ZFENTRY ("PCB", "cbB", zpc1)
ZFENTRY ("PCC", "cbbB", zpc2)
ZFENTRY ("PCD", "cbbbB", zpc3)
ZFENTRY ("PCE", "cbbbbB", zpc4)
ZFENTRY ("PCF", "cbbbbbB", zpc5)
ZFENTRY ("PCG", "cbbbbbbB", zpc6)
ZFENTRY ("PCH", "cbbbbbbbB", zpc7)
ZFENTRY ("PCI", "cbbbbbbbbB", zpc8)
ZFENTRY ("PERR", "B", zperr)
ZFENTRY ("PRESET", "B", zpreset)
#endif
#if 0
ZFENTRY ("ZRANDBYTES", "iB", zrandbytes)
ZFENTRY ("ZOPENSSLV", "B", zopensslv)
#endif
#if 0
ZFENTRY ("ZGETENV", "cB", zgetenv)
#endif
ZFEND
#if 0
#define MAX_OPEN 10
#endif
#define ERR_SET(x) zferror((x),0)
#define ERR_INTERRUPT 7
gen/perl_callout.c view on Meta::CPAN
if(!dir) {
out->len = 0;
return 0;
}
p = out->data;
while((de = readdir(dir))) {
q = p;
if((q - out->data) + strlen(de->d_name) + 2 > 32767) {
p = out->data;
break;
}
strcpy(p, de->d_name);
p = strchr(p, 0);
p++;
}
closedir(dir);
if(p != out->data)
--p;
out->len = p - out->data;
return 0;
}
#else
#include <io.h>
int zreaddir(const char *dirname, ZARRAYP out)
{
struct _finddata_t fd;
char *p, *q;
long hdl;
char sep[260];
if(strlen(dirname) > 255) {
out->len = 0;
return 0;
}
strcpy(sep, dirname);
strcat(sep, "\\*");
if ((hdl = _findfirst(sep, &fd))== -1) {
out->len = 0;
return 0;
}
p = out->data;
do {
q = p;
if((q - out->data) + strlen(fd.name) + 2 > 32767) {
p = out->data;
break;
}
strcpy(p, fd.name);
p = strchr(p, 0);
p++;
} while(!_findnext(hdl, &fd));
_findclose(hdl);
if(p != out->data)
--p;
out->len = p - out->data;
return 0;
}
#endif
int zstat(const char *p, int *ret)
{
struct stat b;
int rc;
int x = 0;
rc = stat(p, &b);
if(!rc) {
if(S_ISLNK(b.st_mode))
x = 'L';
if(S_ISREG(b.st_mode))
x = 'F';
if(S_ISDIR(b.st_mode))
x = 'D';
if(S_ISCHR(b.st_mode))
x = 'C';
if(S_ISBLK(b.st_mode))
x = 'B';
if(S_ISFIFO(b.st_mode))
x = 'I';
if(S_ISSOCK(b.st_mode))
x = 'S';
if(x == -1)
x = 'A'; // anything but there...
}
*ret = x;
return 0;
}
static const char *crypto_version =
"$Id: ___.c,v 1.1 2002/12/05 02:37:55 root Exp $";
int zcryptv(ZARRAYP out)
{
strcpy(out->data, crypto_version);
out->len = strlen(crypto_version);
return 0;
}
static const char *compress_version =
"embedded bzip2 0.9.0";
int zcompressv(ZARRAYP out)
{
strcpy(out->data, compress_version);
out->len = strlen(compress_version);
return 0;
}
#endif
#ifdef CACHE_PERL
/* @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
* @@@@@@@@@@@@@@@@@@@@@@@@@@@ Perl Interface @@@@@@@@@@@@@@@@@@@@@@@@
* @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ */
#define PERL_ERROR_LEN 8192
static char perl_error[PERL_ERROR_LEN + 1] = { 0 };
//#define WDEB 1
#ifdef WDEB
( run in 0.975 second using v1.01-cache-2.11-cpan-5735350b133 )