1 |
root |
1.1 |
#include "EXTERN.h" |
2 |
|
|
#include "perl.h" |
3 |
|
|
#include "XSUB.h" |
4 |
|
|
|
5 |
|
|
#define HLOG 18 /* up to 22, but gives diminishing improvements */ |
6 |
|
|
#define VERY_FAST 0 |
7 |
|
|
#define ULTRA_FAST 0 |
8 |
|
|
|
9 |
|
|
#include "liblzf/lzf_c_best.c" |
10 |
|
|
|
11 |
|
|
#include "urlib.h" |
12 |
|
|
#include "urlib.c" |
13 |
|
|
|
14 |
|
|
MODULE = Urlader PACKAGE = Urlader PREFIX = u_ |
15 |
|
|
|
16 |
|
|
PROTOTYPES: ENABLE |
17 |
|
|
|
18 |
|
|
BOOT: |
19 |
|
|
{ |
20 |
|
|
HV *stash = gv_stashpv ("Urlader", 1); |
21 |
|
|
|
22 |
|
|
static const struct { |
23 |
|
|
const char *name; |
24 |
|
|
IV iv; |
25 |
|
|
} *civ, const_iv[] = { |
26 |
|
|
# define const_iv(name) { # name, (IV) name }, |
27 |
|
|
const_iv (T_NULL) |
28 |
|
|
const_iv (T_META) |
29 |
|
|
const_iv (T_ENV) |
30 |
|
|
const_iv (T_ARG) |
31 |
|
|
const_iv (T_DIR) |
32 |
|
|
const_iv (T_FILE) |
33 |
|
|
const_iv (T_NUM) |
34 |
|
|
const_iv (F_LZF) |
35 |
|
|
const_iv (F_EXEC) |
36 |
|
|
const_iv (F_NULL) |
37 |
|
|
}; |
38 |
|
|
|
39 |
|
|
for (civ = const_iv + sizeof (const_iv) / sizeof (const_iv [0]); civ > const_iv; civ--) |
40 |
|
|
newCONSTSUB (stash, (char *)civ[-1].name, newSViv (civ[-1].iv)); |
41 |
|
|
|
42 |
|
|
newCONSTSUB (stash, "URLADER" , newSVpv (URLADER , 0)); |
43 |
|
|
newCONSTSUB (stash, "URLADER_VERSION", newSVpv (URLADER_VERSION, 0)); |
44 |
|
|
newCONSTSUB (stash, "TAIL_MAGIC" , newSVpv (TAIL_MAGIC , 0)); |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
const char * |
48 |
|
|
getenv (const char *name) |
49 |
|
|
|
50 |
|
|
SV * |
51 |
|
|
lzf_compress (SV *in, int min_improve = 2) |
52 |
|
|
CODE: |
53 |
|
|
{ |
54 |
|
|
STRLEN in_len; |
55 |
|
|
char *in_data = SvPVbyte (in, in_len); |
56 |
|
|
STRLEN out_len = in_len - min_improve; |
57 |
|
|
SV *out = sv_newmortal (); |
58 |
|
|
|
59 |
|
|
RETVAL = &PL_sv_no; |
60 |
|
|
if (in_len) |
61 |
|
|
{ |
62 |
|
|
sv_grow (out, out_len); |
63 |
|
|
out_len = lzf_compress_best (in_data, in_len, SvPVX (out), out_len); |
64 |
|
|
|
65 |
|
|
if (out_len) |
66 |
|
|
{ |
67 |
|
|
SvPOK_only (out); |
68 |
|
|
SvCUR_set (out, out_len); |
69 |
|
|
SvSetSV (in, out); |
70 |
|
|
RETVAL = &PL_sv_yes; |
71 |
|
|
} |
72 |
|
|
} |
73 |
|
|
} |
74 |
|
|
OUTPUT: |
75 |
|
|
RETVAL |
76 |
|
|
|
77 |
|
|
void |
78 |
|
|
_set_datadir () |
79 |
|
|
CODE: |
80 |
|
|
u_set_datadir (); |
81 |
|
|
|
82 |
|
|
void |
83 |
|
|
_set_exe_info (const char *id, const char *ver) |
84 |
|
|
CODE: |
85 |
|
|
strcpy (exe_id , id); |
86 |
|
|
strcpy (exe_ver, ver); |
87 |
|
|
u_set_exe_info (); |
88 |
|
|
|
89 |
|
|
SV * |
90 |
|
|
lock (SV *path, SV *excl, SV *dowait) |
91 |
|
|
CODE: |
92 |
|
|
{ |
93 |
|
|
u_handle h = u_lock (SvPVbyte_nolen (path), SvTRUE (excl), SvTRUE (dowait)); |
94 |
|
|
|
95 |
|
|
RETVAL = &PL_sv_undef; |
96 |
|
|
if (u_valid (h)) |
97 |
root |
1.3 |
RETVAL = sv_setref_iv (NEWSV (0, 0), "Urlader::lock", (IV)h); |
98 |
root |
1.1 |
} |
99 |
|
|
OUTPUT: |
100 |
|
|
RETVAL |
101 |
|
|
|
102 |
|
|
MODULE = Urlader PACKAGE = Urlader::lock |
103 |
|
|
|
104 |
|
|
void |
105 |
|
|
DESTROY (SV *self) |
106 |
|
|
CODE: |
107 |
|
|
u_close ((u_handle)SvIV (SvRV (self))); |
108 |
|
|
|
109 |
|
|
|